function TermTest::testTermInterface in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/taxonomy/src/Tests/TermTest.php \Drupal\taxonomy\Tests\TermTest::testTermInterface()
Save, edit and delete a term using the user interface.
File
- core/
modules/ taxonomy/ src/ Tests/ TermTest.php, line 306 - Contains \Drupal\taxonomy\Tests\TermTest.
Class
- TermTest
- Tests load, save and delete for taxonomy terms.
Namespace
Drupal\taxonomy\TestsCode
function testTermInterface() {
\Drupal::service('module_installer')
->install(array(
'views',
));
$edit = array(
'name[0][value]' => $this
->randomMachineName(12),
'description[0][value]' => $this
->randomMachineName(100),
);
// Explicitly set the parents field to 'root', to ensure that
// TermForm::save() handles the invalid term ID correctly.
$edit['parent[]'] = array(
0,
);
// Create the term to edit.
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/add', $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
$this
->assertNotNull($term, 'Term found in database.');
// Submitting a term takes us to the add page; we need the List page.
$this
->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/overview');
$this
->clickLink(t('Edit'));
$this
->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
$this
->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
$edit = array(
'name[0][value]' => $this
->randomMachineName(14),
'description[0][value]' => $this
->randomMachineName(102),
);
// Edit the term.
$this
->drupalPostForm('taxonomy/term/' . $term
->id() . '/edit', $edit, t('Save'));
// Check that the term is still present at admin UI after edit.
$this
->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary
->id() . '/overview');
$this
->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this
->assertLink(t('Edit'));
// Check the term link can be clicked through to the term page.
$this
->clickLink($edit['name[0][value]']);
$this
->assertResponse(200, 'Term page can be accessed via the listing link.');
// View the term and check that it is correct.
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
$this
->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
// Did this page request display a 'term-listing-heading'?
$this
->assertTrue($this
->xpath('//div[contains(@class, "field--name-description")]'), 'Term page displayed the term description element.');
// Check that it does NOT show a description when description is blank.
$term
->setDescription(NULL);
$term
->save();
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertFalse($this
->xpath('//div[contains(@class, "field--entity-taxonomy-term--description")]'), 'Term page did not display the term description when description was blank.');
// Check that the description value is processed.
$value = $this
->randomMachineName();
$term
->setDescription($value);
$term
->save();
$this
->assertEqual($term->description->processed, "<p>{$value}</p>\n");
// Check that the term feed page is working.
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/feed');
// Delete the term.
$this
->drupalGet('taxonomy/term/' . $term
->id() . '/edit');
$this
->clickLink(t('Delete'));
$this
->drupalPostForm(NULL, NULL, t('Delete'));
// Assert that the term no longer exists.
$this
->drupalGet('taxonomy/term/' . $term
->id());
$this
->assertResponse(404, 'The taxonomy term page was not found.');
}