ScheduleUnitTest.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. //require_once "../application/configs/conf.php";
  3. require_once "TestHelper.php";
  4. require_once "ShowServiceData.php";
  5. require_once "Schedule.php";
  6. require_once "Zend/Controller/Action.php";
  7. require_once "ControllerTestCase.php";
  8. require_once "ApiController.php";
  9. class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Framework_TestCase
  10. {
  11. public function setUp()
  12. {
  13. TestHelper::installTestDatabase();
  14. TestHelper::setupZendBootstrap();
  15. parent::setUp();
  16. }
  17. public function testCheckOverlappingShows()
  18. {
  19. }
  20. public function testIsFileScheduledInTheFuture()
  21. {
  22. TestHelper::loginUser();
  23. $CC_CONFIG = Config::getConfig();
  24. $testShowData = ShowServiceData::getNoRepeatNoRRData();
  25. $showService = new Application_Service_ShowService();
  26. $futureDate = new DateTime();
  27. $futureDate->add(new DateInterval('P1Y')); //1 year into the future
  28. $futureDateString = $futureDate->format('Y-m-d');
  29. $testShowData["add_show_start_date"] = $futureDateString;
  30. $testShowData["add_show_end_date"] = $futureDateString;
  31. $testShowData["add_show_end_date_no_repeat"] = $futureDateString;
  32. //Fudge the "populated until" date to workaround and issue where the default
  33. //value will prevent anything from actually being scheduled. Normally this isn't
  34. //a problem because as soon as you view the calendar for the first time, this is
  35. //set to a week ahead in the future.
  36. $populateUntil = new DateTime("now", new DateTimeZone('UTC'));
  37. $populateUntil = $populateUntil->add(new DateInterval("P2Y")); //2 years ahead in the future.
  38. Application_Model_Preference::SetShowsPopulatedUntil($populateUntil);
  39. //$showService->setCcShow($testShowData); //Denise says this is not needed.
  40. $showService->addUpdateShow($testShowData); //Create show instances
  41. // Because files are stored relative to their watch directory,
  42. // we need to set the "stor" path before we can successfully
  43. // create a fake file in the database.
  44. //Copy paste from airtime-db-install.php:
  45. $stor_dir = "/tmp";
  46. $con = Propel::getConnection();
  47. $sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
  48. try {
  49. $con->exec($sql);
  50. } catch (Exception $e) {
  51. echo " * Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
  52. echo " * Message {$e->getMessage()}".PHP_EOL;
  53. return false;
  54. }
  55. // Insert a fake file into the database
  56. $request = $this->getRequest();
  57. $params = $request->getParams();
  58. $params['action'] = '';
  59. $params['api_key'] = $CC_CONFIG["apiKey"][0];
  60. $request->setParams($params);
  61. $metadata = array("MDATA_KEY_FILEPATH" => "/tmp/foobar.mp3",
  62. "MDATA_KEY_DURATION" => "00:01:00",
  63. "is_record" => false);
  64. //Create the file in the database via the HTTP API.
  65. $apiController = new ApiController($this->request, $this->getResponse());
  66. $results = $apiController->dispatchMetadata($metadata, "create");
  67. $fileId = $results["fileid"];
  68. $this->assertNotEquals($fileId, -1);
  69. $this->assertEquals($fileId, 1);
  70. //The file should not be scheduled in the future (or at all) at this point
  71. $scheduleModel = new Application_Model_Schedule();
  72. $scheduleModel->IsFileScheduledInTheFuture($fileId);
  73. $this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), false);
  74. //Schedule the fake file in the test show, which should be in the future.
  75. $showInstance = new Application_Model_ShowInstance(1);
  76. $showInstance->addFileToShow($fileId);
  77. //Test the function we actually want to test. :-)
  78. $this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), true);
  79. }
  80. }