3 namespace Drupal\Tests\taxonomy\Functional;
6 * Ensure that the term indentation works properly.
10 class TaxonomyTermIndentationTest extends TaxonomyTestBase {
17 public static $modules = ['taxonomy'];
20 * Vocabulary for testing.
22 * @var \Drupal\taxonomy\VocabularyInterface
24 protected $vocabulary;
26 protected function setUp() {
28 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
29 $this->vocabulary = $this->createVocabulary();
33 * Tests term indentation.
35 public function testTermIndentation() {
36 $assert = $this->assertSession();
37 // Create three taxonomy terms.
38 $term1 = $this->createTerm($this->vocabulary);
39 $term2 = $this->createTerm($this->vocabulary);
40 $term3 = $this->createTerm($this->vocabulary);
42 // Get the taxonomy storage.
43 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
45 // Indent the second term under the first one.
46 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
48 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
49 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
50 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
52 // Because we can't post hidden form elements, we have to change them in
53 // code here, and then submit.
54 foreach ($hidden_edit as $field => $value) {
55 $node = $assert->hiddenFieldExists($field);
56 $node->setValue($value);
59 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
61 // Submit the edited form and check for HTML indentation element presence.
62 $this->drupalPostForm(NULL, $edit, t('Save'));
63 $this->assertPattern('|<div class="js-indentation indentation"> </div>|');
65 // Check explicitly that term 2's parent is term 1.
66 $parents = $taxonomy_storage->loadParents($term2->id());
67 $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
69 // Move the second term back out to the root level.
70 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
72 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
73 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
74 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
76 // Because we can't post hidden form elements, we have to change them in
77 // code here, and then submit.
78 foreach ($hidden_edit as $field => $value) {
79 $node = $assert->hiddenFieldExists($field);
80 $node->setValue($value);
83 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
85 $this->drupalPostForm(NULL, $edit, t('Save'));
86 // All terms back at the root level, no indentation should be present.
87 $this->assertSession()->responseNotMatches('|<div class="js-indentation indentation"> </div>|');
89 // Check explicitly that term 2 has no parents.
90 \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
91 $parents = $taxonomy_storage->loadParents($term2->id());
92 $this->assertTrue(empty($parents), 'Term 2 has no parents now');