'Poormanscron functionality', 'description' => 'Tests the poormanscron module.', 'group' => 'Poormanscron', ); } function setUp() { parent::setUp('poormanscron'); $this->admin_user = $this->drupalCreateUser(array('administer site configuration')); } /** * Ensure that the cron image callback to run it automatically is working. * * In these tests we do not use REQUEST_TIME to track start time, because we * need the exact time when cron is triggered. */ function testCronThreshold() { // Ensure cron does not run when the cron threshold is enabled and was // not passed. $cron_last = time(); $cron_safe_threshold = 100; variable_set('cron_last', $cron_last); variable_set('cron_safe_threshold', $cron_safe_threshold); $this->drupalGet(''); $this->assertRaw('"runNext":' . ($cron_last + $cron_safe_threshold)); $this->drupalGet('poormanscron/run-cron-check'); $this->assertExpiresHeader($cron_last + $cron_safe_threshold); $this->assertTrue($cron_last == variable_get('cron_last', 0), t('Cron does not run when the cron threshold is not passed.')); // Test if cron runs when the cron threshold was passed. $cron_last = time() - 200; variable_set('cron_last', $cron_last); $this->drupalGet(''); $this->assertRaw('"runNext":' . ($cron_last + $cron_safe_threshold)); $this->drupalGet('poormanscron/run-cron-check'); $this->assertExpiresHeader(variable_get('cron_last', 0) + $cron_safe_threshold); $this->assertTrue($cron_last < variable_get('cron_last', 0), t('Cron runs when the cron threshold is passed.')); // Disable the cron threshold through the interface. $this->drupalLogin($this->admin_user); $this->drupalPost('admin/config/system/site-information', array('cron_safe_threshold' => 0), t('Save configuration')); $this->assertText(t('The configuration options have been saved.')); $this->drupalLogout(); // Test if cron does not run when the cron threshold is disabled. $cron_last = time() - 200; variable_set('cron_last', $cron_last); $this->drupalGet(''); $this->assertNoRaw('runNext'); $this->drupalGet('poormanscron/run-cron-check'); $this->assertResponse(403); $this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is disabled.')); } /** * Assert that the Expires header is a specific timestamp. * * @param $timestamp * The timestamp value to match against the header. */ private function assertExpiresHeader($timestamp) { $expires = $this->drupalGetHeader('Expires'); $expires = strtotime($expires); $this->assertEqual($expires, $timestamp, t('Expires header expected @expected got @actual.', array('@expected' => $timestamp, '@actual' => $expires))); } }