You are here

protected function DefaultViewsTest::setUp in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/views/src/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::setUp()
  2. 8 core/modules/views_ui/src/Tests/DefaultViewsTest.php \Drupal\views_ui\Tests\DefaultViewsTest::setUp()
Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/DefaultViewsTest.php \Drupal\views\Tests\DefaultViewsTest::setUp()

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

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

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.

Overrides ViewTestBase::setUp

File

core/modules/views/src/Tests/DefaultViewsTest.php, line 47
Contains \Drupal\views\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests the default views provided by views.

Namespace

Drupal\views\Tests

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalPlaceBlock('page_title_block');

  // Create Basic page node type.
  $this
    ->drupalCreateContentType(array(
    'type' => 'page',
    'name' => 'Basic page',
  ));
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => $this
      ->randomMachineName(),
    'description' => $this
      ->randomMachineName(),
    'vid' => Unicode::strtolower($this
      ->randomMachineName()),
    'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'help' => '',
    'nodes' => array(
      'page' => 'page',
    ),
    'weight' => mt_rand(0, 10),
  ));
  $vocabulary
    ->save();

  // Create a field.
  $field_name = Unicode::strtolower($this
    ->randomMachineName());
  $handler_settings = array(
    'target_bundles' => array(
      $vocabulary
        ->id() => $vocabulary
        ->id(),
    ),
    'auto_create' => TRUE,
  );
  $this
    ->createEntityReferenceField('node', 'page', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

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

    // Make every other node promoted.
    if ($i % 2) {
      $values['promote'] = TRUE;
    }
    $values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', [
      'node' => 1,
    ]));
    $node = $this
      ->drupalCreateNode($values);
    $comment = array(
      'uid' => $user
        ->id(),
      'status' => CommentInterface::PUBLISHED,
      'entity_id' => $node
        ->id(),
      'entity_type' => 'node',
      'field_name' => 'comment',
    );
    entity_create('comment', $comment)
      ->save();
  }

  // Some views, such as the "Who's Online" view, only return results if at
  // least one user is logged in.
  $account = $this
    ->drupalCreateUser(array());
  $this
    ->drupalLogin($account);
}