diff --git a/scheduler.test b/scheduler.test index 0a24683..9ac6877 100644 --- a/scheduler.test +++ b/scheduler.test @@ -20,6 +20,9 @@ class SchedulerTestCase extends DrupalWebTestCase { */ protected $admin_user; + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Scheduler functionality', @@ -28,6 +31,9 @@ class SchedulerTestCase extends DrupalWebTestCase { ); } + /** + * {@inheritdoc} + */ function setUp() { parent::setUp('scheduler'); @@ -42,8 +48,11 @@ class SchedulerTestCase extends DrupalWebTestCase { variable_set('scheduler_unpublish_enable_page', 1); } + /** + * Basic test for Scheduler functionality. + */ function testScheduler() { - // Create node to edit. + // Create node values. Set time to one hour in the future. $edit = array( 'title' => 'title', 'publish_on' => format_date(time() + 3600, 'custom', 'Y-m-d H:i:s'), @@ -56,12 +65,18 @@ class SchedulerTestCase extends DrupalWebTestCase { $this->helpTestScheduler($edit); } + /** + * Basic test helper function for creating nodes and running cron. + */ function helpTestScheduler($edit) { + // Add a page. $langcode = LANGUAGE_NONE; $body = $this->randomName(); $edit["body[$langcode][0][value]"] = $body; $this->drupalLogin($this->admin_user); $this->drupalPost('node/add/page', $edit, t('Save')); + // Show the site front page for an anonymous visitor, then assert that the + // node is correctly published or unpublished. $this->drupalLogout(); $this->drupalGet('node'); if (isset($edit['publish_on'])) { @@ -72,10 +87,15 @@ class SchedulerTestCase extends DrupalWebTestCase { $key = 'unpublish_on'; $this->assertText($body, t('Node is published')); } + // Verify that the scheduler table is not empty. + $this->assertTrue(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is not empty'); + // Modify the scheduler row to a time in the past, then run cron. db_update('scheduler')->fields(array($key => time() - 1))->execute(); - $this->assertTrue(db_query('SELECT COUNT(*) FROM {scheduler}')->fetchField(), 'Scheduler table is not empty'); $this->cronRun(); - $this->assertFalse(db_query('SELECT COUNT(*) FROM {scheduler}')->fetchField(), 'Scheduler table is empty'); + // Verify that the scheduler table is empty. + $this->assertFalse(db_query_range('SELECT 1 FROM {scheduler}', 0, 1)->fetchField(), 'Scheduler table is empty'); + // Show the site front page for an anonymous visitor, then assert that the + // node is correctly published or unpublished. $this->drupalGet('node'); if (isset($edit['publish_on'])) { $this->assertText($body, t('Node is published'));