cron_example.test

  1. examples
    1. 7 cron_example/cron_example.test
    2. 8 cron_example/cron_example.test

Test case for testing the cron example module.

Classes

NameDescription
CronExampleTestCasecron_example test class

File

cron_example/cron_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test case for testing the cron example module.
  5. */
  6. /**
  7. * @addtogroup cron_example
  8. * @{
  9. */
  10. /**
  11. * cron_example test class
  12. */
  13. class CronExampleTestCase extends DrupalWebTestCase {
  14. protected $web_user;
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'Cron example functionality',
  18. 'description' => 'Test the functionality of the Cron Example.',
  19. 'group' => 'Examples',
  20. );
  21. }
  22. /**
  23. * Enable modules and create user with specific permissions.
  24. */
  25. function setUp() {
  26. parent::setUp('cron_example');
  27. // Create user. Search content permission granted for the search block to
  28. // be shown.
  29. $this->web_user = $this->drupalCreateUser(array('administer site configuration'));
  30. $this->drupalLogin($this->web_user);
  31. }
  32. /**
  33. * Login user, create an example node, and test block functionality through
  34. * the admin and user interfaces.
  35. */
  36. 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. */
Login or register to post comments