1 cron_example.test public CronExampleTestCase::testCronExampleBasic()

Test running cron through the user interface.

File

modules/examples/cron_example/tests/cron_example.test, line 29
Test case for testing the cron example module.

Class

CronExampleTestCase
cron_example test class

Code

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 /');
}