function ViewsUIWizardTaggedWithTestCase::testTaggedWith

Tests the "tagged with" functionality.

File

tests/views_ui.test, line 376

Class

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

Code

public function testTaggedWith() {
    // In this test we will only create nodes that have an instance of the tag
    // field.
    $node_add_path = 'node/add/' . $this->node_type_with_tags->type;
    // Create three nodes, with different tags.
    $tag_field = $this->tag_field['field_name'] . '[' . LANGUAGE_NONE . ']';
    $edit = array();
    $edit['title'] = $node_tag1_title = $this->randomName();
    $edit[$tag_field] = 'tag1';
    $this->drupalPost($node_add_path, $edit, t('Save'));
    $edit = array();
    $edit['title'] = $node_tag1_tag2_title = $this->randomName();
    $edit[$tag_field] = 'tag1, tag2';
    $this->drupalPost($node_add_path, $edit, t('Save'));
    $edit = array();
    $edit['title'] = $node_no_tags_title = $this->randomName();
    $this->drupalPost($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->node_type_with_tags->type;
    $this->drupalPost('admin/structure/views/add', $view1, t('Update "of type" choice'));
    // Now resubmit the entire form to the same URL.
    $view1['human_name'] = $this->randomName(16);
    $view1['name'] = strtolower($this->randomName(16));
    $view1['description'] = $this->randomName(16);
    $view1['show[tagged_with]'] = 'tag1';
    $view1['page[create]'] = 1;
    $view1['page[title]'] = $this->randomName(16);
    $view1['page[path]'] = $this->randomName(16);
    $this->drupalPost(NULL, $view1, t('Save & exit'));
    // 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->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->node_type_with_tags->type;
    $this->drupalPost('admin/structure/views/add', $view2, t('Update "of type" choice'));
    $view2['human_name'] = $this->randomName(16);
    $view2['name'] = strtolower($this->randomName(16));
    $view2['description'] = $this->randomName(16);
    $view2['show[tagged_with]'] = 'tag2';
    $view2['page[create]'] = 1;
    $view2['page[title]'] = $this->randomName(16);
    $view2['page[path]'] = $this->randomName(16);
    $this->drupalPost(NULL, $view2, t('Save & exit'));
    $this->drupalGet($view2['page[path]']);
    $this->assertNoText($node_tag1_title);
    $this->assertText($node_tag1_tag2_title);
    $this->assertNoText($node_no_tags_title);
}