function TaggedWithTest::testTaggedWithByNodeType 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::testTaggedWithByNodeType()
Tests that the "tagged with" form element only shows for node types that support it.
File
- core/
modules/ views/ src/ Tests/ Wizard/ TaggedWithTest.php, line 186 - 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 testTaggedWithByNodeType() {
// The tagging field is associated with one of our node types only. So the
// "tagged with" form element on the view wizard should appear on the form
// by default (when the wizard is configured to display all content) and
// also when the node type that has the tagging field is selected, but not
// when the node type that doesn't have the tagging field is selected.
$tags_xpath = '//input[@name="show[tagged_with]"]';
$this
->drupalGet('admin/structure/views/add');
$this
->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithTags
->id();
$this
->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
$this
->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithoutTags
->id();
$this
->drupalPostForm(NULL, $view, t('Update "of type" choice (2)'));
$this
->assertNoFieldByXpath($tags_xpath);
// If we add an instance of the tagging field to the second node type, the
// "tagged with" form element should not appear for it too.
entity_create('field_config', array(
'field_name' => $this->tagFieldName,
'entity_type' => 'node',
'bundle' => $this->nodeTypeWithoutTags
->id(),
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
$this->tagVocabulary
->id() => $this->tagVocabulary
->id(),
),
'auto_create' => TRUE,
),
),
))
->save();
entity_get_form_display('node', $this->nodeTypeWithoutTags
->id(), 'default')
->setComponent($this->tagFieldName, array(
'type' => 'entity_reference_autocomplete_tags',
))
->save();
$view['show[type]'] = $this->nodeTypeWithTags
->id();
$this
->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
$this
->assertFieldByXpath($tags_xpath);
$view['show[type]'] = $this->nodeTypeWithoutTags
->id();
$this
->drupalPostForm(NULL, $view, t('Update "of type" choice (2)'));
$this
->assertFieldByXpath($tags_xpath);
}