View source
<?php
namespace Drupal\Tests\scheduler\Functional;
class SchedulerRequiredTest extends SchedulerBrowserTestBase {
public function testRequiredScheduling($id, $publish_required, $unpublish_required, $operation, $scheduled, $status, $publish_expected, $unpublish_expected, $message) {
$this
->drupalLogin($this->schedulerUser);
$fields = $this->container
->get('entity_field.manager')
->getFieldDefinitions('node', $this->type);
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', $publish_required)
->setThirdPartySetting('scheduler', 'unpublish_required', $unpublish_required)
->save();
$title_data = [
'id = ' . $id,
$publish_required ? 'Publishing required' : '',
$unpublish_required ? 'Unpublishing required' : '',
'on ' . $operation,
$status ? 'published' : 'unpublished',
$scheduled ? 'scheduled' : 'not scheduled',
];
$title_data = array_filter($title_data);
$title = implode(', ', $title_data);
if ($operation == 'edit') {
$options = [
'title' => $title,
'type' => $this->type,
'status' => $status,
'publish_on' => $scheduled ? strtotime('+1 day') : NULL,
'body' => $message,
];
$node = $this
->drupalCreateNode($options);
$path = 'node/' . $node
->id() . '/edit';
}
else {
$fields['status']
->getConfig($this->type)
->setDefaultValue($status)
->save();
$path = 'node/add/' . $this->type;
}
$values = [
'title[0][value]' => $title,
'publish_on[0][value][date]' => '',
'publish_on[0][value][time]' => '',
'unpublish_on[0][value][date]' => '',
'unpublish_on[0][value][time]' => '',
];
$this
->drupalGet($path);
$this
->submitForm($values, 'Save');
if ($publish_expected) {
$string = sprintf('The %s date is required.', ucfirst('publish') . ' on');
$this
->assertSession()
->pageTextContains($string);
}
if ($unpublish_expected) {
$string = sprintf('The %s date is required.', ucfirst('unpublish') . ' on');
$this
->assertSession()
->pageTextContains($string);
}
if (!$publish_expected && !$unpublish_expected) {
$string = sprintf('%s %s has been %s.', $this->typeName, $title, $operation == 'add' ? 'created' : 'updated');
$this
->assertSession()
->pageTextContains($string);
}
}
public function dataRequiredScheduling() {
$data = [
[
'id' => 0,
'publish_required' => FALSE,
'unpublish_required' => FALSE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => FALSE,
'unpublish_expected' => FALSE,
'message' => 'By default when a new node is created, the publish on and unpublish on dates are not required.',
],
[
'id' => 1,
'publish_required' => TRUE,
'unpublish_required' => FALSE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => TRUE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled publishing is required and a new unpublished node is created, entering a date in the publish on field is required.',
],
[
'id' => 2,
'publish_required' => TRUE,
'unpublish_required' => FALSE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => TRUE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled publishing is required and a new published node is created, entering a date in the publish on field is required.',
],
[
'id' => 3,
'publish_required' => TRUE,
'unpublish_required' => FALSE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => FALSE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled publishing is required and an existing published, unscheduled node is edited, entering a date in the publish on field is not required.',
],
[
'id' => 4,
'publish_required' => TRUE,
'unpublish_required' => FALSE,
'operation' => 'edit',
'scheduled' => TRUE,
'status' => FALSE,
'publish_expected' => TRUE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled publishing is required and an existing unpublished, scheduled node is edited, entering a date in the publish on field is required.',
],
[
'id' => 5,
'publish_required' => TRUE,
'unpublish_required' => FALSE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => FALSE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled publishing is required and an existing unpublished, unscheduled node is edited, entering a date in the publish on field is not required.',
],
[
'id' => 6,
'publish_required' => FALSE,
'unpublish_required' => TRUE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => FALSE,
'unpublish_expected' => TRUE,
'message' => 'When scheduled unpublishing is required and a new unpublished node is created, entering a date in the unpublish on field is required.',
],
[
'id' => 7,
'publish_required' => FALSE,
'unpublish_required' => TRUE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => FALSE,
'unpublish_expected' => TRUE,
'message' => 'When scheduled unpublishing is required and a new published node is created, entering a date in the unpublish on field is required.',
],
[
'id' => 8,
'publish_required' => FALSE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => FALSE,
'unpublish_expected' => TRUE,
'message' => 'When scheduled unpublishing is required and an existing published, unscheduled node is edited, entering a date in the unpublish on field is required.',
],
[
'id' => 9,
'publish_required' => FALSE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => TRUE,
'status' => FALSE,
'publish_expected' => FALSE,
'unpublish_expected' => TRUE,
'message' => 'When scheduled unpublishing is required and an existing unpublished, scheduled node is edited, entering a date in the unpublish on field is required.',
],
[
'id' => 10,
'publish_required' => FALSE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => FALSE,
'unpublish_expected' => FALSE,
'message' => 'When scheduled unpublishing is required and an existing unpublished, unscheduled node is edited, entering a date in the unpublish on field is not required.',
],
[
'id' => 11,
'publish_required' => TRUE,
'unpublish_required' => TRUE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => TRUE,
'unpublish_expected' => TRUE,
'message' => 'When both scheduled publishing and unpublishing are required and a new unpublished node is created, entering a date in both the publish and unpublish on fields is required.',
],
[
'id' => 12,
'publish_required' => TRUE,
'unpublish_required' => TRUE,
'operation' => 'add',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => TRUE,
'unpublish_expected' => TRUE,
'message' => 'When both scheduled publishing and unpublishing are required and a new published node is created, entering a date in both the publish and unpublish on fields is required.',
],
[
'id' => 13,
'publish_required' => TRUE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => TRUE,
'publish_expected' => FALSE,
'unpublish_expected' => TRUE,
'message' => 'When both scheduled publishing and unpublishing are required and an existing published, unscheduled node is edited, entering a date in the unpublish on field is required, but a publish date is not required.',
],
[
'id' => 14,
'publish_required' => TRUE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => TRUE,
'status' => FALSE,
'publish_expected' => TRUE,
'unpublish_expected' => TRUE,
'message' => 'When both scheduled publishing and unpublishing are required and an existing unpublished, scheduled node is edited, entering a date in both the publish and unpublish on fields is required.',
],
[
'id' => 15,
'publish_required' => TRUE,
'unpublish_required' => TRUE,
'operation' => 'edit',
'scheduled' => FALSE,
'status' => FALSE,
'publish_expected' => FALSE,
'unpublish_expected' => FALSE,
'message' => 'When both scheduled publishing and unpublishing are required and an existing unpublished, unscheduled node is edited, entering a date in the publish or unpublish on fields is not required.',
],
];
return $data;
}
}