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