function BundleDeleteFormTest::testBundleEntityDeleteForm

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/BundleDeleteFormTest.php \Drupal\KernelTests\Core\Entity\BundleDeleteFormTest::testBundleEntityDeleteForm()

Tests that deleting a bundle with content entities is not allowed.

File

core/tests/Drupal/KernelTests/Core/Entity/BundleDeleteFormTest.php, line 66

Class

BundleDeleteFormTest
Tests the bundle deletion form.

Namespace

Drupal\KernelTests\Core\Entity

Code

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.