You are here

public function DeleteParentWarningTest::testDeleteWarning in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/DeleteParentWarningTest.php \Drupal\Tests\entity_hierarchy\Functional\DeleteParentWarningTest::testDeleteWarning()

Tests delete warning.

File

tests/src/Functional/DeleteParentWarningTest.php, line 49

Class

DeleteParentWarningTest
Defines a class for testing the warnings on delete form.

Namespace

Drupal\Tests\entity_hierarchy\Functional

Code

public function testDeleteWarning() {
  $entities = $this
    ->createChildEntities($this->parent
    ->id());
  $first_child = reset($entities);
  $grandchildren = $this
    ->createChildEntities($first_child
    ->id(), 3);
  $this
    ->drupalLogin($this
    ->drupalCreateUser([], NULL, TRUE));
  $this
    ->drupalGet($this->parent
    ->toUrl('delete-form'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains('This Test entity has 5 children, deleting this item will move those items to the root of the hierarchy.');
  foreach ($entities as $entity) {
    $assert
      ->pageTextContains($entity
      ->label());
  }

  // Now test one with a grandparent.
  $this
    ->drupalGet($first_child
    ->toUrl('delete-form'));
  $assert = $this
    ->assertSession();
  $assert
    ->pageTextContains(sprintf('This Test entity has 3 children, deleting this item will change their parent to be %s.', $this->parent
    ->label()));
  foreach ($grandchildren as $entity) {
    $assert
      ->pageTextContains($entity
      ->label());
  }
}