Chris@0: drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access'])); Chris@0: $this->vocabulary = $this->createVocabulary(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests term indentation. Chris@0: */ Chris@0: public function testTermIndentation() { Chris@0: // Create three taxonomy terms. Chris@0: $term1 = $this->createTerm($this->vocabulary); Chris@0: $term2 = $this->createTerm($this->vocabulary); Chris@0: $term3 = $this->createTerm($this->vocabulary); Chris@0: Chris@0: // Get the taxonomy storage. Chris@0: $taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term'); Chris@0: Chris@0: // Indent the second term under the first one. Chris@0: $edit = [ Chris@0: 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2, Chris@0: 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1, Chris@0: 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1, Chris@0: 'terms[tid:' . $term2->id() . ':0][weight]' => 1, Chris@0: ]; Chris@0: Chris@0: // Submit the edited form and check for HTML indentation element presence. Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save')); Chris@0: $this->assertPattern('|
 
|'); Chris@0: Chris@0: // Check explicitly that term 2's parent is term 1. Chris@0: $parents = $taxonomy_storage->loadParents($term2->id()); Chris@0: $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent'); Chris@0: Chris@0: // Move the second term back out to the root level. Chris@0: $edit = [ Chris@0: 'terms[tid:' . $term2->id() . ':0][term][tid]' => 2, Chris@0: 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0, Chris@0: 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0, Chris@0: 'terms[tid:' . $term2->id() . ':0][weight]' => 1, Chris@0: ]; Chris@0: Chris@0: $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save')); Chris@0: // All terms back at the root level, no indentation should be present. Chris@0: $this->assertNoPattern('|
 
|'); Chris@0: Chris@0: // Check explicitly that term 2 has no parents. Chris@0: \Drupal::entityManager()->getStorage('taxonomy_term')->resetCache(); Chris@0: $parents = $taxonomy_storage->loadParents($term2->id()); Chris@0: $this->assertTrue(empty($parents), 'Term 2 has no parents now'); Chris@0: } Chris@0: Chris@0: }