SchedulerDeleteEntityTest.php in Scheduler 2.x
File
tests/src/Functional/SchedulerDeleteEntityTest.php
View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerDeleteEntityTest extends SchedulerBrowserTestBase {
public function testDeleteEntityWhenSchedulingIsRequired($entityTypeId, $bundle) {
$this
->drupalLogin($this->adminUser);
$published_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => TRUE,
]);
$unpublished_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
]);
$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();
$this
->drupalGet($published_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} {$published_entity->label()}");
$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()}");
}
public function testDeleteEntityWithPastDates($entityTypeId, $bundle) {
$this
->drupalLogin($this->adminUser);
$published_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => TRUE,
'unpublish_on' => strtotime('- 2 day'),
]);
$unpublished_entity = $this
->createEntity($entityTypeId, $bundle, [
'status' => FALSE,
'publish_on' => strtotime('- 2 day'),
]);
$entity_type_label = $published_entity
->getEntityType()
->getSingularLabel();
$this
->drupalGet($published_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} {$published_entity->label()}");
$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()}");
}
}