3 namespace Drupal\Tests\taxonomy\Functional;
5 use Drupal\Component\Utility\Tags;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\taxonomy\Entity\Term;
9 use Drupal\taxonomy\Entity\Vocabulary;
12 * Tests load, save and delete for taxonomy terms.
16 class TermTest extends TaxonomyTestBase {
19 * Vocabulary for testing.
21 * @var \Drupal\taxonomy\VocabularyInterface
23 protected $vocabulary;
26 * Taxonomy term reference field for testing.
28 * @var \Drupal\field\FieldConfigInterface
37 public static $modules = ['block'];
42 protected function setUp() {
45 $this->drupalPlaceBlock('local_actions_block');
46 $this->drupalPlaceBlock('local_tasks_block');
47 $this->drupalPlaceBlock('page_title_block');
49 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
50 $this->vocabulary = $this->createVocabulary();
52 $field_name = 'taxonomy_' . $this->vocabulary->id();
56 $this->vocabulary->id() => $this->vocabulary->id(),
58 'auto_create' => TRUE,
60 $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
61 $this->field = FieldConfig::loadByName('node', 'article', $field_name);
63 entity_get_form_display('node', 'article', 'default')
64 ->setComponent($field_name, [
65 'type' => 'options_select',
68 entity_get_display('node', 'article', 'default')
69 ->setComponent($field_name, [
70 'type' => 'entity_reference_label',
76 * The "parent" field must restrict references to the same vocabulary.
78 public function testParentHandlerSettings() {
79 $vocabulary_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', $this->vocabulary->id());
80 $parent_target_bundles = $vocabulary_fields['parent']->getSetting('handler_settings')['target_bundles'];
81 $this->assertIdentical([$this->vocabulary->id() => $this->vocabulary->id()], $parent_target_bundles);
85 * Test terms in a single and multiple hierarchy.
87 public function testTaxonomyTermHierarchy() {
88 // Create two taxonomy terms.
89 $term1 = $this->createTerm($this->vocabulary);
90 $term2 = $this->createTerm($this->vocabulary);
92 // Get the taxonomy storage.
93 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
95 // Check that hierarchy is flat.
96 $vocabulary = Vocabulary::load($this->vocabulary->id());
97 $this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.');
99 // Edit $term2, setting $term1 as parent.
101 $edit['parent[]'] = [$term1->id()];
102 $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
104 // Check the hierarchy.
105 $children = $taxonomy_storage->loadChildren($term1->id());
106 $parents = $taxonomy_storage->loadParents($term2->id());
107 $this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.');
108 $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
110 // Load and save a term, confirming that parents are still set.
111 $term = Term::load($term2->id());
113 $parents = $taxonomy_storage->loadParents($term2->id());
114 $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
116 // Create a third term and save this as a parent of term2.
117 $term3 = $this->createTerm($this->vocabulary);
118 $term2->parent = [$term1->id(), $term3->id()];
120 $parents = $taxonomy_storage->loadParents($term2->id());
121 $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
125 * Tests that many terms with parents show on each page
127 public function testTaxonomyTermChildTerms() {
128 // Set limit to 10 terms per page. Set variable to 9 so 10 terms appear.
129 $this->config('taxonomy.settings')->set('terms_per_page_admin', '9')->save();
130 $term1 = $this->createTerm($this->vocabulary);
133 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
135 // Create 40 terms. Terms 1-12 get parent of $term1. All others are
137 for ($x = 1; $x <= 40; $x++) {
139 // Set terms in order so we know which terms will be on which pages.
140 $edit['weight'] = $x;
142 // Set terms 1-20 to be children of first term created.
144 $edit['parent'] = $term1->id();
146 $term = $this->createTerm($this->vocabulary, $edit);
147 $children = $taxonomy_storage->loadChildren($term1->id());
148 $parents = $taxonomy_storage->loadParents($term->id());
149 $terms_array[$x] = Term::load($term->id());
153 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
154 $this->assertText($term1->getName(), 'Parent Term is displayed on Page 1');
155 for ($x = 1; $x <= 13; $x++) {
156 $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 1');
160 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
161 $this->assertText($term1->getName(), 'Parent Term is displayed on Page 2');
162 for ($x = 1; $x <= 18; $x++) {
163 $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 2');
167 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 2]]);
168 $this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 3');
169 for ($x = 1; $x <= 17; $x++) {
170 $this->assertNoText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' not found on Page 3');
172 for ($x = 18; $x <= 25; $x++) {
173 $this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 3');
178 * Test that hook_node_$op implementations work correctly.
180 * Save & edit a node and assert that taxonomy terms are saved/loaded properly.
182 public function testTaxonomyNode() {
183 // Create two taxonomy terms.
184 $term1 = $this->createTerm($this->vocabulary);
185 $term2 = $this->createTerm($this->vocabulary);
189 $edit['title[0][value]'] = $this->randomMachineName();
190 $edit['body[0][value]'] = $this->randomMachineName();
191 $edit[$this->field->getName() . '[]'] = $term1->id();
192 $this->drupalPostForm('node/add/article', $edit, t('Save'));
194 // Check that the term is displayed when the node is viewed.
195 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
196 $this->drupalGet('node/' . $node->id());
197 $this->assertText($term1->getName(), 'Term is displayed when viewing the node.');
199 $this->clickLink(t('Edit'));
200 $this->assertText($term1->getName(), 'Term is displayed when editing the node.');
201 $this->drupalPostForm(NULL, [], t('Save'));
202 $this->assertText($term1->getName(), 'Term is displayed after saving the node with no changes.');
204 // Edit the node with a different term.
205 $edit[$this->field->getName() . '[]'] = $term2->id();
206 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
208 $this->drupalGet('node/' . $node->id());
209 $this->assertText($term2->getName(), 'Term is displayed when viewing the node.');
212 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Preview'));
213 $this->assertUniqueText($term2->getName(), 'Term is displayed when previewing the node.');
214 $this->drupalPostForm('node/' . $node->id() . '/edit', NULL, t('Preview'));
215 $this->assertUniqueText($term2->getName(), 'Term is displayed when previewing the node again.');
219 * Test term creation with a free-tagging vocabulary from the node form.
221 public function testNodeTermCreationAndDeletion() {
222 // Enable tags in the vocabulary.
223 $field = $this->field;
224 entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
225 ->setComponent($field->getName(), [
226 'type' => 'entity_reference_autocomplete_tags',
228 'placeholder' => 'Start typing here.',
232 // Prefix the terms with a letter to ensure there is no clash in the first
234 // @see https://www.drupal.org/node/2397691
236 'term1' => 'a' . $this->randomMachineName(),
237 'term2' => 'b' . $this->randomMachineName(),
238 'term3' => 'c' . $this->randomMachineName() . ', ' . $this->randomMachineName(),
239 'term4' => 'd' . $this->randomMachineName(),
243 $edit['title[0][value]'] = $this->randomMachineName();
244 $edit['body[0][value]'] = $this->randomMachineName();
245 // Insert the terms in a comma separated list. Vocabulary 1 is a
246 // free-tagging field created by the default profile.
247 $edit[$field->getName() . '[target_id]'] = Tags::implode($terms);
249 // Verify the placeholder is there.
250 $this->drupalGet('node/add/article');
251 $this->assertRaw('placeholder="Start typing here."', 'Placeholder is present.');
253 // Preview and verify the terms appear but are not created.
254 $this->drupalPostForm(NULL, $edit, t('Preview'));
255 foreach ($terms as $term) {
256 $this->assertText($term, 'The term appears on the node preview.');
258 $tree = $this->container->get('entity.manager')->getStorage('taxonomy_term')->loadTree($this->vocabulary->id());
259 $this->assertTrue(empty($tree), 'The terms are not created on preview.');
261 // taxonomy.module does not maintain its static caches.
262 taxonomy_terms_static_reset();
264 // Save, creating the terms.
265 $this->drupalPostForm('node/add/article', $edit, t('Save'));
266 $this->assertText(t('@type @title has been created.', ['@type' => t('Article'), '@title' => $edit['title[0][value]']]), 'The node was created successfully.');
268 // Verify that the creation message contains a link to a node.
269 $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
270 $this->assert(isset($view_link), 'The message area contains a link to a node');
272 foreach ($terms as $term) {
273 $this->assertText($term, 'The term was saved and appears on the node page.');
276 // Get the created terms.
278 foreach ($terms as $key => $term) {
279 $term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
280 $term_objects[$key] = reset($term_objects[$key]);
284 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
286 // Test editing the node.
287 $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
288 foreach ($terms as $term) {
289 $this->assertText($term, 'The term was retained after edit and still appears on the node page.');
292 // Delete term 1 from the term edit page.
293 $this->drupalGet('taxonomy/term/' . $term_objects['term1']->id() . '/edit');
294 $this->clickLink(t('Delete'));
295 $this->drupalPostForm(NULL, NULL, t('Delete'));
297 // Delete term 2 from the term delete page.
298 $this->drupalGet('taxonomy/term/' . $term_objects['term2']->id() . '/delete');
299 $this->drupalPostForm(NULL, [], t('Delete'));
300 $term_names = [$term_objects['term3']->getName(), $term_objects['term4']->getName()];
302 $this->drupalGet('node/' . $node->id());
304 foreach ($term_names as $term_name) {
305 $this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', ['%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName()]));
307 $this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term1']->getName()]));
308 $this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term2']->getName()]));
312 * Save, edit and delete a term using the user interface.
314 public function testTermInterface() {
315 \Drupal::service('module_installer')->install(['views']);
317 'name[0][value]' => $this->randomMachineName(12),
318 'description[0][value]' => $this->randomMachineName(100),
320 // Explicitly set the parents field to 'root', to ensure that
321 // TermForm::save() handles the invalid term ID correctly.
322 $edit['parent[]'] = [0];
324 // Create the term to edit.
325 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
327 $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
328 $term = reset($terms);
329 $this->assertNotNull($term, 'Term found in database.');
331 // Submitting a term takes us to the add page; we need the List page.
332 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
334 $this->clickLink(t('Edit'));
336 $this->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
337 $this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
340 'name[0][value]' => $this->randomMachineName(14),
341 'description[0][value]' => $this->randomMachineName(102),
345 $this->drupalPostForm('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save'));
347 // Check that the term is still present at admin UI after edit.
348 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
349 $this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
350 $this->assertLink(t('Edit'));
352 // Check the term link can be clicked through to the term page.
353 $this->clickLink($edit['name[0][value]']);
354 $this->assertResponse(200, 'Term page can be accessed via the listing link.');
356 // View the term and check that it is correct.
357 $this->drupalGet('taxonomy/term/' . $term->id());
358 $this->assertText($edit['name[0][value]'], 'The randomly generated term name is present.');
359 $this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
361 // Did this page request display a 'term-listing-heading'?
362 $this->assertTrue($this->xpath('//div[contains(@class, "field--name-description")]'), 'Term page displayed the term description element.');
363 // Check that it does NOT show a description when description is blank.
364 $term->setDescription(NULL);
366 $this->drupalGet('taxonomy/term/' . $term->id());
367 $this->assertFalse($this->xpath('//div[contains(@class, "field--entity-taxonomy-term--description")]'), 'Term page did not display the term description when description was blank.');
369 // Check that the description value is processed.
370 $value = $this->randomMachineName();
371 $term->setDescription($value);
373 $this->assertEqual($term->description->processed, "<p>$value</p>\n");
375 // Check that the term feed page is working.
376 $this->drupalGet('taxonomy/term/' . $term->id() . '/feed');
379 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
380 $this->clickLink(t('Delete'));
381 $this->drupalPostForm(NULL, NULL, t('Delete'));
383 // Assert that the term no longer exists.
384 $this->drupalGet('taxonomy/term/' . $term->id());
385 $this->assertResponse(404, 'The taxonomy term page was not found.');
389 * Save, edit and delete a term using the user interface.
391 public function testTermReorder() {
392 $assert = $this->assertSession();
393 $this->createTerm($this->vocabulary);
394 $this->createTerm($this->vocabulary);
395 $this->createTerm($this->vocabulary);
397 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
399 // Fetch the created terms in the default alphabetical order, i.e. term1
400 // precedes term2 alphabetically, and term2 precedes term3.
401 $taxonomy_storage->resetCache();
402 list($term1, $term2, $term3) = $taxonomy_storage->loadTree($this->vocabulary->id(), 0, NULL, TRUE);
404 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
406 // Each term has four hidden fields, "tid:1:0[tid]", "tid:1:0[parent]",
407 // "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2,
408 // term3, term1 by setting weight property, make term3 a child of term2 by
409 // setting the parent and depth properties, and update all hidden fields.
411 'terms[tid:' . $term2->id() . ':0][term][tid]' => $term2->id(),
412 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
413 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
414 'terms[tid:' . $term3->id() . ':0][term][tid]' => $term3->id(),
415 'terms[tid:' . $term3->id() . ':0][term][parent]' => $term2->id(),
416 'terms[tid:' . $term3->id() . ':0][term][depth]' => 1,
417 'terms[tid:' . $term1->id() . ':0][term][tid]' => $term1->id(),
418 'terms[tid:' . $term1->id() . ':0][term][parent]' => 0,
419 'terms[tid:' . $term1->id() . ':0][term][depth]' => 0,
421 // Because we can't post hidden form elements, we have to change them in
422 // code here, and then submit.
423 foreach ($hidden_edit as $field => $value) {
424 $node = $assert->hiddenFieldExists($field);
425 $node->setValue($value);
427 // Edit non-hidden elements within drupalPostForm().
429 'terms[tid:' . $term2->id() . ':0][weight]' => 0,
430 'terms[tid:' . $term3->id() . ':0][weight]' => 1,
431 'terms[tid:' . $term1->id() . ':0][weight]' => 2,
433 $this->drupalPostForm(NULL, $edit, 'Save');
435 $taxonomy_storage->resetCache();
436 $terms = $taxonomy_storage->loadTree($this->vocabulary->id());
437 $this->assertEqual($terms[0]->tid, $term2->id(), 'Term 2 was moved above term 1.');
438 $this->assertEqual($terms[1]->parents, [$term2->id()], 'Term 3 was made a child of term 2.');
439 $this->assertEqual($terms[2]->tid, $term1->id(), 'Term 1 was moved below term 2.');
441 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', [], t('Reset to alphabetical'));
442 // Submit confirmation form.
443 $this->drupalPostForm(NULL, [], t('Reset to alphabetical'));
444 // Ensure form redirected back to overview.
445 $this->assertUrl('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
447 $taxonomy_storage->resetCache();
448 $terms = $taxonomy_storage->loadTree($this->vocabulary->id(), 0, NULL, TRUE);
449 $this->assertEqual($terms[0]->id(), $term1->id(), 'Term 1 was moved to back above term 2.');
450 $this->assertEqual($terms[1]->id(), $term2->id(), 'Term 2 was moved to back below term 1.');
451 $this->assertEqual($terms[2]->id(), $term3->id(), 'Term 3 is still below term 2.');
452 $this->assertEqual($terms[2]->parents, [$term2->id()], 'Term 3 is still a child of term 2.');
456 * Test saving a term with multiple parents through the UI.
458 public function testTermMultipleParentsInterface() {
459 // Add a new term to the vocabulary so that we can have multiple parents.
460 $parent = $this->createTerm($this->vocabulary);
462 // Add a new term with multiple parents.
464 'name[0][value]' => $this->randomMachineName(12),
465 'description[0][value]' => $this->randomMachineName(100),
466 'parent[]' => [0, $parent->id()],
468 // Save the new term.
469 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
471 // Check that the term was successfully created.
472 $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
473 $term = reset($terms);
474 $this->assertNotNull($term, 'Term found in database.');
475 $this->assertEqual($edit['name[0][value]'], $term->getName(), 'Term name was successfully saved.');
476 $this->assertEqual($edit['description[0][value]'], $term->getDescription(), 'Term description was successfully saved.');
477 // Check that the parent tid is still there. The other parent (<root>) is
478 // not added by \Drupal\taxonomy\TermStorageInterface::loadParents().
479 $parents = $this->container->get('entity.manager')->getStorage('taxonomy_term')->loadParents($term->id());
480 $parent = reset($parents);
481 $this->assertEqual($edit['parent[]'][1], $parent->id(), 'Term parents were successfully saved.');
485 * Test taxonomy_term_load_multiple_by_name().
487 public function testTaxonomyGetTermByName() {
488 $term = $this->createTerm($this->vocabulary);
490 // Load the term with the exact name.
491 $terms = taxonomy_term_load_multiple_by_name($term->getName());
492 $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name.');
494 // Load the term with space concatenated.
495 $terms = taxonomy_term_load_multiple_by_name(' ' . $term->getName() . ' ');
496 $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with extra whitespace.');
498 // Load the term with name uppercased.
499 $terms = taxonomy_term_load_multiple_by_name(strtoupper($term->getName()));
500 $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with uppercased name.');
502 // Load the term with name lowercased.
503 $terms = taxonomy_term_load_multiple_by_name(strtolower($term->getName()));
504 $this->assertTrue(isset($terms[$term->id()]), 'Term loaded with lowercased name.');
506 // Try to load an invalid term name.
507 $terms = taxonomy_term_load_multiple_by_name('Banana');
508 $this->assertFalse($terms, 'No term loaded with an invalid name.');
510 // Try to load the term using a substring of the name.
511 $terms = taxonomy_term_load_multiple_by_name(mb_substr($term->getName(), 2), 'No term loaded with a substring of the name.');
512 $this->assertFalse($terms);
514 // Create a new term in a different vocabulary with the same name.
515 $new_vocabulary = $this->createVocabulary();
516 $new_term = Term::create([
517 'name' => $term->getName(),
518 'vid' => $new_vocabulary->id(),
522 // Load multiple terms with the same name.
523 $terms = taxonomy_term_load_multiple_by_name($term->getName());
524 $this->assertEqual(count($terms), 2, 'Two terms loaded with the same name.');
526 // Load single term when restricted to one vocabulary.
527 $terms = taxonomy_term_load_multiple_by_name($term->getName(), $this->vocabulary->id());
528 $this->assertEqual(count($terms), 1, 'One term loaded when restricted by vocabulary.');
529 $this->assertTrue(isset($terms[$term->id()]), 'Term loaded using exact name and vocabulary machine name.');
531 // Create a new term with another name.
532 $term2 = $this->createTerm($this->vocabulary);
534 // Try to load a term by name that doesn't exist in this vocabulary but
535 // exists in another vocabulary.
536 $terms = taxonomy_term_load_multiple_by_name($term2->getName(), $new_vocabulary->id());
537 $this->assertFalse($terms, 'Invalid term name restricted by vocabulary machine name not loaded.');
539 // Try to load terms filtering by a non-existing vocabulary.
540 $terms = taxonomy_term_load_multiple_by_name($term2->getName(), 'non_existing_vocabulary');
541 $this->assertEqual(count($terms), 0, 'No terms loaded when restricted by a non-existing vocabulary.');
545 * Tests that editing and saving a node with no changes works correctly.
547 public function testReSavingTags() {
548 // Enable tags in the vocabulary.
549 $field = $this->field;
550 entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
551 ->setComponent($field->getName(), [
552 'type' => 'entity_reference_autocomplete_tags',
556 // Create a term and a node using it.
557 $term = $this->createTerm($this->vocabulary);
559 $edit['title[0][value]'] = $this->randomMachineName(8);
560 $edit['body[0][value]'] = $this->randomMachineName(16);
561 $edit[$this->field->getName() . '[target_id]'] = $term->getName();
562 $this->drupalPostForm('node/add/article', $edit, t('Save'));
564 // Check that the term is displayed when editing and saving the node with no
566 $this->clickLink(t('Edit'));
567 $this->assertRaw($term->getName(), 'Term is displayed when editing the node.');
568 $this->drupalPostForm(NULL, [], t('Save'));
569 $this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.');
573 * Check the breadcrumb on edit and delete a term page.
575 public function testTermBreadcrumbs() {
577 'name[0][value]' => $this->randomMachineName(14),
578 'description[0][value]' => $this->randomMachineName(100),
583 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, 'Save');
585 $terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
586 $term = reset($terms);
587 $this->assertNotNull($term, 'Term found in database.');
589 // Check the breadcrumb on the term edit page.
590 $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
591 $breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
592 $this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
593 $this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
594 $this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term edit page.');
595 $this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');
597 // Check the breadcrumb on the term delete page.
598 $this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
599 $breadcrumbs = $this->getSession()->getPage()->findAll('css', 'nav.breadcrumb ol li a');
600 $this->assertIdentical(count($breadcrumbs), 2, 'The breadcrumbs are present on the page.');
601 $this->assertIdentical($breadcrumbs[0]->getText(), 'Home', 'First breadcrumb text is Home');
602 $this->assertIdentical($breadcrumbs[1]->getText(), $term->label(), 'Second breadcrumb text is term name on term delete page.');
603 $this->assertEscaped($breadcrumbs[1]->getText(), 'breadcrumbs displayed and escaped.');