Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\taxonomy\Functional; | |
4 | |
5 /** | |
6 * Ensure that the term indentation works properly. | |
7 * | |
8 * @group taxonomy | |
9 */ | |
10 class TaxonomyTermIndentationTest extends TaxonomyTestBase { | |
11 | |
12 /** | |
13 * Modules to enable. | |
14 * | |
15 * @var array | |
16 */ | |
17 public static $modules = ['taxonomy']; | |
18 | |
19 /** | |
20 * Vocabulary for testing. | |
21 * | |
22 * @var \Drupal\taxonomy\VocabularyInterface | |
23 */ | |
24 protected $vocabulary; | |
25 | |
26 protected function setUp() { | |
27 parent::setUp(); | |
28 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access'])); | |
29 $this->vocabulary = $this->createVocabulary(); | |
30 } | |
31 | |
32 /** | |
33 * Tests term indentation. | |
34 */ | |
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); | |
41 | |
42 // Get the taxonomy storage. | |
43 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term'); | |
44 | |
45 // Indent the second term under the first one. | |
46 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview'); | |
47 $hidden_edit = [ | |
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, | |
51 ]; | |
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); | |
57 } | |
58 $edit = [ | |
59 'terms[tid:' . $term2->id() . ':0][weight]' => 1, | |
60 ]; | |
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>|'); | |
64 | |
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'); | |
68 | |
69 // Move the second term back out to the root level. | |
70 $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview'); | |
71 $hidden_edit = [ | |
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, | |
75 ]; | |
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); | |
81 } | |
82 $edit = [ | |
83 'terms[tid:' . $term2->id() . ':0][weight]' => 1, | |
84 ]; | |
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>|'); | |
88 | |
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'); | |
93 } | |
94 | |
95 } |