Test case for testing the cron example module.
<?php /** * @file * Test case for testing the cron example module. */ /** * cron_example test class * * @ingroup cron_example */ class CronExampleTestCase extends BackdropWebTestCase { protected $webUser; /** * Enable modules and create user with specific permissions. */ public function setUp() { parent::setUp('cron_example'); // Create user. Search content permission granted for the search block to // be shown. $this->webUser = $this->backdropCreateUser(array('administer site configuration')); $this->backdropLogin($this->webUser); } /** * Test running cron through the user interface. */ public function testCronExampleBasic() { // Pretend that cron has never been run (even though simpletest seems to // run it once...) state_set('cron_example_next_execution', 0); $this->backdropGet('examples/cron_example'); // Initial run should cause cron_example_cron() to fire. $post = array(); $this->backdropPost('examples/cron_example', $post, t('Run cron now')); $this->assertText(t('cron_example executed at')); // Forcing should also cause cron_example_cron() to fire. $post['cron_reset'] = TRUE; $this->backdropPost(NULL, $post, t('Run cron now')); $this->assertText(t('cron_example executed at')); // But if followed immediately and not forced, it should not fire. $post['cron_reset'] = FALSE; $this->backdropPost(NULL, $post, t('Run cron now')); $this->assertNoText(t('cron_example executed at')); $this->assertText(t('There are currently 0 items in queue 1 and 0 items in queue 2')); $post = array( 'num_items' => 5, 'queue' => 'cron_example_queue_1', ); $this->backdropPost(NULL, $post, t('Add jobs to queue')); $this->assertText('There are currently 5 items in queue 1 and 0 items in queue 2'); $post = array( 'num_items' => 100, 'queue' => 'cron_example_queue_2', ); $this->backdropPost(NULL, $post, t('Add jobs to queue')); $this->assertText('There are currently 5 items in queue 1 and 100 items in queue 2'); $post = array(); $this->backdropPost('examples/cron_example', $post, t('Run cron now')); $this->assertPattern('/Queue 1 worker processed item with sequence 5 /'); $this->assertPattern('/Queue 2 worker processed item with sequence 100 /'); } } /** * @} End of "addtogroup cron_example". */