SchedulerTests.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. require_once(dirname(__FILE__)."/../Schedule.php");
  3. class SchedulerTests extends PHPUnit_TestCase {
  4. private $groupIdCreated;
  5. private $storedFile;
  6. private $storedFile2;
  7. function setup() {
  8. global $CC_CONFIG;
  9. // Clear the files table
  10. //$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
  11. // Add a file
  12. $values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
  13. $this->storedFile = Application_Model_StoredFile::Insert($values, false);
  14. // Add a file
  15. $values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
  16. $this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
  17. // Clear the schedule table
  18. //$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
  19. }
  20. function testDateToId() {
  21. $dateStr = "2006-04-02 10:20:08.123456";
  22. $id = Application_Model_ScheduleGroup::dateToId($dateStr);
  23. $expected = "20060402102008123";
  24. if ($id != $expected) {
  25. $this->fail("Did not convert date to ID correctly #1: $id != $expected");
  26. }
  27. $dateStr = "2006-04-02 10:20:08";
  28. $id = Application_Model_ScheduleGroup::dateToId($dateStr);
  29. $expected = "20060402102008000";
  30. if ($id != $expected) {
  31. $this->fail("Did not convert date to ID correctly #2: $id != $expected");
  32. }
  33. }
  34. function testAddAndRemoveAudioFile() {
  35. $i = new Application_Model_ScheduleGroup();
  36. $this->groupIdCreated = $i->add('2010-10-10 01:30:23', $this->storedFile->getId());
  37. $i = new Application_Model_ScheduleGroup($this->groupIdCreated);
  38. $result = $i->remove();
  39. if ($result != 1) {
  40. $this->fail("Did not remove item.");
  41. }
  42. }
  43. function testAddAndRemovePlaylist() {
  44. // Create a playlist
  45. $playlist = new Application_Model_Playlist();
  46. $playlist->create("Scheduler Unit Test ".uniqid());
  47. $result = $playlist->addAudioClip($this->storedFile->getId());
  48. $result = $playlist->addAudioClip($this->storedFile2->getId());
  49. $result = $playlist->addAudioClip($this->storedFile2->getId());
  50. $i = new Application_Model_ScheduleGroup();
  51. $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
  52. $group = new Application_Model_ScheduleGroup($this->groupIdCreated);
  53. if ($group->count() != 3) {
  54. $this->fail("Wrong number of items added.");
  55. }
  56. $items = $group->getItems();
  57. if (!is_array($items) || ($items[1]["starts"] != "2010-11-11 01:30:34.231")) {
  58. $this->fail("Wrong start time for 2nd item.");
  59. }
  60. $result = $group->remove();
  61. if ($result != 1) {
  62. $this->fail("Did not remove item.");
  63. }
  64. Application_Model_Playlist::Delete($playlist->getId());
  65. }
  66. function testIsScheduleEmptyInRange() {
  67. $i = new Application_Model_ScheduleGroup();
  68. $this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId());
  69. if (Application_Model_Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
  70. $this->fail("Reporting empty schedule when it isnt.");
  71. return;
  72. }
  73. // echo "groupid: ".$this->groupIdCreated."\n";
  74. $success = $i->remove();
  75. if ($success === false) {
  76. $this->fail("Failed to delete schedule group.");
  77. return;
  78. }
  79. if (!Application_Model_Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) {
  80. $this->fail("Reporting booked schedule when it isnt.");
  81. return;
  82. }
  83. }
  84. /*
  85. function testGetItems() {
  86. $i1 = new Application_Model_ScheduleGroup();
  87. $groupId1 = $i1->add('2008-01-01 12:00:00.000', $this->storedFile->getId());
  88. $i2 = new Application_Model_ScheduleGroup();
  89. $i2->addAfter($groupId1, $this->storedFile->getId());
  90. $items = Application_Model_Schedule::getItems("2008-01-01", "2008-01-02");
  91. if (count($items) != 2) {
  92. $this->fail("Wrong number of items returned.");
  93. return;
  94. }
  95. $i1->remove();
  96. $i2->remove();
  97. }
  98. */
  99. }