public function SchedulerDeleteEntityTest::testDeleteEntityWhenSchedulingIsRequired in Scheduler 2.x
Tests the deletion of an entity when the scheduler dates are required.
Check that it is possible to delete an entity that does not have a publishing date set, when scheduled publishing is required. Likewise for unpublishing.
@dataProvider dataStandardEntityTypes()
See also
https://www.drupal.org/project/scheduler/issues/1614880
File
- tests/
src/ Functional/ SchedulerDeleteEntityTest.php, line 26
Class
- SchedulerDeleteEntityTest
- Tests deletion of entities enabled for Scheduler.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testDeleteEntityWhenSchedulingIsRequired($entityTypeId, $bundle) {
// Log in.
$this
->drupalLogin($this->adminUser);
// Create a published and an unpublished entity, with no scheduled dates.
$published_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => TRUE,
]);
$unpublished_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
]);
// Make scheduled publishing and unpublishing required.
$bundle_field_name = $published_entity
->getEntityType()
->get('entity_keys')['bundle'];
$published_entity->{$bundle_field_name}->entity
->setThirdPartySetting('scheduler', 'publish_required', TRUE)
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
$entity_type_label = $published_entity
->getEntityType()
->getSingularLabel();
// Check that deleting the entity does not throw form validation errors.
$this
->drupalGet($published_entity
->toUrl('edit-form'));
$this
->clickLink('Delete');
// The text 'error message' is used in a header h2 html tag which is
// normally made hidden from browsers but will be in the page source.
// It is also good when testing for the absense of something to also test
// for the presence of text, hence the second assertion for each check.
$this
->assertSession()
->pageTextNotContains('Error message');
$this
->assertSession()
->pageTextContains("Are you sure you want to delete the {$entity_type_label} {$published_entity->label()}");
// Do the same test for the unpublished entity.
$this
->drupalGet($unpublished_entity
->toUrl('edit-form'));
$this
->clickLink('Delete');
$this
->assertSession()
->pageTextNotContains('Error message');
$this
->assertSession()
->pageTextContains("Are you sure you want to delete the {$entity_type_label} {$unpublished_entity->label()}");
}