ElggCoreDatabaseQueueTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * \Elgg\Queue\DatabaseQueue tests
  4. *
  5. * @package Elgg
  6. * @subpackage Test
  7. */
  8. class ElggCoreDatabaseQueueTest extends \ElggCoreUnitTest {
  9. public function testEnqueueAndDequeue() {
  10. $queue = new \Elgg\Queue\DatabaseQueue('unit:test', _elgg_services()->db);
  11. $first = array(1, 2, 3);
  12. $second = array(4, 5, 6);
  13. $result = $queue->enqueue($first);
  14. $this->assertTrue($result);
  15. $result = $queue->enqueue($second);
  16. $this->assertTrue($result);
  17. $this->assertIdentical(2, $queue->size());
  18. $data = $queue->dequeue();
  19. $this->assertIdentical($first, $data);
  20. $data = $queue->dequeue();
  21. $this->assertIdentical($second, $data);
  22. $data = $queue->dequeue();
  23. $this->assertIdentical(null, $data);
  24. }
  25. public function testMultipleQueues() {
  26. $queue1 = new \Elgg\Queue\DatabaseQueue('unit:test1', _elgg_services()->db);
  27. $queue2 = new \Elgg\Queue\DatabaseQueue('unit:test2', _elgg_services()->db);
  28. $first = array(1, 2, 3);
  29. $second = array(4, 5, 6);
  30. $result = $queue1->enqueue($first);
  31. $this->assertTrue($result);
  32. $result = $queue2->enqueue($second);
  33. $this->assertTrue($result);
  34. $this->assertIdentical(1, $queue1->size());
  35. $this->assertIdentical(1, $queue2->size());
  36. $data = $queue2->dequeue();
  37. $this->assertIdentical($second, $data);
  38. $data = $queue1->dequeue();
  39. $this->assertIdentical($first, $data);
  40. }
  41. public function testClear() {
  42. $queue = new \Elgg\Queue\DatabaseQueue('unit:test', _elgg_services()->db);
  43. $first = array(1, 2, 3);
  44. $second = array(4, 5, 6);
  45. $result = $queue->enqueue($first);
  46. $this->assertTrue($result);
  47. $result = $queue->enqueue($second);
  48. $this->assertTrue($result);
  49. $queue->clear();
  50. $data = $queue->dequeue();
  51. $this->assertIdentical(null, $data);
  52. $this->assertIdentical(0, $queue->size());
  53. }
  54. }