View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerNonEnabledTypeTest extends SchedulerBrowserTestBase {
public function testNonEnabledType($id, $entityTypeId, $description, $publishing_enabled, $unpublishing_enabled) {
$this
->drupalLogin($this->adminUser);
$entityType = $this
->entityTypeObject($entityTypeId, 'non-enabled');
$bundle = $entityType
->id();
$storage = $this
->entityStorageObject($entityTypeId);
$titleField = $entityTypeId == 'media' ? 'name' : 'title';
if ($description != 'Default') {
$entityType
->setThirdPartySetting('scheduler', 'publish_enable', $publishing_enabled)
->setThirdPartySetting('scheduler', 'unpublish_enable', $unpublishing_enabled)
->save();
}
$entityType
->setThirdPartySetting('scheduler', 'publish_required', !$publishing_enabled)
->save();
$entityType
->setThirdPartySetting('scheduler', 'unpublish_required', !$unpublishing_enabled)
->save();
$entityType
->setThirdPartySetting('scheduler', 'publish_past_date', 'schedule')
->save();
$this
->drupalGet($this
->entityAddUrl($entityTypeId, $bundle));
if ($publishing_enabled) {
$this
->assertSession()
->fieldExists('publish_on[0][value][date]');
}
else {
$this
->assertSession()
->fieldNotExists('publish_on[0][value][date]');
}
if ($unpublishing_enabled) {
$this
->assertSession()
->fieldExists('unpublish_on[0][value][date]');
}
else {
$this
->assertSession()
->fieldNotExists('unpublish_on[0][value][date]');
}
$title = $id . 'a - ' . $description;
$this
->submitForm([
"{$titleField}[0][value]" => $title,
], 'Save');
$this
->assertSession()
->pageTextMatches('/' . preg_quote($title, '/') . ' has been (created|successfully saved)/');
$title = $id . 'b - ' . $description;
$values = [
"{$titleField}" => $title,
'status' => FALSE,
'publish_on' => $this->requestTime - 120,
];
$entity = $this
->createEntity($entityTypeId, $bundle, $values);
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextMatches('/' . preg_quote($title, '/') . ' has been (updated|successfully saved)/');
$this
->cronRun();
$this
->drupalGet('admin/reports/dblog');
$storage
->resetCache([
$entity
->id(),
]);
$entity = $storage
->load($entity
->id());
if ($publishing_enabled) {
$this
->assertTrue($entity
->isPublished(), "The unpublished entity '{$title}' should now be published");
}
else {
$this
->assertFalse($entity
->isPublished(), "The unpublished entity '{$title}' should remain unpublished");
}
$title = $id . 'c - ' . $description;
$values = [
"{$titleField}" => $title,
'status' => TRUE,
'unpublish_on' => $this->requestTime + 180,
];
$entity = $this
->createEntity($entityTypeId, $bundle, $values);
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->submitForm([], 'Save');
$this
->assertSession()
->pageTextMatches('/' . preg_quote($title, '/') . ' has been (updated|successfully saved)/');
$title = $id . 'd - ' . $description;
$values = [
"{$titleField}" => $title,
'status' => TRUE,
'unpublish_on' => $this->requestTime - 120,
];
$entity = $this
->createEntity($entityTypeId, $bundle, $values);
$this
->cronRun();
$this
->drupalGet('admin/reports/dblog');
$storage
->resetCache([
$entity
->id(),
]);
$entity = $storage
->load($entity
->id());
if ($unpublishing_enabled) {
$this
->assertFalse($entity
->isPublished(), "The published entity '{$title}' should now be unpublished");
}
else {
$this
->assertTrue($entity
->isPublished(), "The published entity '{$title}' should remain published");
}
switch ($entityTypeId) {
case 'node':
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/content/scheduled');
break;
case 'media':
$this
->drupalGet('admin/content/media');
$this
->drupalGet('admin/content/media/scheduled');
break;
case 'commerce_product':
$this
->drupalGet('admin/commerce/products');
$this
->drupalGet('admin/commerce/products/scheduled');
break;
}
}
public function dataNonEnabledType() {
$data = [];
foreach ($this
->dataStandardEntityTypes() as $key => $values) {
$entityTypeId = $values[0];
$data["{$key}-1"] = [
1,
$entityTypeId,
'Default',
FALSE,
FALSE,
];
$data["{$key}-2"] = [
2,
$entityTypeId,
'Disabling both settings',
FALSE,
FALSE,
];
$data["{$key}-3"] = [
3,
$entityTypeId,
'Enabling publishing only',
TRUE,
FALSE,
];
$data["{$key}-4"] = [
4,
$entityTypeId,
'Enabling unpublishing only',
FALSE,
TRUE,
];
$data["{$key}-5"] = [
5,
$entityTypeId,
'Enabling both publishing and unpublishing',
TRUE,
TRUE,
];
}
return $data;
}
}