queue_example.test 2.7 KB

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