3 namespace Drupal\taxonomy\Tests;
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 // Create three taxonomy terms.
37 $term1 = $this->createTerm($this->vocabulary);
38 $term2 = $this->createTerm($this->vocabulary);
39 $term3 = $this->createTerm($this->vocabulary);
41 // Get the taxonomy storage.
42 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
44 // Indent the second term under the first one.
46 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
47 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
48 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
49 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
52 // Submit the edited form and check for HTML indentation element presence.
53 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
54 $this->assertPattern('|<div class="js-indentation indentation"> </div>|');
56 // Check explicitly that term 2's parent is term 1.
57 $parents = $taxonomy_storage->loadParents($term2->id());
58 $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
60 // Move the second term back out to the root level.
62 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
63 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
64 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
65 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
68 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid' ) . '/overview', $edit, t('Save'));
69 // All terms back at the root level, no indentation should be present.
70 $this->assertNoPattern('|<div class="js-indentation indentation"> </div>|');
72 // Check explicitly that term 2 has no parents.
73 \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
74 $parents = $taxonomy_storage->loadParents($term2->id());
75 $this->assertTrue(empty($parents), 'Term 2 has no parents now');