| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Unit tests for the poormanscron module. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
|
class PoormanscronUnitTest extends DrupalWebTestCase { |
| 10 |
|
public static function getInfo() { |
| 11 |
|
return array( |
| 12 |
|
'name' => 'Poormanscron functionality', |
| 13 |
|
'description' => 'Tests the poormanscron module.', |
| 14 |
|
'group' => 'Poormanscron', |
| 15 |
|
); |
| 16 |
|
} |
| 17 |
|
|
| 18 |
|
function setUp() { |
| 19 |
|
parent::setUp('poormanscron'); |
| 20 |
|
$this->admin_user = $this->drupalCreateUser(array('administer site configuration')); |
| 21 |
|
} |
| 22 |
|
|
| 23 |
|
/** |
| 24 |
|
* Ensure that the cron image callback to run it automatically is working. |
| 25 |
|
*/ |
| 26 |
|
function testCronThreshold() { |
| 27 |
|
// Ensure cron does not run when the cron threshold is enabled and was |
| 28 |
|
// not passed. |
| 29 |
|
$cron_last = time(); |
| 30 |
|
$cron_safe_threshold = 100; |
| 31 |
|
variable_set('cron_last', $cron_last); |
| 32 |
|
variable_set('cron_safe_threshold', $cron_safe_threshold); |
| 33 |
|
$this->drupalGet(''); |
| 34 |
|
$this->assertRaw('"cronCheck": ' . ($cron_last + $cron_safe_threshold)); |
| 35 |
|
$this->drupalGet('poormanscron/run-cron-check'); |
| 36 |
|
$this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is not passed.')); |
| 37 |
|
|
| 38 |
|
// Test if cron runs when the cron threshold was passed. |
| 39 |
|
$cron_last = time() - 200; |
| 40 |
|
variable_set('cron_last', $cron_last); |
| 41 |
|
$this->drupalGet(''); |
| 42 |
|
$this->assertRaw('"cronCheck": ' . ($cron_last + $cron_safe_threshold)); |
| 43 |
|
$this->drupalGet('poormanscron/run-cron-check'); |
| 44 |
|
$this->assertTrue($cron_last < variable_get('cron_last', NULL), t('Cron runs when the cron threshold is passed.')); |
| 45 |
|
|
| 46 |
|
// Disable the cron threshold through the interface. |
| 47 |
|
$this->drupalLogin($this->admin_user); |
| 48 |
|
$this->drupalPost('admin/settings/site-information', array('cron_safe_threshold' => 0), t('Save configuration')); |
| 49 |
|
$this->assertText(t('The configuration options have been saved.')); |
| 50 |
|
|
| 51 |
|
// Test if cron does not run when the cron threshold is disabled. |
| 52 |
|
$cron_last = time() - 200; |
| 53 |
|
variable_set('cron_last', $cron_last); |
| 54 |
|
$this->drupalGet(''); |
| 55 |
|
$this->assertNoRaw('cronCheck'); |
| 56 |
|
$this->drupalGet('poormanscron/run-cron-check'); |
| 57 |
|
$this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is disabled.')); |
| 58 |
|
} |
| 59 |
|
} |