You are here

protected function TermParentsTest::doTestEditingSingleParent in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/TermParentsTest.php \Drupal\Tests\taxonomy\Functional\TermParentsTest::doTestEditingSingleParent()
  2. 9 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.

File

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

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
    ->submitForm([], '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
    ->submitForm([], '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
    ->submitForm([], '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
    ->submitForm([], '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
    ->submitForm([], 'Save');
  $this
    ->assertParentsUnchanged($term_5);
  $terms[] = $term_5;
  return $terms;
}