You are here

protected function TermParentsTest::doTestEditingSingleParent 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::doTestEditingSingleParent()
  2. 10 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::doTestEditingSingleParent()

Performs tests that edit terms with a single parent

Return value

\Drupal\taxonomy\TermInterface[] A list of terms created for testing.

2 calls to TermParentsTest::doTestEditingSingleParent()
TermParentsTest::testEditingParents in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Tests editing the parents of existing terms.
TermParentsTest::testEditingParentsWithDisabledFormElement in core/modules/taxonomy/tests/src/Functional/TermParentsTest.php
Tests specifying parents when creating terms and a disabled parent form.

File

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

Class

TermParentsTest
Tests managing taxonomy parents through the user interface.

Namespace

Drupal\Tests\taxonomy\Functional

Code

protected function doTestEditingSingleParent() {
  $terms = [];

  // Create two terms without any parents.
  $term_1 = $this
    ->createTerm('Test term 1');
  $this
    ->drupalGet($term_1
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>', TRUE);
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_1);
  $terms[] = $term_1;
  $term_2 = $this
    ->createTerm('Test term 2');
  $this
    ->drupalGet($term_2
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>', TRUE);
  $this
    ->assertParentOption('Test term 1');
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_2);
  $terms[] = $term_2;

  // Create two terms with the previously created terms as parents,
  // respectively.
  $term_3 = $this
    ->createTerm('Test term 3', [
    $term_1
      ->id(),
  ]);
  $this
    ->drupalGet($term_3
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>');
  $this
    ->assertParentOption('Test term 1', TRUE);
  $this
    ->assertParentOption('Test term 2');
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_3);
  $terms[] = $term_3;
  $term_4 = $this
    ->createTerm('Test term 4', [
    $term_2
      ->id(),
  ]);
  $this
    ->drupalGet($term_4
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>');
  $this
    ->assertParentOption('Test term 1');
  $this
    ->assertParentOption('-Test term 3');
  $this
    ->assertParentOption('Test term 2', TRUE);
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_4);
  $terms[] = $term_4;

  // Create a term with term 3 as parent.
  $term_5 = $this
    ->createTerm('Test term 5', [
    $term_3
      ->id(),
  ]);
  $this
    ->drupalGet($term_5
    ->toUrl('edit-form'));
  $this
    ->assertParentOption('<root>');
  $this
    ->assertParentOption('Test term 1');
  $this
    ->assertParentOption('-Test term 3', TRUE);
  $this
    ->assertParentOption('Test term 2');
  $this
    ->assertParentOption('-Test term 4');
  $this
    ->drupalPostForm(NULL, [], 'Save');
  $this
    ->assertParentsUnchanged($term_5);
  $terms[] = $term_5;
  return $terms;
}