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