public function setUp()
 {
     $this->setupFile = dirname(__FILE__) . '/../VideoPageTool.setup.php';
     parent::setUp();
     $mock_user = $this->getMock('User', ['getId', 'getName']);
     $mock_user->expects($this->any())->method('getId')->will($this->returnValue(123));
     $mock_user->expects($this->any())->method('getName')->will($this->returnValue('Garthwebb'));
     $this->mockGlobalVariable('wgUser', $mock_user);
     $this->mockStaticMethod('User', 'newFromId', $mock_user);
     /*
      * That's pretty bad, as we will return master db connection for all wfGetDB calls, even those for slave and
      * dataware. But as for now mockGlobalFunction does not support PHPUnit's callbacks and returnValueArray
      */
     $slaveDb = wfGetDB(DB_MASTER, [], 'video151');
     $this->mockGlobalFunction('wfGetDB', $slaveDb);
     $language = 'en';
     $date = 158486400;
     // This is Jan 9th, 1975 a date suitably far in the past but doing well for its age thank you very much
     $this->program = VideoPageToolProgram::newProgram($language, $date);
     // If a previous test faield and didn't clean itself up, clean up now.  This includes
     // deleting related assets and clearing their caches
     if ($this->program->exists()) {
         $cascade = true;
         $this->program->delete($cascade);
         $this->program = VideoPageToolProgram::newProgram($language, $date);
     }
     if (empty($this->program)) {
         throw new Exception("Failed to load program with lang={$language} and date={$date}");
     }
     // Save this program to get a program ID
     $status = $this->program->save();
     if (!$status->isGood()) {
         throw new Exception("Failed to save program with lang={$language} and date={$date}");
     }
     $this->programID = $this->program->getProgramId();
 }
 /**
  * Publish program
  * @requestParam string language
  * @requestParam string date [timestamp]
  * @responseParam string result [ok/error]
  * @responseParam string msg - result message
  */
 public function publish()
 {
     $time = $this->getVal('date', time());
     $language = $this->getVal('language', VideoPageToolHelper::DEFAULT_LANGUAGE);
     if ($this->request->wasPosted()) {
         $program = VideoPageToolProgram::newProgram($language, $time);
         if (!$program->exists()) {
             $this->result = 'error';
             $this->msg = wfMessage('videopagetool-error-unknown-program')->plain();
             return;
         }
         // get all sections
         $helper = new VideoPageToolHelper();
         $sections = array_keys($helper->getSections());
         // validate program
         if (!$program->isPublishable($sections)) {
             $this->result = 'error';
             $this->msg = wfMessage('videopagetool-error-program-not-ready')->plain();
             return;
         }
         // publish program
         $status = $program->publishProgram();
         if (!$status->isGood()) {
             $this->result = 'error';
             $this->msg = $status->getMessage();
             return;
         }
     }
     $this->result = 'ok';
     $this->msg = '';
 }