Пример #1
0
 /**
  * @covers F4h_TicketConverter_Dependency_Verifier::checkDependencies
  */
 public function testCheckDependencies()
 {
     //assert that loaded extension return true
     $this->assertTrue(F4h_TicketConverter_Dependency_Verifier::checkDependencies($this->goodDependencies));
     //assert no dependencies return true
     $this->assertTrue(F4h_TicketConverter_Dependency_Verifier::checkDependencies(array()));
     //assert that a not loaded extension causes an exception
     $this->assertInternalType($this->setExpectedException('F4h_TicketConverter_Dependency_Exception'), F4h_TicketConverter_Dependency_Verifier::checkDependencies($this->badDependencies));
 }
Пример #2
0
 /**
  * @return bool
  */
 public static function go()
 {
     session_start();
     session_regenerate_id();
     $_SESSION['notices'] = '';
     $_SESSION['errors'] = '';
     $_SESSION['success'] = '';
     $_SESSION['informational'] = '';
     try {
         //check dependencies, e.g. needed php extensions
         F4h_TicketConverter_Dependency_Verifier::checkDependencies(F4h_TicketConverter_Config::getInstance()->getDependencies());
         //get QueueBuilder
         $queueBuilder = F4h_TicketConverter_QueueBuilder_Factory::getQueueBuilder(self::getInput());
         if ($queueBuilder) {
             //build requestQueue
             $queue = $queueBuilder->build();
             if (!isset($_SESSION['tickets_to_confirm'])) {
                 self::_checkCollection($queue);
             } else {
                 unset($_SESSION['tickets_to_confirm']);
             }
             if (count($queue) !== 0) {
                 //pass requestQueue to Manager -> invoke output creation process
                 $manager = new F4h_TicketConverter_Manager($queue);
                 $buildingOutputIsSuccessful = $manager->buildOutput();
                 //return output depending on output type set in Config Class -> either send directly to printer or show as html
                 if ($buildingOutputIsSuccessful) {
                     $outputPath = F4h_TicketConverter_Config::getInstance()->getOutputFile();
                     if (F4h_TicketConverter_Config::getInstance()->getEnvironment() === F4h_TicketConverter_Config::ENV_WEB) {
                         switch (F4h_TicketConverter_Config::getInstance()->getOutputType()) {
                             //build pdf with apache fop and send it directly to printer
                             case F4h_TicketConverter_Config::OUTPUT_PDF:
                                 exec('sh ' . F4h_TicketConverter_Config::getInstance()->getApacheFopPath() . ' ' . $outputPath . ' output.pdf');
                                 //comment the following line out for testing purpose
                                 exec('lp -d ' . F4h_TicketConverter_Config::getInstance()->getPrinterName() . ' -o media=A6 -o landscape output.pdf');
                                 $outputPath = substr($outputPath, 0, strrpos($outputPath, '.')) . '.pdf';
                                 break;
                                 //redirect to output.html
                             //redirect to output.html
                             case F4h_TicketConverter_Config::OUTPUT_HTML:
                                 header('Location: output.html');
                                 break;
                         }
                     } else {
                         self::getMsgContainer()->push(new F4h_TicketConverter_Model_Message("output-path: " . $outputPath, F4h_TicketConverter_Model_Message::NOTICE));
                     }
                 }
             } else {
                 self::getMsgContainer()->push(new F4h_TicketConverter_Model_Message('In der Liste der zu druckenden Tickets wurden nur bereits gedruckte oder ungültigen Ticket-IDs angegeben.', F4h_TicketConverter_Model_Message::ERROR));
             }
         }
     } catch (F4h_TicketConverter_Exception_Dependency $dependencyException) {
         self::getMsgContainer()->push(new F4h_TicketConverter_Model_Message('Der Ticketconverter kann nicht gestartet werden, da eine oder mehrere Abhängigkeiten fehlen.', F4h_TicketConverter_Model_Message::ERROR));
         F4h_TicketConverter_Log_Exception_Handler::trap($dependencyException);
     } catch (F4h_TicketConverter_Exception_Abstract $tcException) {
         if ($tcException->getLogLevel() === F4h_TicketConverter_Log_Exception_Handler::FATAL) {
             self::getMsgContainer()->push(new F4h_TicketConverter_Model_Message($tcException->getMessage(), F4h_TicketConverter_Model_Message::ERROR));
         }
         F4h_TicketConverter_Log_Exception_Handler::trap($tcException);
     } catch (Exception $exception) {
         self::getMsgContainer()->push(new F4h_TicketConverter_Model_Message($exception->getMessage(), F4h_TicketConverter_Model_Message::ERROR));
         F4h_TicketConverter_Log_Exception_Handler::trap($exception);
     }
     self::_response();
     return true;
 }