DeleteParentWarningTest.php in Entity Reference Hierarchy 8.2
File
tests/src/Functional/DeleteParentWarningTest.php
View source
<?php
namespace Drupal\Tests\entity_hierarchy\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\entity_hierarchy\Traits\EntityHierarchyTestTrait;
class DeleteParentWarningTest extends BrowserTestBase {
use EntityHierarchyTestTrait;
const FIELD_NAME = 'parents';
const ENTITY_TYPE = 'entity_test';
protected $defaultTheme = 'stark';
protected static $modules = [
'entity_hierarchy',
'entity_test',
'system',
'user',
'dbal',
'field',
];
protected function setUp() {
parent::setUp();
$this
->setupEntityHierarchyField(static::ENTITY_TYPE, static::ENTITY_TYPE, static::FIELD_NAME);
$this
->additionalSetup();
}
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());
}
$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());
}
}
}