ShowServiceUnitTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. require_once "../application/configs/conf.php";
  3. require_once "ShowService.php";
  4. require_once "ShowServiceData.php";
  5. class ShowServiceUnitTest extends PHPUnit_Framework_TestCase
  6. {
  7. // needed for accessing private methods
  8. protected $_reflectionOfShowService;
  9. protected $_showService;
  10. public function setUp()
  11. {
  12. $this->_reflectionOfShowService = new ReflectionClass('Application_Service_ShowService');
  13. $this->_showService = new Application_Service_ShowService();
  14. }
  15. public function testFormatShowDuration()
  16. {
  17. $duration = Application_Service_ShowService::formatShowDuration("01h 00m");
  18. $this->assertEquals("01:00", $duration);
  19. $duration = Application_Service_ShowService::formatShowDuration("00h 05m");
  20. $this->assertEquals("00:05", $duration);
  21. $duration = Application_Service_ShowService::formatShowDuration("03h 55m");
  22. $this->assertEquals("03:55", $duration);
  23. }
  24. public function testCalculateEndDate()
  25. {
  26. $method = $this->_reflectionOfShowService->getMethod('calculateEndDate');
  27. $method->setAccessible(true);
  28. $end = $method->invokeArgs($this->_showService, array(ShowServiceData::getNoRepeatNoRRData()));
  29. $this->assertEquals(null, $end);
  30. $end = $method->invokeArgs($this->_showService, array(ShowServiceData::getWeeklyRepeatWithEndNoRRData()));
  31. $this->assertEquals(new DateTime("2016-01-27", new DateTimeZone("UTC")), $end);
  32. $end = $method->invokeArgs($this->_showService, array(ShowServiceData::getWeeklyRepeatNoEndNoRRData()));
  33. $this->assertEquals(null, $end);
  34. }
  35. public function testGetMonthlyWeeklyRepeatInterval()
  36. {
  37. $method = $this->_reflectionOfShowService->getMethod('getMonthlyWeeklyRepeatInterval');
  38. $method->setAccessible(true);
  39. $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-01"), new DateTimeZone("UTC")));
  40. $this->assertEquals(array("first", "Friday"), $repeatInterval);
  41. $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-12"), new DateTimeZone("UTC")));
  42. $this->assertEquals(array("second", "Tuesday"), $repeatInterval);
  43. $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-18"), new DateTimeZone("UTC")));
  44. $this->assertEquals(array("third", "Monday"), $repeatInterval);
  45. $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-28"), new DateTimeZone("UTC")));
  46. $this->assertEquals(array("fourth", "Thursday"), $repeatInterval);
  47. $repeatInterval = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-30"), new DateTimeZone("UTC")));
  48. $this->assertEquals(array("fifth", "Saturday"), $repeatInterval);
  49. }
  50. public function testGetNextMonthlyMonthlyRepeatDate()
  51. {
  52. $method = $this->_reflectionOfShowService->getMethod('getNextMonthlyMonthlyRepeatDate');
  53. $method->setAccessible(true);
  54. $next = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-01"), "UTC", "00:00"));
  55. $this->assertEquals(new DateTime("2016-02-01", new DateTimeZone("UTC")), $next);
  56. $next = $method->invokeArgs($this->_showService, array(new DateTime("2016-01-30"), "UTC", "00:00"));
  57. $this->assertEquals(new DateTime("2016-03-30", new DateTimeZone("UTC")), $next);
  58. }
  59. public function testGetNextMonthlyWeeklyRepeatDate()
  60. {
  61. $method = $this->_reflectionOfShowService->getMethod('getNextMonthlyWeeklyRepeatDate');
  62. $method->setAccessible(true);
  63. $next = $method->invokeArgs($this->_showService, array(
  64. new DateTime("2016-02-01"), "UTC", "00:00", "first", "Friday"));
  65. $this->assertEquals(new DateTime("2016-02-05", new DateTimeZone("UTC")), $next);
  66. $next = $method->invokeArgs($this->_showService, array(
  67. new DateTime("2016-02-01"), "UTC", "00:00", "fifth", "Saturday"));
  68. $this->assertEquals(new DateTime("2016-04-30", new DateTimeZone("UTC")), $next);
  69. $next = $method->invokeArgs($this->_showService, array(
  70. new DateTime("2016-02-01"), "UTC", "00:00", "fourth", "Monday"));
  71. $this->assertEquals(new DateTime("2016-02-22", new DateTimeZone("UTC")), $next);
  72. }
  73. public function testCreateUTCStartEndDateTime()
  74. {
  75. $method = $this->_reflectionOfShowService->getMethod('createUTCStartEndDateTime');
  76. $method->setAccessible(true);
  77. $utcTimezone = new DateTimeZone("UTC");
  78. //America/Toronto
  79. $localStartDT = new DateTime("2016-01-01 06:30", new DateTimeZone("America/Toronto"));
  80. $localEndDT = new DateTime("2016-01-01 07:30", new DateTimeZone("America/Toronto"));
  81. $dt = $method->invokeArgs($this->_showService, array($localStartDT, "01:00"));
  82. $this->assertEquals(array(
  83. $localStartDT->setTimezone($utcTimezone),$localEndDT->setTimezone($utcTimezone)), $dt);
  84. //America/Toronto with offset for rebroadcast shows
  85. $localStartDT = new DateTime("2016-01-01 06:30", new DateTimeZone("America/Toronto"));
  86. $localEndDT = new DateTime("2016-01-01 07:30", new DateTimeZone("America/Toronto"));
  87. $localRebroadcastStartDT = new DateTime("2016-01-02 06:30", new DateTimeZone("America/Toronto"));
  88. $localRebroadcastEndDT = new DateTime("2016-01-02 07:30", new DateTimeZone("America/Toronto"));
  89. $dt = $method->invokeArgs($this->_showService, array($localStartDT, "01:00",
  90. array("days" => "1", "hours" => "06", "mins" => "30")));
  91. $this->assertEquals(array(
  92. $localRebroadcastStartDT->setTimezone($utcTimezone),$localRebroadcastEndDT->setTimezone($utcTimezone)), $dt);
  93. //Australia/Brisbane
  94. $localStartDT = new DateTime("2016-01-01 06:30", new DateTimeZone("Australia/Brisbane"));
  95. $localEndDT = new DateTime("2016-01-01 07:30", new DateTimeZone("Australia/Brisbane"));
  96. $dt = $method->invokeArgs($this->_showService, array($localStartDT, "01:00"));
  97. $this->assertEquals(array(
  98. $localStartDT->setTimezone($utcTimezone), $localEndDT->setTimezone($utcTimezone)), $dt);
  99. //America/Vancouver
  100. $localStartDT = new DateTime("2016-01-01 06:30", new DateTimeZone("America/Vancouver"));
  101. $localEndDT = new DateTime("2016-01-01 07:30", new DateTimeZone("America/Vancouver"));
  102. $dt = $method->invokeArgs($this->_showService, array($localStartDT, "01:00"));
  103. $this->assertEquals(array(
  104. $localStartDT->setTimezone($utcTimezone), $localEndDT->setTimezone($utcTimezone)), $dt);
  105. }
  106. }