CC-5651: Unit Test the Scheduler
* Added a beastly unit test for Application_Model_Schedule::isFileScheduledInTheFuture
This commit is contained in:
parent
dfc4c2f308
commit
296adfdb24
|
@ -46,6 +46,9 @@ set_include_path(APPLICATION_PATH . '/services' . PATH_SEPARATOR . get_include_p
|
|||
//models
|
||||
set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//Controllers.
|
||||
set_include_path(APPLICATION_PATH . '/controllers' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
//Controller plugins.
|
||||
set_include_path(APPLICATION_PATH . '/controllers/plugins' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
|
@ -58,18 +61,16 @@ set_include_path(APPLICATION_PATH . '/../tests/application/helpers' . PATH_SEPAR
|
|||
//Zend framework
|
||||
if (file_exists('/usr/share/php/libzend-framework-php')) {
|
||||
set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path());
|
||||
set_include_path('/usr/share/php/libzend-framework-php/Zend/Test/PHPUnit' . PATH_SEPARATOR . get_include_path());
|
||||
}
|
||||
|
||||
require_once 'Zend/Application.php';
|
||||
require_once 'Zend/Config.php';
|
||||
//require_once 'helpers/TestHelper.php';
|
||||
|
||||
require_once APPLICATION_PATH.'/configs/conf.php';
|
||||
require_once 'propel/runtime/lib/Propel.php';
|
||||
Propel::init("../application/configs/airtime-conf-production.php");
|
||||
|
||||
#require_once 'DatabaseTestCase.php';
|
||||
require_once 'Zend/Session.php';
|
||||
Zend_Session::start();
|
||||
|
||||
//TestHelper::installTestDatabase();
|
||||
|
|
|
@ -61,7 +61,9 @@ class TestHelper
|
|||
//Add any tables that shouldn't be cleared here.
|
||||
// cc_subjs - Most of Airtime requires an admin account to work, which has id=1,
|
||||
// so don't clear it.
|
||||
$tablesToNotClear = array("cc_subjs");
|
||||
// cc_music_dirs - Has foreign key constraints against cc_files, so we clear cc_files
|
||||
// first and ckear cc_music_dirs after
|
||||
$tablesToNotClear = array("cc_subjs", "cc_music_dirs");
|
||||
|
||||
$con->beginTransaction();
|
||||
foreach ($rows as $row) {
|
||||
|
@ -78,6 +80,11 @@ class TestHelper
|
|||
$sql = "DELETE FROM $tablename";
|
||||
AirtimeInstall::InstallQuery($sql, false);
|
||||
}
|
||||
|
||||
//Now that cc_files is empty, clearing cc_music_dirs should work
|
||||
$sql = "DELETE FROM cc_music_dirs";
|
||||
AirtimeInstall::InstallQuery($sql, false);
|
||||
|
||||
$con->commit();
|
||||
|
||||
//Because we're DELETEing all the rows instead of using TRUNCATE (for speed),
|
||||
|
|
|
@ -10,14 +10,18 @@ class PreferenceUnitTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
TestHelper::installTestDatabase();
|
||||
TestHelper::setupZendBootstrap();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public function testSetHeadTitle()
|
||||
{
|
||||
$title = "unit test";
|
||||
//This function is confusing and doesn't really work so we're just gonna let it slide...
|
||||
Application_Model_Preference::SetHeadTitle($title);
|
||||
//$this->assertEquals(Application_Model_Preference::GetHeadTitle(), $title);
|
||||
$this->assertEquals(Application_Model_Preference::GetHeadTitle(), $title);
|
||||
}
|
||||
*/
|
||||
|
||||
public function testSetShowsPopulatedUntil()
|
||||
{
|
||||
|
|
|
@ -1,11 +1,97 @@
|
|||
<?php
|
||||
require_once "../application/configs/conf.php";
|
||||
//require_once "../application/configs/conf.php";
|
||||
require_once "TestHelper.php";
|
||||
require_once "ShowServiceData.php";
|
||||
require_once "Schedule.php";
|
||||
require_once "Zend/Controller/Action.php";
|
||||
require_once "ControllerTestCase.php";
|
||||
require_once "ApiController.php";
|
||||
|
||||
class ScheduleUnitTest extends PHPUnit_Framework_TestCase
|
||||
class ScheduleUnitTest extends Zend_Test_PHPUnit_ControllerTestCase //PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
TestHelper::installTestDatabase();
|
||||
TestHelper::setupZendBootstrap();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testCheckOverlappingShows()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testIsFileScheduledInTheFuture()
|
||||
{
|
||||
TestHelper::loginUser();
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
|
||||
$testShowData = ShowServiceData::getNoRepeatNoRRData();
|
||||
$showService = new Application_Service_ShowService();
|
||||
$futureDate = new DateTime();
|
||||
$futureDate->add(new DateInterval('P1Y')); //1 year into the future
|
||||
$futureDateString = $futureDate->format('Y-m-d');
|
||||
|
||||
$testShowData["add_show_start_date"] = $futureDateString;
|
||||
$testShowData["add_show_end_date"] = $futureDateString;
|
||||
$testShowData["add_show_end_date_no_repeat"] = $futureDateString;
|
||||
|
||||
//Fudge the "populated until" date to workaround and issue where the default
|
||||
//value will prevent anything from actually being scheduled. Normally this isn't
|
||||
//a problem because as soon as you view the calendar for the first time, this is
|
||||
//set to a week ahead in the future.
|
||||
$populateUntil = new DateTime("now", new DateTimeZone('UTC'));
|
||||
$populateUntil = $populateUntil->add(new DateInterval("P2Y")); //2 years ahead in the future.
|
||||
Application_Model_Preference::SetShowsPopulatedUntil($populateUntil);
|
||||
|
||||
//$showService->setCcShow($testShowData); //Denise says this is not needed.
|
||||
$showService->addUpdateShow($testShowData); //Create show instances
|
||||
|
||||
// Because files are stored relative to their watch directory,
|
||||
// we need to set the "stor" path before we can successfully
|
||||
// create a fake file in the database.
|
||||
//Copy paste from airtime-db-install.php:
|
||||
$stor_dir = "/tmp";
|
||||
$con = Propel::getConnection();
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
try {
|
||||
$con->exec($sql);
|
||||
} catch (Exception $e) {
|
||||
echo " * Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
|
||||
echo " * Message {$e->getMessage()}".PHP_EOL;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Insert a fake file into the database
|
||||
$request = $this->getRequest();
|
||||
$params = $request->getParams();
|
||||
$params['action'] = '';
|
||||
$params['api_key'] = $CC_CONFIG["apiKey"][0];
|
||||
$request->setParams($params);
|
||||
|
||||
$metadata = array("MDATA_KEY_FILEPATH" => "/tmp/foobar.mp3",
|
||||
"MDATA_KEY_DURATION" => "00:01:00",
|
||||
"is_record" => false);
|
||||
|
||||
//Create the file in the database via the HTTP API.
|
||||
$apiController = new ApiController($this->request, $this->getResponse());
|
||||
$results = $apiController->dispatchMetadata($metadata, "create");
|
||||
$fileId = $results["fileid"];
|
||||
$this->assertNotEquals($fileId, -1);
|
||||
$this->assertEquals($fileId, 1);
|
||||
|
||||
//The file should not be scheduled in the future (or at all) at this point
|
||||
$scheduleModel = new Application_Model_Schedule();
|
||||
$scheduleModel->IsFileScheduledInTheFuture($fileId);
|
||||
$this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), false);
|
||||
|
||||
//Schedule the fake file in the test show, which should be in the future.
|
||||
$showInstance = new Application_Model_ShowInstance(1);
|
||||
$showInstance->addFileToShow($fileId);
|
||||
|
||||
//Test the function we actually want to test. :-)
|
||||
$this->assertEquals($scheduleModel->IsFileScheduledInTheFuture($fileId), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
Class ShowServiceData
|
||||
{
|
||||
//Just a regular show - Non repeating, and not a recording & rebroadcast show.
|
||||
public static function getNoRepeatNoRRData()
|
||||
{
|
||||
return array(
|
||||
|
@ -487,4 +488,4 @@ Class ShowServiceData
|
|||
"add_show_day_check" => array(5)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue