function TaggedWithTest::testTaggedWith in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Wizard/TaggedWithTest.php \Drupal\views\Tests\Wizard\TaggedWithTest::testTaggedWith()
Tests the "tagged with" functionality.
File
- core/
modules/ views/ src/ Tests/ Wizard/ TaggedWithTest.php, line 120 - Contains \Drupal\views\Tests\Wizard\TaggedWithTest.
Class
- TaggedWithTest
- Tests the ability of the views wizard to create views filtered by taxonomy.
Namespace
Drupal\views\Tests\WizardCode
function testTaggedWith() {
// In this test we will only create nodes that have an instance of the tag
// field.
$node_add_path = 'node/add/' . $this->nodeTypeWithTags
->id();
// Create three nodes, with different tags.
$edit = array();
$edit['title[0][value]'] = $node_tag1_title = $this
->randomMachineName();
$edit[$this->tagFieldName . '[target_id]'] = 'tag1';
$this
->drupalPostForm($node_add_path, $edit, t('Save'));
$edit = array();
$edit['title[0][value]'] = $node_tag1_tag2_title = $this
->randomMachineName();
$edit[$this->tagFieldName . '[target_id]'] = 'tag1, tag2';
$this
->drupalPostForm($node_add_path, $edit, t('Save'));
$edit = array();
$edit['title[0][value]'] = $node_no_tags_title = $this
->randomMachineName();
$this
->drupalPostForm($node_add_path, $edit, t('Save'));
// Create a view that filters by taxonomy term "tag1". It should show only
// the two nodes from above that are tagged with "tag1".
$view1 = array();
// First select the node type and update the form so the correct tag field
// is used.
$view1['show[type]'] = $this->nodeTypeWithTags
->id();
$this
->drupalPostForm('admin/structure/views/add', $view1, t('Update "of type" choice'));
// Now resubmit the entire form to the same URL.
$view1['label'] = $this
->randomMachineName(16);
$view1['id'] = strtolower($this
->randomMachineName(16));
$view1['description'] = $this
->randomMachineName(16);
$view1['show[tagged_with]'] = 'tag1';
$view1['page[create]'] = 1;
$view1['page[title]'] = $this
->randomMachineName(16);
$view1['page[path]'] = $this
->randomMachineName(16);
$this
->drupalPostForm(NULL, $view1, t('Save and edit'));
// Visit the page and check that the nodes we expect are present and the
// ones we don't expect are absent.
$this
->drupalGet($view1['page[path]']);
$this
->assertResponse(200);
$this
->assertText($node_tag1_title);
$this
->assertText($node_tag1_tag2_title);
$this
->assertNoText($node_no_tags_title);
// Create a view that filters by taxonomy term "tag2". It should show only
// the one node from above that is tagged with "tag2".
$view2 = array();
$view2['show[type]'] = $this->nodeTypeWithTags
->id();
$this
->drupalPostForm('admin/structure/views/add', $view2, t('Update "of type" choice'));
$this
->assertResponse(200);
$view2['label'] = $this
->randomMachineName(16);
$view2['id'] = strtolower($this
->randomMachineName(16));
$view2['description'] = $this
->randomMachineName(16);
$view2['show[tagged_with]'] = 'tag2';
$view2['page[create]'] = 1;
$view2['page[title]'] = $this
->randomMachineName(16);
$view2['page[path]'] = $this
->randomMachineName(16);
$this
->drupalPostForm(NULL, $view2, t('Save and edit'));
$this
->assertResponse(200);
$this
->drupalGet($view2['page[path]']);
$this
->assertNoText($node_tag1_title);
$this
->assertText($node_tag1_tag2_title);
$this
->assertNoText($node_no_tags_title);
}