queue_example.test

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

Test the queue example module.

Classes

NameDescription
QueueExampleTestCase@file Test the queue example module.

File

queue_example/queue_example.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Test the queue example module.
  5. */
  6. class QueueExampleTestCase extends DrupalWebTestCase {
  7. public static function getInfo() {
  8. return array(
  9. 'name' => 'Queue Example functionality',
  10. 'description' => 'Test Queue Example functionality',
  11. 'group' => 'Examples',
  12. );
  13. }
  14. /**
  15. * Enable modules and create user with specific permissions.
  16. */
  17. function setUp() {
  18. parent::setUp('queue_example');
  19. }
  20. /**
  21. * Login user, create an example node, and test blog functionality through the admin and user interfaces.
  22. */
  23. function testQueueExampleBasic() {
  24. // Load the queue with 5 items.
  25. for ($i = 1; $i <= 5; $i++) {
  26. $edit = array('queue_name' => 'queue_example_first_queue', 'string_to_add' => "boogie$i");
  27. $this->drupalPost('queue_example/insert_remove', $edit, t('Insert into queue'));
  28. $this->assertText(t('There are now @number items in the queue', array('@number' => $i)));
  29. }
  30. // Claim each of the 5 items with a claim time of 0 seconds.
  31. for ($i = 1; $i <= 5; $i++) {
  32. $edit = array('queue_name' => 'queue_example_first_queue', 'claim_time' => 0);
  33. $this->drupalPost(NULL, $edit, t('Claim the next item from the queue'));
  34. $this->assertPattern(t('%Claimed item id=.*string=@string for 0 seconds.%', array('@string' => "boogie$i")));
  35. }
  36. $edit = array('queue_name' => 'queue_example_first_queue', 'claim_time' => 0);
  37. $this->drupalPost(NULL, $edit, t('Claim the next item from the queue'));
  38. $this->assertText(t('There were no items in the queue available to claim'));
  39. // Sleep a second so we can make sure that the timeouts actually time out.
  40. // Local systems work fine with this but apparently the PIFR server is so
  41. /// fast that it needs a sleep before the cron run.
  42. sleep(1);
  43. // Run cron to release expired items.
  44. $this->drupalPost(NULL, array(), t('Run cron manually (to expire claimed items)'));
  45. $queue_items = queue_example_retrieve_queue('queue_example_first_queue');
  46. // Claim and delete each of the 5 items which should now be available.
  47. for ($i = 1; $i <= 5; $i++) {
  48. $edit = array('queue_name' => 'queue_example_first_queue', 'claim_time' => 0);
  49. $this->drupalPost(NULL, $edit, t('Claim the next item and delete it'));
  50. $this->assertPattern(t('%Claimed and deleted item id=.*string=@string for 0 seconds.%', array('@string' => "boogie$i")));
  51. }
  52. // Verify that nothing is left to claim.
  53. $edit = array('queue_name' => 'queue_example_first_queue', 'claim_time' => 0);
  54. $this->drupalPost(NULL, $edit, t('Claim the next item from the queue'));
  55. $this->assertText(t('There were no items in the queue available to claim'));
  56. }
  57. }
Login or register to post comments