protected function DefaultViewsTest::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 Drupal\simpletest\WebTestBase::$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 WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php, line 44
Definition of Drupal\views\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests for views default views.

Namespace

Drupal\views\Tests

Code

protected function setUp() {
  parent::setUp();
  $this->vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
    'machine_name' => drupal_strtolower($this
      ->randomName()),
    'langcode' => LANGUAGE_NOT_SPECIFIED,
    'help' => '',
    'nodes' => array(
      'page' => 'page',
    ),
    'weight' => mt_rand(0, 10),
  ));
  taxonomy_vocabulary_save($this->vocabulary);

  // Setup 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',
    ),
    'display' => array(
      'full' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);

  // Create a time in the past for the archive.
  $time = time() - 3600;
  for ($i = 0; $i <= 10; $i++) {
    $user = $this
      ->drupalCreateUser();
    $term = $this
      ->createTerm($this->vocabulary);
    $values = array(
      'created' => $time,
      'type' => 'page',
    );
    $values[$this->field_name][LANGUAGE_NOT_SPECIFIED][]['tid'] = $term->tid;

    // Make every other node promoted.
    if ($i % 2) {
      $values['promote'] = TRUE;
    }
    $values['body'][LANGUAGE_NOT_SPECIFIED][]['value'] = l('Node ' . 1, 'node/' . 1);
    $node = $this
      ->drupalCreateNode($values);
    search_index($node->nid, 'node', $node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], LANGUAGE_NOT_SPECIFIED);
    $comment = array(
      'uid' => $user->uid,
      'nid' => $node->nid,
    );
    entity_create('comment', $comment)
      ->save();
  }
}