reverted: --- b/src/Tests/SchedulerRulesConditionsTest.php +++ /dev/null @@ -1,255 +0,0 @@ -rulesStorage = $this->container->get('entity_type.manager')->getStorage('rules_reaction_rule'); - $this->expressionManager = $this->container->get('plugin.manager.rules_expression'); - - // Create a published page node. - $type = $this->nodetype->get('type'); - $this->node = $this->drupalCreateNode([ - 'title' => 'Rules Test Node', - 'type' => $type, - 'uid' => $this->adminUser->id(), - 'status' => TRUE, - ]); - } - - /** - * Tests the conditions for whether a nodetype is enabled for Scheduler. - */ - public function testNodeTypeEnabledConditions() { - // Create a reaction rule to display a message when viewing a node of a type - // that is enabled for scheduled publishing. - // "viewing content" actually means "viewing PUBLISHED content" - $rule1 = $this->expressionManager->createRule(); - $rule1->addCondition('scheduler_condition_publishing_is_enabled', - ContextConfig::create()->map('node', 'node') - ); - $message1 = 'RULES message 1. This node type is enabled for scheduled publishing.'; - $rule1->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message1) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule1', - 'events' => [['event_name' => 'rules_entity_view:node']], - 'expression' => $rule1->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when viewing a node of a type - // that is enabled for scheduled unpublishing. - $rule2 = $this->expressionManager->createRule(); - $rule2->addCondition('scheduler_condition_unpublishing_is_enabled', - ContextConfig::create()->map('node', 'node') - ); - $message2 = 'RULES message 2. This node type is enabled for scheduled unpublishing.'; - $rule2->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message2) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule2', - 'events' => [['event_name' => 'rules_entity_view:node']], - 'expression' => $rule2->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when viewing a node of a type - // that is NOT enabled for scheduled publishing. - $rule3 = $this->expressionManager->createRule(); - $rule3->addCondition('scheduler_condition_publishing_is_enabled', - ContextConfig::create()->map('node', 'node')->negateResult() - ); - $message3 = 'RULES message 3. This node type is not enabled for scheduled publishing.'; - $rule3->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message3) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule3', - 'events' => [['event_name' => 'rules_entity_view:node']], - 'expression' => $rule3->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when viewing a node of a type - // that is NOT enabled for scheduled unpublishing. - $rule4 = $this->expressionManager->createRule(); - $rule4->addCondition('scheduler_condition_unpublishing_is_enabled', - ContextConfig::create()->map('node', 'node')->negateResult() - ); - $message4 = 'RULES message 4. This node type is not enabled for scheduled unpublishing.'; - $rule4->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message4) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule4', - 'events' => [['event_name' => 'rules_entity_view:node']], - 'expression' => $rule4->getConfiguration(), - ]); - $config_entity->save(); - - // View the node and check the default position - that the node type is - // enabled for both publishing and unpublishing. - $this->drupalGet('node/' . $this->node->id()); - $this->assertText($message1, '"' . $message1 . '" is shown'); - $this->assertText($message2, '"' . $message2 . '" is shown'); - $this->assertNoText($message3, '"' . $message3 . '" is not shown'); - $this->assertNoText($message4, '"' . $message4 . '" is not shown'); - - // Turn off scheduled publishing for the node type and check the rules. - $this->nodetype->setThirdPartySetting('scheduler', 'publish_enable', FALSE)->save(); - $this->drupalGet('node/' . $this->node->id()); - $this->assertNoText($message1, '"' . $message1 . '" is not shown'); - $this->assertText($message2, '"' . $message2 . '" is shown'); - $this->assertText($message3, '"' . $message3 . '" is shown'); - $this->assertNoText($message4, '"' . $message4 . '" is not shown'); - - // Turn off scheduled unpublishing for the node type and the check again. - $this->nodetype->setThirdPartySetting('scheduler', 'unpublish_enable', FALSE)->save(); - $this->drupalGet('node/' . $this->node->id()); - $this->assertNoText($message1, '"' . $message1 . '" is not shown'); - $this->assertNoText($message2, '"' . $message2 . '" is not shown'); - $this->assertText($message3, '"' . $message3 . '" is shown'); - $this->assertText($message4, '"' . $message4 . '" is shown'); - - } - - /** - * Tests the conditions for whether a node is scheduled. - */ - public function testNodeIsScheduledConditions() { - // Create a reaction rule to display a message when a node is updated and - // is not scheduled for publishing. - $rule5 = $this->expressionManager->createRule(); - $rule5->addCondition('scheduler_condition_node_scheduled_for_publishing', - ContextConfig::create()->map('node', 'node')->negateResult() - ); - $message5 = 'RULES message 5. This content is not scheduled for publishing.'; - $rule5->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message5) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule5', - 'events' => [['event_name' => 'rules_entity_update:node']], - 'expression' => $rule5->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when a node is updated and - // is not scheduled for unpublishing. - $rule6 = $this->expressionManager->createRule(); - $rule6->addCondition('scheduler_condition_node_scheduled_for_unpublishing', - ContextConfig::create()->map('node', 'node')->negateResult() - ); - $message6 = 'RULES message 6. This content is not scheduled for unpublishing.'; - $rule6->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message6) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule6', - 'events' => [['event_name' => 'rules_entity_update:node']], - 'expression' => $rule6->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when a node is updated and - // is scheduled for publishing. - $rule7 = $this->expressionManager->createRule(); - $rule7->addCondition('scheduler_condition_node_scheduled_for_publishing', - ContextConfig::create()->map('node', 'node') - ); - $message7 = 'RULES message 7. This content is scheduled for publishing.'; - $rule7->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message7) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule7', - 'events' => [['event_name' => 'rules_entity_update:node']], - 'expression' => $rule7->getConfiguration(), - ]); - $config_entity->save(); - - // Create a reaction rule to display a message when a node is updated and - // is scheduled for unpublishing. - $rule8 = $this->expressionManager->createRule(); - $rule8->addCondition('scheduler_condition_node_scheduled_for_unpublishing', - ContextConfig::create()->map('node', 'node') - ); - $message8 = 'RULES message 8. This content is scheduled for unpublishing.'; - $rule8->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message8) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule8', - 'events' => [['event_name' => 'rules_entity_update:node']], - 'expression' => $rule8->getConfiguration(), - ]); - $config_entity->save(); - - $this->drupalLogin($this->adminUser); - - // Edit the node but do not enter any scheduling dates. - $edit = [ - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and keep published')); - - $this->assertText($message5, '"' . $message5 . '" is shown'); - $this->assertText($message6, '"' . $message6 . '" is shown'); - $this->assertNoText($message7, '"' . $message7 . '" is not shown'); - $this->assertNoText($message8, '"' . $message8 . '" is not shown'); - - // Edit the node and set a publish_on date. - $edit = [ - 'publish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', REQUEST_TIME)), - 'publish_on[0][value][time]' => date('H:i:s', strtotime('+1 day', REQUEST_TIME)), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and unpublish')); - - $this->assertNoText($message5, '"' . $message5 . '" is not shown'); - $this->assertText($message6, '"' . $message6 . '" is shown'); - $this->assertText($message7, '"' . $message7 . '" is shown'); - $this->assertNoText($message8, '"' . $message8 . '" is not shown'); - - // Edit the node and set an unpublish_on date. - $edit = [ - 'unpublish_on[0][value][date]' => date('Y-m-d', strtotime('+2 day', REQUEST_TIME)), - 'unpublish_on[0][value][time]' => date('H:i:s', strtotime('+2 day', REQUEST_TIME)), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and keep unpublished')); - - $this->assertNoText($message5, '"' . $message5 . '" is not shown'); - $this->assertNoText($message6, '"' . $message6 . '" is not shown'); - $this->assertText($message7, '"' . $message7 . '" is shown'); - $this->assertText($message8, '"' . $message8 . '" is shown'); - - } -} reverted: --- b/src/Tests/SchedulerRulesActionsTest.php +++ /dev/null @@ -1,281 +0,0 @@ -nodeStorage = $this->container->get('entity.manager')->getStorage('node'); - $this->rulesStorage = $this->container->get('entity_type.manager')->getStorage('rules_reaction_rule'); - $this->expressionManager = $this->container->get('plugin.manager.rules_expression'); - - // Create a published page node. - $type = $this->nodetype->get('type'); - $this->node = $this->drupalCreateNode([ - 'title' => 'Initial Test Node', - 'type' => $type, - 'uid' => $this->adminUser->id(), - 'status' => TRUE, - ]); - } - - /** - * Tests the actions which set and remove the 'Publish On' date. - */ - public function testPublishOnActions() { - - // Create rule 1 to set the publishing date. - $rule1 = $this->expressionManager->createRule(); - $rule1->addCondition('scheduler_condition_publishing_is_enabled', - ContextConfig::create() - ->map('node', 'node') - ) - ->addCondition('rules_data_comparison', - ContextConfig::create() - ->map('data', 'node.title.value') - ->setValue('operation', '==') - ->setValue('value', 'Trigger Action Rule 1') - ); - $message1 = 'RULES message 1. Action to set Publish-on date.'; - $rule1->addAction('scheduler_set_publishing_date_action', - ContextConfig::create() - ->map('node', 'node') - ->setValue('date', REQUEST_TIME + 1800) - ) - ->addAction('rules_system_message', - ContextConfig::create() - ->setValue('message', $message1) - ->setValue('type', 'status') - ); - // The event needs to be rules_entity_presave:node 'before saving' because - // rules_entity_update:node 'after save' is too late to set the date. - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule1', - 'events' => [['event_name' => 'rules_entity_presave:node']], - 'expression' => $rule1->getConfiguration(), - ]); - $config_entity->save(); - - // Create rule 2 to remove the publishing date and publish the node. - $rule2 = $this->expressionManager->createRule(); - $rule2->addCondition('scheduler_condition_publishing_is_enabled', - ContextConfig::create() - ->map('node', 'node') - ) - ->addCondition('rules_data_comparison', - ContextConfig::create() - ->map('data', 'node.title.value') - ->setValue('operation', '==') - ->setValue('value', 'Trigger Action Rule 2') - ); - $message2 = 'RULES message 2. Action to remove Publish-on date and publish the node immediately.'; - $rule2->addAction('scheduler_remove_publishing_date_action', - ContextConfig::create() - ->map('node', 'node') - ) - ->addAction('scheduler_publish_now_action', - ContextConfig::create() - ->map('node', 'node') - ) - ->addAction('rules_system_message', - ContextConfig::create() - ->setValue('message', $message2) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule2', - 'events' => [['event_name' => 'rules_entity_presave:node']], - 'expression' => $rule2->getConfiguration(), - ]); - $config_entity->save(); - - $this->drupalLogin($this->adminUser); - $node = $this->node; - - // Edit node without changing title. - $edit = [ - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $this->nodeStorage->resetCache([$node->id()]); - $node = $this->nodeStorage->load($node->id()); - // Check that neither of the rules are triggered, no publish and unpublish - // dates are set and the status is still published. - $this->assertNoText($message1, '"' . $message1 . '" is not shown'); - $this->assertNoText($message2, '"' . $message2 . '" is not shown'); - $this->assertFalse($node->publish_on->value, 'Node is not scheduled for publishing.'); - $this->assertFalse($node->unpublish_on->value, 'Node is not scheduled for unpublishing.'); - $this->assertTrue($node->isPublished(), 'Node remains published for title: "' . $node->title->value . '".'); - - // Edit the node, triggering rule 1. - $edit = [ - 'title[0][value]' => 'Trigger Action Rule 1', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and keep published')); - $this->nodeStorage->resetCache([$this->node->id()]); - $node = $this->nodeStorage->load($this->node->id()); - // Check that rule 1 is triggered and rule 2 is not. Check that a publishing - // date has been set and status is now unpublished. - $this->assertText($message1, '"' . $message1 . '" is shown'); - $this->assertNoText($message2, '"' . $message2 . '" is not shown'); - $this->assertTrue($node->publish_on->value, 'Node is scheduled for publishing.'); - $this->assertFalse($node->unpublish_on->value, 'Node is not scheduled for unpublishing.'); - $this->assertFalse($node->isPublished(), 'Node is now unpublished for title: "' . $node->title->value . '".'); - - // Edit the node, triggering rule 2. - $edit = [ - 'title[0][value]' => 'Trigger Action Rule 2', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and publish')); - $this->nodeStorage->resetCache([$this->node->id()]); - $node = $this->nodeStorage->load($this->node->id()); - // Check that rule 2 is triggered and rule 1 is not. Check that the - // publishing date has been removed and the status is published. - $this->assertNoText($message1, '"' . $message1 . '" is not shown'); - $this->assertText($message2, '"' . $message2 . '" is shown'); - $this->assertFalse($node->publish_on->value, 'Node is not scheduled for publishing.'); - $this->assertFalse($node->unpublish_on->value, 'Node is not scheduled for unpublishing.'); - $this->assertTrue($node->isPublished(), 'Node is now published for title: "' . $node->title->value . '".'); - - } - - /** - * Tests the actions which set and remove the 'Unpublish On' date. - */ - public function testUnpublishOnActions() { - - // Create rule 3 to set the unpublishing date. - $rule3 = $this->expressionManager->createRule(); - $rule3->addCondition('scheduler_condition_unpublishing_is_enabled', - ContextConfig::create() - ->map('node', 'node') - ) - ->addCondition('rules_data_comparison', - ContextConfig::create() - ->map('data', 'node.title.value') - ->setValue('operation', '==') - ->setValue('value', 'Trigger Action Rule 3') - ); - $message3 = 'RULES message 3. Action to set Unpublish-on date.'; - $rule3->addAction('scheduler_set_unpublishing_date_action', - ContextConfig::create() - ->map('node', 'node') - ->setValue('date', REQUEST_TIME + 1800) - ) - ->addAction('rules_system_message', - ContextConfig::create() - ->setValue('message', $message3) - ->setValue('type', 'status') - ); - // The event needs to be rules_entity_presave:node 'before saving' because - // rules_entity_update:node 'after save' is too late to set the date. - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule3', - 'events' => [['event_name' => 'rules_entity_presave:node']], - 'expression' => $rule3->getConfiguration(), - ]); - $config_entity->save(); - - // Create rule 4 to remove the unpublishing date and unpublish the node. - $rule4 = $this->expressionManager->createRule(); - $rule4->addCondition('scheduler_condition_unpublishing_is_enabled', - ContextConfig::create() - ->map('node', 'node') - ) - ->addCondition('rules_data_comparison', - ContextConfig::create() - ->map('data', 'node.title.value') - ->setValue('operation', '==') - ->setValue('value', 'Trigger Action Rule 4') - ); - $message4 = 'RULES message 4. Action to remove Unpublish-on date and unpublish the node immediately.'; - $rule4->addAction('scheduler_remove_unpublishing_date_action', - ContextConfig::create() - ->map('node', 'node') - ) - ->addAction('scheduler_unpublish_now_action', - ContextConfig::create() - ->map('node', 'node') - ) - ->addAction('rules_system_message', - ContextConfig::create() - ->setValue('message', $message4) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule4', - 'events' => [['event_name' => 'rules_entity_presave:node']], - 'expression' => $rule4->getConfiguration(), - ]); - $config_entity->save(); - - $this->drupalLogin($this->adminUser); - $node = $this->node; - - // Edit node without changing title. - $edit = [ - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $this->nodeStorage->resetCache([$node->id()]); - $node = $this->nodeStorage->load($node->id()); - // Check that neither of the rules are triggered, no publish and unpublish - // dates are set and the status is still published. - $this->assertNoText($message3, '"' . $message3 . '" is not shown'); - $this->assertNoText($message4, '"' . $message4 . '" is not shown'); - $this->assertFalse($node->publish_on->value, 'Node is not scheduled for publishing.'); - $this->assertFalse($node->unpublish_on->value, 'Node is not scheduled for unpublishing.'); - $this->assertTrue($node->isPublished(), 'Node remains published for title: "' . $node->title->value . '".'); - - // Edit the node, triggering rule 3. - $edit = [ - 'title[0][value]' => 'Trigger Action Rule 3', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and keep published')); - $this->nodeStorage->resetCache([$this->node->id()]); - $node = $this->nodeStorage->load($this->node->id()); - // Check that rule 3 is triggered and rule 4 is not. Check that an - // unpublishing date has been set and status is still published. - $this->assertText($message3, '"' . $message3 . '" is shown'); - $this->assertNoText($message4, '"' . $message4 . '" is not shown'); - $this->assertFalse($node->publish_on->value, 'Node is not scheduled for publishing.'); - $this->assertTrue($node->unpublish_on->value, 'Node is scheduled for unpublishing.'); - $this->assertTrue($node->isPublished(), 'Node is still published for title: "' . $node->title->value . '".'); - - // Edit the node, triggering rule 4. - $edit = [ - 'title[0][value]' => 'Trigger Action Rule 4', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $this->node->id() . '/edit', $edit, t('Save and keep published')); - $this->nodeStorage->resetCache([$this->node->id()]); - $node = $this->nodeStorage->load($this->node->id()); - // Check that rule 4 is triggered and rule 3 is not. Check that the - // unpublishing date has been removed and the status is unpublished. - $this->assertNoText($message3, '"' . $message3 . '" is not shown'); - $this->assertText($message4, '"' . $message4 . '" is shown'); - $this->assertFalse($node->publish_on->value, 'Node is not scheduled for publishing.'); - $this->assertFalse($node->unpublish_on->value, 'Node is not scheduled for unpublishing.'); - $this->assertFalse($node->isPublished(), 'Node is now unpublished for title: "' . $node->title->value . '".'); - } -} reverted: --- b/src/Tests/SchedulerRulesEventsTest.php +++ /dev/null @@ -1,228 +0,0 @@ -rulesStorage = $this->container->get('entity_type.manager')->getStorage('rules_reaction_rule'); - $this->nodeStorage = $this->container->get('entity.manager')->getStorage('node'); - $this->expressionManager = $this->container->get('plugin.manager.rules_expression'); - - } - - /** - * Tests the six events provided by Scheduler. - * - * This class tests all six events provided by Scheduler, by creating six - * rules which are all active throughout the test. They are all checked in - * this one test class to make the tests stronger, as this will show not only - * that the correct events are triggered in the right places, but also - * that they are not triggered in the wrong places. - */ - public function testRulesEvents() { - - // Create six reaction rules, one for each event that Scheduler triggers. - $rule_data = array( - 1 => ['scheduler_new_node_is_scheduled_for_publishing_event', 'A new node is created and is scheduled for publishing.'], - 2 => ['scheduler_existing_node_is_scheduled_for_publishing_event', 'An existing node is saved and is scheduled for publishing.'], - 3 => ['scheduler_has_published_this_node_event', 'Scheduler has published this node during cron.'], - 4 => ['scheduler_new_node_is_scheduled_for_unpublishing_event', 'A new node is created and is scheduled for unpublishing.'], - 5 => ['scheduler_existing_node_is_scheduled_for_unpublishing_event', 'An existing node is saved and is scheduled for unpublishing.'], - 6 => ['scheduler_has_unpublished_this_node_event', 'Scheduler has unpublished this node during cron.'], - ); - foreach ($rule_data as $i => $data) { - list($event_name, $description) = $data; - $rule[$i] = $this->expressionManager->createRule(); - $message[$i] = 'RULES message ' . $i . '. ' . $description; - $rule[$i]->addAction('rules_system_message', ContextConfig::create() - ->setValue('message', $message[$i]) - ->setValue('type', 'status') - ); - $config_entity = $this->rulesStorage->create([ - 'id' => 'rule' . $i, - 'events' => [['event_name' => $event_name]], - 'expression' => $rule[$i]->getConfiguration(), - ]); - $config_entity->save(); - } - - $this->drupalLogin($this->adminUser); - // Get the internal name of the content type. - $type = $this->nodetype->get('type'); - - // Create a node without any scheduled dates, using node/add/ not - // drupalCreateNode(), and check that no events are triggered. - $edit = [ - 'title[0][value]' => 'Test for no events', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish')); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Edit the node and check that no events are triggered. - $edit = [ - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Create a new node with a publish-on date, and check that only event 1 is - // triggered. - $edit = [ - 'title[0][value]' => 'Create node with publish-on date', - 'publish_on[0][value][date]' => date('Y-m-d', time() + 3), - 'publish_on[0][value][time]' => date('H:i:s', time() + 3), - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish')); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertText($message[1], '"' . $message[1] . '" IS shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Edit this node and check that only event 2 is triggered. - $edit = [ - 'title[0][value]' => 'Edit node with publish-on date', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep unpublished')); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertText($message[2], '"' . $message[2] . '" IS shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Delay to ensure that the date entered is now in the past so that the node - // will be processed during cron, and assert that event 3 is triggered. - sleep(5); - $this->cronRun(); - $this->drupalGet('admin/reports/dblog'); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertText($message[3], '"' . $message[3] . '" IS shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Create a new node with an unpublish-on date, and check that only event 4 - // is triggered. - $edit = [ - 'title[0][value]' => 'Create node with unpublish-on date', - 'unpublish_on[0][value][date]' => date('Y-m-d', time() + 3), - 'unpublish_on[0][value][time]' => date('H:i:s', time() + 3), - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish')); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertText($message[4], '"' . $message[4] . '" IS shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Edit this node and check that only event 5 is triggered. - $edit = [ - 'title[0][value]' => 'Edit node with unpublish-on date', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertText($message[5], '"' . $message[5] . '" IS shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Delay to ensure that the date entered is now in the past so that the node - // will be processed during cron, and assert that event 6 is triggered. - sleep(5); - $this->cronRun(); - $this->drupalGet('admin/reports/dblog'); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertText($message[6], '"' . $message[6] . '" IS shown'); - - // Create a new node with both publish-on and unpublish-on dates, and check - // that events 1 and event 4 are both triggered. - $edit = [ - 'title[0][value]' => 'Create node with both dates', - 'publish_on[0][value][date]' => date('Y-m-d', time() + 3), - 'publish_on[0][value][time]' => date('H:i:s', time() + 3), - 'unpublish_on[0][value][date]' => date('Y-m-d', time() + 4), - 'unpublish_on[0][value][time]' => date('H:i:s', time() + 4), - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish')); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertText($message[1], '"' . $message[1] . '" IS shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertText($message[4], '"' . $message[4] . '" IS shown'); - $this->assertNoText($message[5], '"' . $message[5] . '" is not shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Edit this node and check that events 2 and 5 are triggered. - $edit = [ - 'title[0][value]' => 'Edit node with both dates', - 'body[0][value]' => $this->randomString(30), - ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep unpublished')); - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertText($message[2], '"' . $message[2] . '" IS shown'); - $this->assertNoText($message[3], '"' . $message[3] . '" is not shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertText($message[5], '"' . $message[5] . '" IS shown'); - $this->assertNoText($message[6], '"' . $message[6] . '" is not shown'); - - // Delay to ensure that the dates are now in the past so that the node will - // be processed during cron, and assert that events 3, 5 and 6 are triggered. - sleep(6); - $this->cronRun(); - $this->drupalGet('admin/reports/dblog'); - $this->assertNoText($message[1], '"' . $message[1] . '" is not shown'); - $this->assertNoText($message[2], '"' . $message[2] . '" is not shown'); - $this->assertText($message[3], '"' . $message[3] . '" IS shown'); - $this->assertNoText($message[4], '"' . $message[4] . '" is not shown'); - $this->assertText($message[5], '"' . $message[5] . '" IS shown'); - $this->assertText($message[6], '"' . $message[6] . '" IS shown'); - - } -}