function TaxonomyTermArgumentDepthTest::setUp

Same name in this branch
  1. 10 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermArgumentDepthTest::setUp()
Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTermArgumentDepthTest::setUp()
  2. 9 core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermArgumentDepthTest::setUp()
  3. 8.9.x core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermArgumentDepthTest::setUp()
  4. 11.x core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Kernel\Views\TaxonomyTermArgumentDepthTest::setUp()
  5. 11.x core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTermArgumentDepthTest.php \Drupal\Tests\taxonomy\Functional\Views\TaxonomyTermArgumentDepthTest::setUp()

Overrides TaxonomyTestBase::setUp

File

core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyTermArgumentDepthTest.php, line 50

Class

TaxonomyTermArgumentDepthTest
Test the taxonomy term with depth argument.

Namespace

Drupal\Tests\taxonomy\Kernel\Views

Code

protected function setUp($import_test_views = TRUE) : void {
    parent::setUp($import_test_views);
    // Install node_access schema in order to successfully re-save nodes.
    $this->installSchema('node', [
        'node_access',
    ]);
    // Create a hierarchy 5 deep. Note the parent setup function creates two
    // top-level terms w/o children.
    $first = $this->createTerm([
        'name' => 'First',
    ]);
    $second = $this->createTerm([
        'name' => 'Second',
        'parent' => $first->id(),
    ]);
    $third = $this->createTerm([
        'name' => 'Third',
        'parent' => $second->id(),
    ]);
    $fourth = $this->createTerm([
        'name' => 'Fourth',
        'parent' => $third->id(),
    ]);
    $fifth = $this->createTerm([
        'name' => 'Fifth',
        'parent' => $fourth->id(),
    ]);
    $this->terms = [
        $first,
        $second,
        $third,
        $fourth,
        $fifth,
    ];
    // Create a node w/o any terms.
    $settings = [
        'type' => 'article',
    ];
    $this->nodes[] = $this->drupalCreateNode($settings);
    // Create a node with only the top level term.
    $settings['field_views_testing_tags'][0]['target_id'] = $first->id();
    $this->nodes[] = $this->drupalCreateNode($settings);
    // Create a node with only the third level term.
    $settings['field_views_testing_tags'][0]['target_id'] = $third->id();
    $this->nodes[] = $this->drupalCreateNode($settings);
    // Create a node with only the fifth level term.
    $settings['field_views_testing_tags'][0]['target_id'] = $fifth->id();
    $this->nodes[] = $this->drupalCreateNode($settings);
    $this->view = Views::getView(self::$testViews[0]);
    // Fix the created date to match the expectations of the order by in the
    // view. Node 1 should be the most recent node and node 6 should be the
    // oldest.
    $time = \Drupal::time();
    foreach ($this->nodes as $i => $node) {
        $node->setCreatedTime($time->getRequestTime() - $i)
            ->save();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.