CC-5651: Unit Test the Scheduler
This commit is contained in:
parent
01ec611ae2
commit
c329d54252
12 changed files with 183 additions and 1 deletions
|
@ -40,6 +40,9 @@ set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_pat
|
|||
//Services
|
||||
set_include_path(APPLICATION_PATH . '/services' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//models
|
||||
set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//Controller plugins.
|
||||
set_include_path(APPLICATION_PATH . '/controllers/plugins' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ require_once "AirtimeInstall.php";
|
|||
require_once "ShowServiceData.php";
|
||||
require_once "TestHelper.php";
|
||||
|
||||
class ShowServiceTest extends Zend_Test_PHPUnit_DatabaseTestCase
|
||||
class ShowServiceDbTest extends Zend_Test_PHPUnit_DatabaseTestCase
|
||||
{
|
||||
private $_connectionMock;
|
||||
|
|
@ -151,6 +151,81 @@ Class ShowServiceData
|
|||
);
|
||||
}
|
||||
|
||||
public static function getWeeklyRepeatWithEndNoRRData()
|
||||
{
|
||||
return array(
|
||||
"add_show_id" => -1,
|
||||
"add_show_instance_id" => -1,
|
||||
"add_show_name" => "test show",
|
||||
"add_show_url" => null,
|
||||
"add_show_genre" => null,
|
||||
"add_show_description" => null,
|
||||
"add_show_start_date" => "2016-01-01",
|
||||
"add_show_start_time" => "00:00",
|
||||
"add_show_end_date_no_repeat" => "2016-01-01",
|
||||
"add_show_end_time" => "01:00",
|
||||
"add_show_duration" => "01h 00m",
|
||||
"add_show_timezone" => "UTC",
|
||||
"add_show_repeats" => 1,
|
||||
"add_show_linked" => 0,
|
||||
"add_show_repeat_type" => 0,
|
||||
"add_show_monthly_repeat_type" => 2,
|
||||
"add_show_end_date" => "2016-01-26",
|
||||
"add_show_no_end" => 0,
|
||||
"cb_airtime_auth" => 0,
|
||||
"cb_custom_auth" => 0,
|
||||
"custom_username" => null,
|
||||
"custom_password" => null,
|
||||
"add_show_record" => 0,
|
||||
"add_show_rebroadcast" => 0,
|
||||
"add_show_rebroadcast_date_absolute_1" => null,
|
||||
"add_show_rebroadcast_time_absolute_1" => null,
|
||||
"add_show_rebroadcast_date_absolute_2" => null,
|
||||
"add_show_rebroadcast_time_absolute_2" => null,
|
||||
"add_show_rebroadcast_date_absolute_3" => null,
|
||||
"add_show_rebroadcast_time_absolute_3" => null,
|
||||
"add_show_rebroadcast_date_absolute_4" => null,
|
||||
"add_show_rebroadcast_time_absolute_4" => null,
|
||||
"add_show_rebroadcast_date_absolute_5" => null,
|
||||
"add_show_rebroadcast_time_absolute_5" => null,
|
||||
"add_show_rebroadcast_date_absolute_6" => null,
|
||||
"add_show_rebroadcast_time_absolute_6" => null,
|
||||
"add_show_rebroadcast_date_absolute_7" => null,
|
||||
"add_show_rebroadcast_time_absolute_7" => null,
|
||||
"add_show_rebroadcast_date_absolute_8" => null,
|
||||
"add_show_rebroadcast_time_absolute_8" => null,
|
||||
"add_show_rebroadcast_date_absolute_9" => null,
|
||||
"add_show_rebroadcast_time_absolute_9" => null,
|
||||
"add_show_rebroadcast_date_absolute_10" => null,
|
||||
"add_show_rebroadcast_time_absolute_10" => null,
|
||||
"add_show_rebroadcast_date_1" => null,
|
||||
"add_show_rebroadcast_time_1" => null,
|
||||
"add_show_rebroadcast_date_2" => null,
|
||||
"add_show_rebroadcast_time_2" => null,
|
||||
"add_show_rebroadcast_date_3" => null,
|
||||
"add_show_rebroadcast_time_3" => null,
|
||||
"add_show_rebroadcast_date_4" => null,
|
||||
"add_show_rebroadcast_time_4" => null,
|
||||
"add_show_rebroadcast_date_5" => null,
|
||||
"add_show_rebroadcast_time_5" => null,
|
||||
"add_show_rebroadcast_date_6" => null,
|
||||
"add_show_rebroadcast_time_6" => null,
|
||||
"add_show_rebroadcast_date_7" => null,
|
||||
"add_show_rebroadcast_time_7" => null,
|
||||
"add_show_rebroadcast_date_8" => null,
|
||||
"add_show_rebroadcast_time_8" => null,
|
||||
"add_show_rebroadcast_date_9" => null,
|
||||
"add_show_rebroadcast_time_9" => null,
|
||||
"add_show_rebroadcast_date_10" => null,
|
||||
"add_show_rebroadcast_time_10" => null,
|
||||
"add_show_hosts_autocomplete" => null,
|
||||
"add_show_background_color" => "364492",
|
||||
"add_show_color" => "ffffff",
|
||||
"add_show_hosts" => null,
|
||||
"add_show_day_check" => array(5)
|
||||
);
|
||||
}
|
||||
|
||||
public static function getWeeklyRepeatDays()
|
||||
{
|
||||
return array(1,2,3,4,5);
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
require_once "../application/configs/conf.php";
|
||||
require_once "ShowService.php";
|
||||
require_once "ShowServiceData.php";
|
||||
|
||||
class ShowServiceUnitTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $_showService;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_showService = new Application_Service_ShowService();
|
||||
}
|
||||
|
||||
public function testFormatShowDurationOneHour()
|
||||
{
|
||||
$duration = Application_Service_ShowService::formatShowDuration("01h 00m");
|
||||
$this->assertEquals("01:00", $duration);
|
||||
}
|
||||
|
||||
public function testFormatShowDurationLessThanOneHour()
|
||||
{
|
||||
$duration = Application_Service_ShowService::formatShowDuration("00h 05m");
|
||||
$this->assertEquals("00:05", $duration);
|
||||
}
|
||||
|
||||
public function testFormatShowDurationMoreTHanOneHour()
|
||||
{
|
||||
$duration = Application_Service_ShowService::formatShowDuration("03h 55m");
|
||||
$this->assertEquals("03:55", $duration);
|
||||
}
|
||||
|
||||
public function testCalculateEndDateNoRepeat()
|
||||
{
|
||||
$end = $this->_showService->calculateEndDate(ShowServiceData::getNoRepeatNoRRData());
|
||||
$this->assertEquals(null, $end);
|
||||
}
|
||||
|
||||
public function testCalculateEndDateRepeatWithEndDate()
|
||||
{
|
||||
$end = $this->_showService->calculateEndDate(ShowServiceData::getWeeklyRepeatWithEndNoRRData());
|
||||
$this->assertEquals(new DateTime("2016-01-27", new DateTimeZone("UTC")), $end);
|
||||
}
|
||||
|
||||
public function testCalculateEndDateRepeatWithNoEndDate()
|
||||
{
|
||||
$end = $this->_showService->calculateEndDate(ShowServiceData::getWeeklyRepeatNoEndNoRRData());
|
||||
$this->assertEquals(null, $end);
|
||||
}
|
||||
|
||||
public function testGetMonthlyWeeklyRepeatIntervalFirstWeek()
|
||||
{
|
||||
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime("2016-01-01"), new DateTimeZone("UTC"));
|
||||
$this->assertEquals(array("first", "Friday"), $repeatInterval);
|
||||
}
|
||||
|
||||
public function testGetMonthlyWeeklyRepeatIntervalSecondWeek()
|
||||
{
|
||||
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime("2016-01-12"), new DateTimeZone("UTC"));
|
||||
$this->assertEquals(array("second", "Tuesday"), $repeatInterval);
|
||||
}
|
||||
|
||||
public function testGetMonthlyWeeklyRepeatIntervalThirdWeek()
|
||||
{
|
||||
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime("2016-01-18"), new DateTimeZone("UTC"));
|
||||
$this->assertEquals(array("third", "Monday"), $repeatInterval);
|
||||
}
|
||||
|
||||
public function testGetMonthlyWeeklyRepeatIntervalFifthWeek()
|
||||
{
|
||||
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime("2016-01-30"), new DateTimeZone("UTC"));
|
||||
$this->assertEquals(array("fifth", "Saturday"), $repeatInterval);
|
||||
}
|
||||
|
||||
public function testGetMonthlyWeeklyRepeatIntervalFourthWeek()
|
||||
{
|
||||
$repeatInterval = $this->_showService->getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime("2016-01-28"), new DateTimeZone("UTC"));
|
||||
$this->assertEquals(array("fourth", "Thursday"), $repeatInterval);
|
||||
}
|
||||
|
||||
public function testGetNextMonthlyMonthlyRepeatDate()
|
||||
{
|
||||
$next = $this->_showService->getNextMonthlyMonthlyRepeatDate(
|
||||
new DateTime("2016-01-01"), "UTC", "00:00");
|
||||
$this->assertEquals(new DateTime("2016-02-01", new DateTimeZone("UTC")), $next);
|
||||
}
|
||||
|
||||
public function testGetNextMonthlyMonthlyRepeatDateSkipsMonth()
|
||||
{
|
||||
$next = $this->_showService->getNextMonthlyMonthlyRepeatDate(
|
||||
new DateTime("2016-01-30"), "UTC", "00:00");
|
||||
$this->assertEquals(new DateTime("2016-03-30", new DateTimeZone("UTC")), $next);
|
||||
}
|
||||
|
||||
public function testCreateUTCStartEndDateTime()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue