ShowServiceDbTest.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. require_once "Zend/Test/PHPUnit/DatabaseTestCase.php";
  3. require_once "ShowService.php";
  4. require_once "../application/configs/conf.php";
  5. require_once "ShowServiceData.php";
  6. require_once "TestHelper.php";
  7. #require_once "PHPUnit/Extensions/Database/DataSet/ReplacementDataSet.php";
  8. /*
  9. * All dates in the xml files are hard coded and in the year 2016
  10. * It would have been nice to use 'PHPUnit/Extensions/Database/DataSet/ReplacementDataSet.php'
  11. * to be able to use variables in the xml dataset files so dates can be relative. This proved
  12. * not practical for Airtime; For repeating shows, the start times are always varying and would
  13. * require functions that calculate the start and end dates, and the next populate date. The
  14. * tests would be performing the same work as the application and require tests themselves.
  15. */
  16. class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase
  17. {
  18. private $_connectionMock;
  19. //private $_nowDT;
  20. public function setUp()
  21. {
  22. TestHelper::installTestDatabase();
  23. TestHelper::setupZendBootstrap();
  24. //$this->_nowDT = new DateTime("now", new DateTimeZone("UTC"));
  25. parent::setUp();
  26. }
  27. public function getConnection()
  28. {
  29. if ($this->_connectionMock == null) {
  30. $config = TestHelper::getDbZendConfig();
  31. $connection = Zend_Db::factory('pdo_pgsql', $config);
  32. $this->_connectionMock = $this->createZendDbConnection(
  33. $connection,
  34. 'airtimeunittests'
  35. );
  36. Zend_Db_Table_Abstract::setDefaultAdapter($connection);
  37. }
  38. return $this->_connectionMock;
  39. }
  40. /* Defines how the initial state of the database should look before each test is executed
  41. * Called once during setUp() and gets recreated for each new test
  42. */
  43. public function getDataSet()
  44. {
  45. $xml_dataset = $this->createXmlDataSet(
  46. dirname(__FILE__) . '/datasets/seed_show_service.xml'
  47. );
  48. /*$xml_dataset_fixed = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet(
  49. $xml_dataset, array('SIX_WEEKS' => $this->_nowDT->add(new DateInterval("P42D"))->format("Y-m-d H:i:s")));
  50. return $xml_dataset_fixed;*/
  51. return $xml_dataset;
  52. }
  53. public function testCcShowInsertedIntoDatabase()
  54. {
  55. $showService = new Application_Service_ShowService();
  56. $data = array(
  57. "add_show_id" => -1,
  58. "add_show_name" => "test show",
  59. "add_show_description" => null,
  60. "add_show_url" => null,
  61. "add_show_genre" => null,
  62. "add_show_color" => "ffffff",
  63. "add_show_background_color" => "364492",
  64. "cb_airtime_auth" => false,
  65. "cb_custom_auth" => false,
  66. "custom_username" => null,
  67. "custom_password" => null,
  68. "add_show_linked" => false
  69. );
  70. $showService->setCcShow($data);
  71. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  72. $this->getConnection()
  73. );
  74. $ds->addTable('cc_show', 'select * from cc_show');
  75. $this->assertDataSetsEqual(
  76. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_ccShowInsertedIntoDatabase.xml"),
  77. $ds
  78. );
  79. }
  80. /* Tests that a non-repeating, non-record, and non-rebroadcast show
  81. * gets created properly
  82. */
  83. public function testCreateNoRepeatNoRRShow()
  84. {
  85. TestHelper::loginUser();
  86. $data = ShowServiceData::getNoRepeatNoRRData();
  87. $showService = new Application_Service_ShowService(null, $data);
  88. $showService->addUpdateShow($data);
  89. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  90. $this->getConnection()
  91. );
  92. $ds->addTable('cc_show', 'select * from cc_show');
  93. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  94. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  95. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  96. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  97. $this->assertDataSetsEqual(
  98. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createNoRepeatNoRRShow.xml"),
  99. $ds
  100. );
  101. }
  102. /* Tests that a weekly repeating, non-record, non-rebroadcast show
  103. * with no end date gets created correctly
  104. */
  105. public function testCreateWeeklyRepeatNoEndNoRRShow()
  106. {
  107. TestHelper::loginUser();
  108. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  109. $showService = new Application_Service_ShowService(null, $data);
  110. $showService->addUpdateShow($data);
  111. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  112. $this->getConnection()
  113. );
  114. $ds->addTable('cc_show', 'select * from cc_show');
  115. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  116. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  117. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  118. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  119. $this->assertDataSetsEqual(
  120. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createWeeklyRepeatNoEndNoRRShow.xml"),
  121. $ds
  122. );
  123. }
  124. public function testCreateBiWeeklyRepeatNoEndNoRRShow()
  125. {
  126. TestHelper::loginUser();
  127. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  128. $data["add_show_repeat_type"] = "1";
  129. $showService = new Application_Service_ShowService(null, $data);
  130. $showService->addUpdateShow($data);
  131. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  132. $this->getConnection()
  133. );
  134. $ds->addTable('cc_show', 'select * from cc_show');
  135. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  136. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  137. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  138. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  139. $this->assertDataSetsEqual(
  140. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createBiWeeklyRepeatNoEndNoRRShow.xml"),
  141. $ds
  142. );
  143. }
  144. public function testCreateTriWeeklyRepeatNoEndNoRRShow()
  145. {
  146. TestHelper::loginUser();
  147. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  148. $data["add_show_repeat_type"] = "4";
  149. $showService = new Application_Service_ShowService(null, $data);
  150. $showService->addUpdateShow($data);
  151. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  152. $this->getConnection()
  153. );
  154. $ds->addTable('cc_show', 'select * from cc_show');
  155. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  156. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  157. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  158. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  159. $this->assertDataSetsEqual(
  160. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createTriWeeklyRepeatNoEndNoRRShow.xml"),
  161. $ds
  162. );
  163. }
  164. public function testCreateQuadWeeklyRepeatNoEndNoRRShow()
  165. {
  166. TestHelper::loginUser();
  167. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  168. $data["add_show_repeat_type"] = "5";
  169. $showService = new Application_Service_ShowService(null, $data);
  170. $showService->addUpdateShow($data);
  171. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  172. $this->getConnection()
  173. );
  174. $ds->addTable('cc_show', 'select * from cc_show');
  175. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  176. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  177. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  178. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  179. $this->assertDataSetsEqual(
  180. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createQuadWeeklyRepeatNoEndNoRRShow.xml"),
  181. $ds
  182. );
  183. }
  184. public function testCreateMonthlyMonthlyRepeatNoEndNoRRShow()
  185. {
  186. TestHelper::loginUser();
  187. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  188. $data["add_show_repeat_type"] = "2";
  189. $showService = new Application_Service_ShowService(null, $data);
  190. $showService->addUpdateShow($data);
  191. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  192. $this->getConnection()
  193. );
  194. $ds->addTable('cc_show', 'select * from cc_show');
  195. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  196. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  197. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  198. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  199. $this->assertDataSetsEqual(
  200. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createMonthlyMonthlyRepeatNoEndNoRRShow.xml"),
  201. $ds
  202. );
  203. }
  204. public function testCreateMonthlyWeeklyRepeatNoEndNoRRShow()
  205. {
  206. TestHelper::loginUser();
  207. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  208. $data["add_show_repeat_type"] = "3";
  209. $showService = new Application_Service_ShowService(null, $data);
  210. $showService->addUpdateShow($data);
  211. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  212. $this->getConnection()
  213. );
  214. $ds->addTable('cc_show', 'select * from cc_show');
  215. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  216. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  217. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  218. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  219. $this->assertDataSetsEqual(
  220. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createMonthlyWeeklyRepeatNoEndNoRRShow.xml"),
  221. $ds
  222. );
  223. }
  224. /* Tests that a show instance gets deleted from it's repeating sequence properly
  225. */
  226. public function testDeleteShowInstance()
  227. {
  228. TestHelper::loginUser();
  229. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  230. $service_show = new Application_Service_ShowService(null, $data);
  231. $service_show->addUpdateShow($data);
  232. $service_show->deleteShow(3, true);
  233. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  234. $this->getConnection()
  235. );
  236. $ds->addTable('cc_show', 'select * from cc_show');
  237. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  238. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances order by id');
  239. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  240. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  241. $this->assertDataSetsEqual(
  242. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_deleteShowInstance.xml"),
  243. $ds
  244. );
  245. }
  246. /* Tests that when a user selects 'Delete this instance and all following
  247. * on the calendar the database gets updated correctly
  248. */
  249. public function testDeleteShowInstanceAndAllFollowing()
  250. {
  251. TestHelper::loginUser();
  252. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  253. $data["add_show_day_check"] = array(5,1,2);
  254. $service_show = new Application_Service_ShowService(null, $data);
  255. $service_show->addUpdateShow($data);
  256. //delete some single instances first
  257. $service_show->deleteShow(1, true);
  258. $service_show->deleteShow(6, true);
  259. $service_show->deleteShow(8, true);
  260. //delete all instances including and after where id=4
  261. $service_show->deleteShow(4);
  262. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  263. $this->getConnection()
  264. );
  265. $ds->addTable('cc_show', 'select * from cc_show');
  266. $ds->addTable('cc_show_days', 'select * from cc_show_days order by first_show');
  267. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances order by id');
  268. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  269. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  270. $this->assertDataSetsEqual(
  271. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_deleteShowInstanceAndAllFollowing.xml"),
  272. $ds
  273. );
  274. }
  275. public function testEditRepeatingShowInstance()
  276. {
  277. TestHelper::loginUser();
  278. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  279. $showService = new Application_Service_ShowService(null, $data);
  280. $showService->addUpdateShow($data);
  281. //move the start date forward one week and the start time forward one hour
  282. $editData = ShowServiceData::getEditRepeatInstanceData();
  283. //need to create a new service so it gets constructed with the new data
  284. $showService = new Application_Service_ShowService(null, $editData);
  285. $showService->editRepeatingShowInstance($editData);
  286. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  287. $this->getConnection()
  288. );
  289. $ds->addTable('cc_show', 'select * from cc_show');
  290. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  291. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances order by id');
  292. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  293. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  294. $this->assertDataSetsEqual(
  295. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_editRepeatingShowInstance.xml"),
  296. $ds
  297. );
  298. }
  299. /* Tests the entire show gets deleted when the user selects 'Delete this
  300. * instance and all following' from the context menu on the calendar
  301. */
  302. public function testDeleteRepeatingShow()
  303. {
  304. TestHelper::loginUser();
  305. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  306. $showService = new Application_Service_ShowService(null, $data);
  307. $showService->addUpdateShow($data);
  308. $showService->deleteShow(1);
  309. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  310. $this->getConnection()
  311. );
  312. $ds->addTable('cc_show', 'select * from cc_show');
  313. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  314. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances order by id');
  315. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  316. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  317. $this->assertDataSetsEqual(
  318. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_deleteRepeatingShow.xml"),
  319. $ds
  320. );
  321. }
  322. public function testRepeatShowCreationWhenUserMovesForwardInCalendar()
  323. {
  324. TestHelper::loginUser();
  325. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  326. $data["add_show_repeat_type"] = "1";
  327. $showService = new Application_Service_ShowService(null, $data);
  328. $showService->addUpdateShow($data);
  329. //simulate the user moves forward in the calendar
  330. $end = new DateTime("2016-03-12", new DateTimeZone("UTC"));
  331. $showService->delegateInstanceCreation(null, $end, true);
  332. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  333. $this->getConnection()
  334. );
  335. $ds->addTable('cc_show', 'select * from cc_show');
  336. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  337. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  338. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  339. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  340. $this->assertDataSetsEqual(
  341. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_repeatShowCreationWhenUserMovesForwardInCalendar.xml"),
  342. $ds
  343. );
  344. }
  345. public function testLinkedShow()
  346. {
  347. TestHelper::loginUser();
  348. /** Test creating a linked show **/
  349. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  350. $data["add_show_linked"] = 1;
  351. $showService = new Application_Service_ShowService(null, $data);
  352. $showService->addUpdateShow($data);
  353. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  354. $this->getConnection()
  355. );
  356. $ds->addTable('cc_show', 'select * from cc_show');
  357. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  358. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  359. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  360. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  361. $this->assertDataSetsEqual(
  362. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createLinkedShow.xml"),
  363. $ds
  364. );
  365. }
  366. /** Test the creation of a single record and rebroadcast(RR) show **/
  367. public function testCreateNoRepeatRRShow()
  368. {
  369. TestHelper::loginUser();
  370. $data = ShowServiceData::getNoRepeatRRData();
  371. $showService = new Application_Service_ShowService(null, $data);
  372. $showService->addUpdateShow($data);
  373. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  374. $this->getConnection()
  375. );
  376. $ds->addTable('cc_show', 'select * from cc_show');
  377. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  378. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  379. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  380. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  381. $this->assertDataSetsEqual(
  382. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createNoRepeatRRShow.xml"),
  383. $ds
  384. );
  385. }
  386. /** Test the creation of a weekly repeating, record and rebroadcast(RR) show **/
  387. public function testCreateWeeklyRepeatRRShow()
  388. {
  389. TestHelper::loginUser();
  390. $data = ShowServiceData::getWeeklyRepeatRRData();
  391. $showService = new Application_Service_ShowService(null, $data);
  392. $showService->addUpdateShow($data);
  393. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  394. $this->getConnection()
  395. );
  396. $ds->addTable('cc_show', 'select * from cc_show');
  397. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  398. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  399. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  400. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  401. $this->assertDataSetsEqual(
  402. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_createWeeklyRepeatRRShow.xml"),
  403. $ds
  404. );
  405. }
  406. public function testEditRepeatingShowChangeNoEndOption()
  407. {
  408. TestHelper::loginUser();
  409. /** Test changing the no end option on a weekly repeating show **/
  410. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  411. $showService = new Application_Service_ShowService(null, $data);
  412. $showService->addUpdateShow($data);
  413. $data["add_show_end_date"] = '2016-01-09';
  414. $data["add_show_no_end"] = 0;
  415. $data["add_show_id"] = 1;
  416. $showService = new Application_Service_ShowService(null, $data, true);
  417. $showService->addUpdateShow($data);
  418. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  419. $this->getConnection()
  420. );
  421. $ds->addTable('cc_show', 'select * from cc_show');
  422. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  423. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  424. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  425. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  426. $this->assertDataSetsEqual(
  427. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_editRepeatingShowChangeNoEndOption.xml"),
  428. $ds
  429. );
  430. }
  431. /**
  432. * Tests that when you remove the first repeat show day, which changes
  433. * the show's first instance start date, updates the scheduled content
  434. * correctly
  435. */
  436. public function testRemoveFirstRepeatShowDayUpdatesScheduleCorrectly()
  437. {
  438. TestHelper::loginUser();
  439. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  440. $data["add_show_start_date"] = "2016-01-29";
  441. $data["add_show_day_check"] = array(5,6);
  442. $data["add_show_linked"] = 1;
  443. $showService = new Application_Service_ShowService(null, $data);
  444. $showService->addUpdateShow($data);
  445. //insert some fake tracks into cc_schedule table
  446. $ccFiles = new CcFiles();
  447. $ccFiles
  448. ->setDbCueIn("00:00:00")
  449. ->setDbCueOut("00:04:32")
  450. ->save();
  451. $scheduleItems = array(
  452. 0 => array(
  453. "id" => 0,
  454. "instance" => 1,
  455. "timestamp" => time()
  456. )
  457. );
  458. $mediaItems = array(
  459. 0 => array(
  460. "id" => 1,
  461. "type" => "audioclip"
  462. )
  463. );
  464. $scheduler = new Application_Model_Scheduler();
  465. $scheduler->scheduleAfter($scheduleItems, $mediaItems);
  466. //delete the first repeat day
  467. $data["add_show_day_check"] = array(6);
  468. $data["add_show_id"] = 1;
  469. $showService = new Application_Service_ShowService(null, $data, true);
  470. $showService->addUpdateShow($data);
  471. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  472. $this->getConnection()
  473. );
  474. $ds->addTable('cc_show', 'select * from cc_show');
  475. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  476. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  477. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  478. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  479. $ds->addTable('cc_schedule', 'select id, starts, ends, file_id, clip_length, fade_in, fade_out, cue_in, cue_out, instance_id, playout_status from cc_schedule');
  480. $this->assertDataSetsEqual(
  481. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_removeFirstRepeatShowDayUpdatesScheduleCorrectly.xml"),
  482. $ds
  483. );
  484. }
  485. public function testChangeRepeatDayUpdatesScheduleCorrectly()
  486. {
  487. TestHelper::loginUser();
  488. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  489. $data["add_show_start_date"] = "2016-01-29";
  490. $data["add_show_day_check"] = array(5, 6);
  491. $data["add_show_linked"] = 1;
  492. $showService = new Application_Service_ShowService(null, $data);
  493. $showService->addUpdateShow($data);
  494. //insert some fake tracks into cc_schedule table
  495. $ccFiles = new CcFiles();
  496. $ccFiles
  497. ->setDbCueIn("00:00:00")
  498. ->setDbCueOut("00:04:32")
  499. ->save();
  500. $scheduleItems = array(
  501. 0 => array(
  502. "id" => 0,
  503. "instance" => 1,
  504. "timestamp" => time()
  505. )
  506. );
  507. $mediaItems = array(
  508. 0 => array(
  509. "id" => 1,
  510. "type" => "audioclip"
  511. )
  512. );
  513. $scheduler = new Application_Model_Scheduler();
  514. $scheduler->scheduleAfter($scheduleItems, $mediaItems);
  515. //delete the first repeat day
  516. $data["add_show_day_check"] = array(6);
  517. $data["add_show_id"] = 1;
  518. $showService = new Application_Service_ShowService(null, $data, true);
  519. $showService->addUpdateShow($data);
  520. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  521. $this->getConnection()
  522. );
  523. $ds->addTable('cc_show', 'select * from cc_show');
  524. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  525. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  526. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  527. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  528. $ds->addTable('cc_schedule', 'select id, starts, ends, file_id, clip_length, fade_in, fade_out, cue_in, cue_out, instance_id, playout_status from cc_schedule');
  529. $this->assertDataSetsEqual(
  530. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_changeRepeatDayUpdatesScheduleCorrectly.xml"),
  531. $ds
  532. );
  533. }
  534. public function testChangeRepeatTypeFromWeeklyToNoRepeat()
  535. {
  536. TestHelper::loginUser();
  537. //test change repeat type from weekly to no-repeat
  538. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  539. $showService = new Application_Service_ShowService(null, $data);
  540. $showService->addUpdateShow($data);
  541. $data["add_show_repeats"] = 0;
  542. $data["add_show_id"] = 1;
  543. $showService = new Application_Service_ShowService(null, $data, true);
  544. $showService->addUpdateShow($data);
  545. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  546. $this->getConnection()
  547. );
  548. $ds->addTable('cc_show', 'select * from cc_show');
  549. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  550. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  551. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  552. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  553. $this->assertDataSetsEqual(
  554. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_weeklyToNoRepeat.xml"),
  555. $ds
  556. );
  557. }
  558. public function testChangeRepeatTypeFromWeeklyToBiWeekly()
  559. {
  560. TestHelper::loginUser();
  561. //test change repeat type weekly to bi-weekly
  562. $data = ShowServiceData::getWeeklyRepeatNoEndNoRRData();
  563. $showService = new Application_Service_ShowService(null, $data);
  564. $showService->addUpdateShow($data);
  565. $data["add_show_id"] = 1;
  566. $data["add_show_repeat_type"] = 1;
  567. $showService = new Application_Service_ShowService(null, $data, true);
  568. $showService->addUpdateShow($data);
  569. $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
  570. $this->getConnection()
  571. );
  572. $ds->addTable('cc_show', 'select * from cc_show');
  573. $ds->addTable('cc_show_days', 'select * from cc_show_days');
  574. $ds->addTable('cc_show_instances', 'select id, starts, ends, show_id, record, rebroadcast, instance_id, modified_instance from cc_show_instances');
  575. $ds->addTable('cc_show_rebroadcast', 'select * from cc_show_rebroadcast');
  576. $ds->addTable('cc_show_hosts', 'select * from cc_show_hosts');
  577. $this->assertDataSetsEqual(
  578. $this->createXmlDataSet(dirname(__FILE__)."/datasets/test_weeklyToBiWeekly.xml"),
  579. $ds
  580. );
  581. }
  582. public function testChangeRepeatTypeFromMonthlyWeeklyToNoRepeat()
  583. {
  584. }
  585. }