function PagePreviewTestCase::setUp

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

drupal/modules/node/node.test, line 459
Tests for node.module.

Class

PagePreviewTestCase
Tests the node entity preview functionality.

Code

function setUp() {
  parent::setUp(array(
    'taxonomy',
    'node',
  ));
  $web_user = $this
    ->drupalCreateUser(array(
    'edit own page content',
    'create page content',
  ));
  $this
    ->drupalLogin($web_user);

  // Add a vocabulary so we can test different view modes.
  $vocabulary = (object) array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    'machine_name' => drupal_strtolower($this
      ->randomName()),
    'help' => '',
    'nodes' => array(
      'page' => 'page',
    ),
  );
  taxonomy_vocabulary_save($vocabulary);
  $this->vocabulary = $vocabulary;

  // Add a term to the vocabulary.
  $term = (object) array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    // Use the first available text format.
    'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)
      ->fetchField(),
    'vid' => $this->vocabulary->vid,
    'vocabulary_machine_name' => $vocabulary->machine_name,
  );
  taxonomy_term_save($term);
  $this->term = $term;

  // Set up a field and instance.
  $this->field_name = drupal_strtolower($this
    ->randomName());
  $this->field = array(
    'field_name' => $this->field_name,
    'type' => 'taxonomy_term_reference',
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $this->vocabulary->machine_name,
          'parent' => '0',
        ),
      ),
    ),
  );
  field_create_field($this->field);
  $this->instance = array(
    'field_name' => $this->field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
    'widget' => array(
      'type' => 'options_select',
    ),
    // Hide on full display but render on teaser.
    'display' => array(
      'default' => array(
        'type' => 'hidden',
      ),
      'teaser' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);
}