cron_example.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Test case for testing the cron example module.
  5. */
  6. /**
  7. * cron_example test class
  8. *
  9. * @ingroup cron_example
  10. */
  11. class CronExampleTestCase extends DrupalWebTestCase {
  12. protected $webUser;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static function getInfo() {
  17. return array(
  18. 'name' => 'Cron example functionality',
  19. 'description' => 'Test the functionality of the Cron Example.',
  20. 'group' => 'Examples',
  21. );
  22. }
  23. /**
  24. * Enable modules and create user with specific permissions.
  25. */
  26. public function setUp() {
  27. parent::setUp('cron_example');
  28. // Create user. Search content permission granted for the search block to
  29. // be shown.
  30. $this->webUser = $this->drupalCreateUser(array('administer site configuration'));
  31. $this->drupalLogin($this->webUser);
  32. }
  33. /**
  34. * Test running cron through the user interface.
  35. */
  36. public function testCronExampleBasic() {
  37. // Pretend that cron has never been run (even though simpletest seems to
  38. // run it once...)
  39. variable_set('cron_example_next_execution', 0);
  40. $this->drupalGet('examples/cron_example');
  41. // Initial run should cause cron_example_cron() to fire.
  42. $post = array();
  43. $this->drupalPost('examples/cron_example', $post, t('Run cron now'));
  44. $this->assertText(t('cron_example executed at'));
  45. // Forcing should also cause cron_example_cron() to fire.
  46. $post['cron_reset'] = TRUE;
  47. $this->drupalPost(NULL, $post, t('Run cron now'));
  48. $this->assertText(t('cron_example executed at'));
  49. // But if followed immediately and not forced, it should not fire.
  50. $post['cron_reset'] = FALSE;
  51. $this->drupalPost(NULL, $post, t('Run cron now'));
  52. $this->assertNoText(t('cron_example executed at'));
  53. $this->assertText(t('There are currently 0 items in queue 1 and 0 items in queue 2'));
  54. $post = array(
  55. 'num_items' => 5,
  56. 'queue' => 'cron_example_queue_1',
  57. );
  58. $this->drupalPost(NULL, $post, t('Add jobs to queue'));
  59. $this->assertText('There are currently 5 items in queue 1 and 0 items in queue 2');
  60. $post = array(
  61. 'num_items' => 100,
  62. 'queue' => 'cron_example_queue_2',
  63. );
  64. $this->drupalPost(NULL, $post, t('Add jobs to queue'));
  65. $this->assertText('There are currently 5 items in queue 1 and 100 items in queue 2');
  66. $post = array();
  67. $this->drupalPost('examples/cron_example', $post, t('Run cron now'));
  68. $this->assertPattern('/Queue 1 worker processed item with sequence 5 /');
  69. $this->assertPattern('/Queue 2 worker processed item with sequence 100 /');
  70. }
  71. }
  72. /**
  73. * @} End of "addtogroup cron_example".
  74. */