public function SchedulerDevelGenerateTest::testDevelGenerate in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerDevelGenerateTest.php \Drupal\Tests\scheduler\Functional\SchedulerDevelGenerateTest::testDevelGenerate()
Test the functionality that Scheduler adds during content generation.
File
- tests/
src/ Functional/ SchedulerDevelGenerateTest.php, line 101
Class
- SchedulerDevelGenerateTest
- Tests the Scheduler interaction with Devel Generate module.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testDevelGenerate() {
$this
->drupalLogin($this->develUser);
// Use the minimum required settings to see what happens when everything
// else is left as default.
$generate_settings = [
"edit-node-types-{$this->type}" => TRUE,
];
$this
->drupalPostForm('admin/config/development/generate/content', $generate_settings, 'Generate');
// Display the full content list and the scheduled list. Calls to these
// pages are for information and debug only. They could be removed.
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/content/scheduled');
// Delete all content for this type and generate new content with only
// publish-on dates. Use 100% as this is how we can count the expected
// number of scheduled nodes. The time range of 3600 is one hour.
// The number of nodes has to be lower than 50 until Devel issue with
// undefined index 'users' is available and we switch to using 8.x-3.0
// See https://www.drupal.org/project/devel/issues/3076613
$generate_settings = [
"edit-node-types-{$this->type}" => TRUE,
'num' => 40,
'kill' => TRUE,
'time_range' => 3600,
'scheduler_publishing' => 100,
'scheduler_unpublishing' => 0,
];
$this
->drupalPostForm('admin/config/development/generate/content', $generate_settings, 'Generate');
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/content/scheduled');
// Check we have the expected number of nodes scheduled for publishing only
// and verify that that the dates are within the time range specified.
$this
->countScheduledNodes($this->type, 'publish_on', 40, 40, $generate_settings['time_range']);
$this
->countScheduledNodes($this->type, 'unpublish_on', 40, 0);
// Do similar for unpublish_on date. Delete all then generate new content
// with only unpublish-on dates. Time range 86400 is one day.
$generate_settings = [
"edit-node-types-{$this->type}" => TRUE,
'num' => 30,
'kill' => TRUE,
'time_range' => 86400,
'scheduler_publishing' => 0,
'scheduler_unpublishing' => 100,
];
$this
->drupalPostForm('admin/config/development/generate/content', $generate_settings, 'Generate');
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/content/scheduled');
// Check we have the expected number of nodes scheduled for unpublishing
// only, and verify that that the dates are within the time range specified.
$this
->countScheduledNodes($this->type, 'publish_on', 30, 0);
$this
->countScheduledNodes($this->type, 'unpublish_on', 30, 30, $generate_settings['time_range']);
// Generate new content using the type which is not enabled for Scheduler.
// The nodes should be created but no dates should be added even though the
// scheduler values are set to 100.
$non_scheduler_id = $this->nonSchedulerNodeType
->id();
$generate_settings = [
"edit-node-types-{$non_scheduler_id}" => TRUE,
'num' => 20,
'kill' => TRUE,
'scheduler_publishing' => 100,
'scheduler_unpublishing' => 100,
];
$this
->drupalPostForm('admin/config/development/generate/content', $generate_settings, 'Generate');
$this
->drupalGet('admin/content');
$this
->drupalGet('admin/content/scheduled');
// Check we have the expected number of nodes but that none are scheduled.
$this
->countScheduledNodes($non_scheduler_id, 'publish_on', 20, 0);
$this
->countScheduledNodes($non_scheduler_id, 'unpublish_on', 20, 0);
}