function TaggedWithTest::testTaggedWithByViewReference

Same name and namespace in other branches
  1. 10 core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php \Drupal\Tests\views\Functional\Wizard\TaggedWithTest::testTaggedWithByViewReference()
  2. 11.x core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php \Drupal\Tests\views\Functional\Wizard\TaggedWithTest::testTaggedWithByViewReference()

Tests that "tagged with" works with views entity reference.

File

core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php, line 250

Class

TaggedWithTest
Tests the ability of the views wizard to create views filtered by taxonomy.

Namespace

Drupal\Tests\views\Functional\Wizard

Code

public function testTaggedWithByViewReference() {
    Term::create([
        'name' => 'term1',
        'vid' => 'views_testing_tags',
    ]);
    $tags_xpath = '//input[@name="show[tagged_with]"]';
    // If we add an instance of the tagging field to the second node type, the
    // "tagged with" form element should now appear for it too.
    FieldConfig::create([
        'field_name' => $this->tagFieldName,
        'entity_type' => 'node',
        'bundle' => $this->nodeTypeWithoutTags
            ->id(),
        'settings' => [
            'handler' => 'views',
            'handler_settings' => [],
        ],
    ])
        ->save();
    \Drupal::service('entity_display.repository')->getFormDisplay('node', $this->nodeTypeWithoutTags
        ->id())
        ->setComponent($this->tagFieldName, [
        'type' => 'entity_reference_autocomplete_tags',
    ])
        ->save();
    $view['show[type]'] = $this->nodeTypeWithTags
        ->id();
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Update "of type" choice');
    $this->assertSession()
        ->elementExists('xpath', $tags_xpath);
    $view['show[type]'] = $this->nodeTypeWithoutTags
        ->id();
    $this->submitForm($view, 'Update "of type" choice (2)');
    $this->assertSession()
        ->elementExists('xpath', $tags_xpath);
    $this->submitForm([
        'show[tagged_with]' => 'term1',
    ], 'Save and edit');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->getSession()
        ->getPage()
        ->hasContent('Has taxonomy term (= term1)');
}

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