You are here

public function TermParentsTest::testEditingParentsWithDisabledFormElement in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::testEditingParentsWithDisabledFormElement()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::testEditingParentsWithDisabledFormElement()

Tests specifying parents when creating terms and a disabled parent form.

File

core/modules/taxonomy/tests/src/Functional/TermParentsTest.php, line 161

Class

TermParentsTest
Tests managing taxonomy parents through the user interface.

Namespace

Drupal\Tests\taxonomy\Functional

Code

public function testEditingParentsWithDisabledFormElement() {

  // Disable the parent form element.
  $this->state
    ->set('taxonomy_test.disable_parent_form_element', TRUE);
  $this
    ->drupalGet("/admin/structure/taxonomy/manage/{$this->vocabularyId}/add");
  $this
    ->assertSession()
    ->fieldDisabled('Parent terms');
  $terms = $this
    ->doTestEditingSingleParent();
  $term_5 = array_pop($terms);
  $term_4 = array_pop($terms);

  // Create a term with multiple parents.
  $term_6 = $this
    ->createTerm('Test term 6', [
    // When the parent form element is disabled, its default value is used as
    // the value which gets populated in ascending order of term IDs.
    $term_4
      ->id(),
    $term_5
      ->id(),
  ]);
  $this
    ->drupalGet($term_6
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>');
  $this
    ->assertParentOption('Test term 1');
  $this
    ->assertParentOption('-Test term 3');
  $this
    ->assertParentOption('--Test term 5', TRUE);
  $this
    ->assertParentOption('Test term 2');
  $this
    ->assertParentOption('-Test term 4', TRUE);
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_6);
}