class BundleDeleteFormTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/BundleDeleteFormTest.php \Drupal\KernelTests\Core\Entity\BundleDeleteFormTest
Tests the bundle deletion form.
Attributes
#[CoversClass(BundleEntityDeleteForm::class)]
#[Group('Entity')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\Core\Entity\BundleDeleteFormTest uses \Drupal\Tests\user\Traits\UserCreationTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of BundleDeleteFormTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BundleDeleteFormTest.php, line 18
Namespace
Drupal\KernelTests\Core\EntityView source
class BundleDeleteFormTest extends KernelTestBase {
use UserCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'user',
'entity_test',
];
/**
* The entity type manager.
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->installEntitySchema('user');
$this->installEntitySchema('entity_test_with_bundle');
$this->entityTypeManager
->getStorage('entity_test_bundle')
->create([
'label' => 'Test bundle',
'id' => 'test',
])
->save();
// Create a user who can see the bundle delete form.
$user = $this->createUser([
'administer entity_test_bundle content',
'administer entity_test_with_bundle content',
]);
$this->setCurrentUser($user);
}
/**
* Tests that deleting a bundle with content entities is not allowed.
*/
public function testBundleEntityDeleteForm() : void {
$test_entity = $this->entityTypeManager
->getStorage('entity_test_with_bundle')
->create([
'type' => 'test',
]);
$test_entity->save();
// Attempt to delete the bundle, which should not be allowed.
$this->drupalGet('/entity_test_bundle/delete/test');
$this->assertSession()
->pageTextContains('Test bundle is used by 1 test entity with bundle on your site. You may not remove this test entity bundle until you have removed all of the Test bundle test entity with bundle entities.');
$this->assertSession()
->pageTextNotContains('This action cannot be undone.');
// Delete the entity.
$test_entity->delete();
// Attempt to delete the bundle, which should now be allowed.
$this->drupalGet('/entity_test_bundle/delete/test');
$this->assertSession()
->pageTextContains('This action cannot be undone.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.