Mercurial > hg > isophonics-drupal-site
comparison core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\taxonomy\Tests; | |
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 // Create three taxonomy terms. | |
37 $term1 = $this->createTerm($this->vocabulary); | |
38 $term2 = $this->createTerm($this->vocabulary); | |
39 $term3 = $this->createTerm($this->vocabulary); | |
40 | |
41 // Get the taxonomy storage. | |
42 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term'); | |
43 | |
44 // Indent the second term under the first one. | |
45 $edit = [ | |
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, | |
50 ]; | |
51 | |
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>|'); | |
55 | |
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'); | |
59 | |
60 // Move the second term back out to the root level. | |
61 $edit = [ | |
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, | |
66 ]; | |
67 | |
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>|'); | |
71 | |
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'); | |
76 } | |
77 | |
78 } |