annotate core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\taxonomy\Tests;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Ensure that the term indentation works properly.
Chris@0 7 *
Chris@0 8 * @group taxonomy
Chris@0 9 */
Chris@0 10 class TaxonomyTermIndentationTest extends TaxonomyTestBase {
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Modules to enable.
Chris@0 14 *
Chris@0 15 * @var array
Chris@0 16 */
Chris@0 17 public static $modules = ['taxonomy'];
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Vocabulary for testing.
Chris@0 21 *
Chris@0 22 * @var \Drupal\taxonomy\VocabularyInterface
Chris@0 23 */
Chris@0 24 protected $vocabulary;
Chris@0 25
Chris@0 26 protected function setUp() {
Chris@0 27 parent::setUp();
Chris@0 28 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
Chris@0 29 $this->vocabulary = $this->createVocabulary();
Chris@0 30 }
Chris@0 31
Chris@0 32 /**
Chris@0 33 * Tests term indentation.
Chris@0 34 */
Chris@0 35 public function testTermIndentation() {
Chris@0 36 // Create three taxonomy terms.
Chris@0 37 $term1 = $this->createTerm($this->vocabulary);
Chris@0 38 $term2 = $this->createTerm($this->vocabulary);
Chris@0 39 $term3 = $this->createTerm($this->vocabulary);
Chris@0 40
Chris@0 41 // Get the taxonomy storage.
Chris@0 42 $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
Chris@0 43
Chris@0 44 // Indent the second term under the first one.
Chris@0 45 $edit = [
Chris@0 46 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
Chris@0 47 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
Chris@0 48 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
Chris@0 49 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
Chris@0 50 ];
Chris@0 51
Chris@0 52 // Submit the edited form and check for HTML indentation element presence.
Chris@0 53 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
Chris@0 54 $this->assertPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
Chris@0 55
Chris@0 56 // Check explicitly that term 2's parent is term 1.
Chris@0 57 $parents = $taxonomy_storage->loadParents($term2->id());
Chris@0 58 $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
Chris@0 59
Chris@0 60 // Move the second term back out to the root level.
Chris@0 61 $edit = [
Chris@0 62 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
Chris@0 63 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
Chris@0 64 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
Chris@0 65 'terms[tid:' . $term2->id() . ':0][weight]' => 1,
Chris@0 66 ];
Chris@0 67
Chris@0 68 $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
Chris@0 69 // All terms back at the root level, no indentation should be present.
Chris@0 70 $this->assertNoPattern('|<div class="js-indentation indentation">&nbsp;</div>|');
Chris@0 71
Chris@0 72 // Check explicitly that term 2 has no parents.
Chris@0 73 \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache();
Chris@0 74 $parents = $taxonomy_storage->loadParents($term2->id());
Chris@0 75 $this->assertTrue(empty($parents), 'Term 2 has no parents now');
Chris@0 76 }
Chris@0 77
Chris@0 78 }