TaxonomyTermIndentationTest.php in Zircon Profile 8
File
core/modules/taxonomy/src/Tests/TaxonomyTermIndentationTest.php
View source
<?php
namespace Drupal\taxonomy\Tests;
class TaxonomyTermIndentationTest extends TaxonomyTestBase {
public static $modules = array(
'taxonomy',
);
protected $vocabulary;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'administer taxonomy',
'bypass node access',
]));
$this->vocabulary = $this
->createVocabulary();
}
function testTermIndentation() {
$term1 = $this
->createTerm($this->vocabulary);
$term2 = $this
->createTerm($this->vocabulary);
$term3 = $this
->createTerm($this->vocabulary);
$taxonomy_storage = $this->container
->get('entity.manager')
->getStorage('taxonomy_term');
$edit = array(
'terms[tid:' . $term2
->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2
->id() . ':0][term][parent]' => 1,
'terms[tid:' . $term2
->id() . ':0][term][depth]' => 1,
'terms[tid:' . $term2
->id() . ':0][weight]' => 1,
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->get('vid') . '/overview', $edit, t('Save'));
$this
->assertPattern('|<div class="js-indentation indentation"> </div>|');
$parents = $taxonomy_storage
->loadParents($term2
->id());
$this
->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
$edit = array(
'terms[tid:' . $term2
->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2
->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2
->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term2
->id() . ':0][weight]' => 1,
);
$this
->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
->get('vid') . '/overview', $edit, t('Save'));
$this
->assertNoPattern('|<div class="js-indentation indentation"> </div>|');
\Drupal::entityManager()
->getStorage('taxonomy_term')
->resetCache();
$parents = $taxonomy_storage
->loadParents($term2
->id());
$this
->assertTrue(empty($parents), 'Term 2 has no parents now');
}
}