class DeleteActionTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php \Drupal\KernelTests\Core\Action\DeleteActionTest
- 10 core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php \Drupal\KernelTests\Core\Action\DeleteActionTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Action/DeleteActionTest.php \Drupal\KernelTests\Core\Action\DeleteActionTest
@group Action
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Action\DeleteActionTest implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of DeleteActionTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Action/ DeleteActionTest.php, line 14
Namespace
Drupal\KernelTests\Core\ActionView source
class DeleteActionTest extends KernelTestBase {
protected $testUser;
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'entity_test',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('entity_test_mulrevpub');
$this->installEntitySchema('user');
$this->installSchema('system', [
'sequences',
]);
$this->testUser = User::create([
'name' => 'foobar',
'mail' => 'foobar@example.com',
]);
$this->testUser
->save();
\Drupal::service('current_user')->setAccount($this->testUser);
}
/**
* @covers \Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver::getDerivativeDefinitions
*/
public function testGetDerivativeDefinitions() {
$deriver = new EntityDeleteActionDeriver(\Drupal::entityTypeManager(), \Drupal::translation());
$this->assertEquals([
'entity_test_mulrevpub' => [
'type' => 'entity_test_mulrevpub',
'label' => 'Delete test entity - revisions, data table, and published interface',
'action_label' => 'Delete',
'confirm_form_route_name' => 'entity.entity_test_mulrevpub.delete_multiple_form',
],
'entity_test_revpub' => [
'type' => 'entity_test_revpub',
'label' => 'Delete test entity - revisions and publishing status',
'action_label' => 'Delete',
'confirm_form_route_name' => 'entity.entity_test_revpub.delete_multiple_form',
],
'entity_test_rev' => [
'type' => 'entity_test_rev',
'label' => 'Delete test entity - revisions',
'action_label' => 'Delete',
'confirm_form_route_name' => 'entity.entity_test_rev.delete_multiple_form',
],
], $deriver->getDerivativeDefinitions([
'action_label' => 'Delete',
]));
}
/**
* @covers \Drupal\Core\Action\Plugin\Action\DeleteAction::execute
*/
public function testDeleteAction() {
$entity = EntityTestMulRevPub::create([
'name' => 'test',
]);
$entity->save();
$action = Action::create([
'id' => 'entity_delete_action',
'plugin' => 'entity:delete_action:entity_test_mulrevpub',
]);
$action->save();
$action->execute([
$entity,
]);
$this->assertSame([
'module' => [
'entity_test',
],
], $action->getDependencies());
/** @var \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store */
$temp_store = \Drupal::service('tempstore.private');
$store_entries = $temp_store->get('entity_delete_multiple_confirm')
->get($this->testUser
->id() . ':entity_test_mulrevpub');
$this->assertSame([
$this->testUser
->id() => [
'en' => 'en',
],
], $store_entries);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.