Example #1
0
 public function testPageOutput()
 {
     View::instance()->html = array();
     ob_start();
     View::lang('en');
     View::title('Test Title');
     View::desc('Test Desc');
     View::html('Content');
     View::styleSrc('/css/css.css');
     View::scriptSrc('/js/js.js');
     View::script('alert("Hi");');
     View::printPage();
     $c = ob_get_contents();
     ob_end_clean();
     $this->assertContains("<html lang='en'", $c);
     $this->assertContains('<title>Test Title</title>', $c);
     $this->assertContains("<meta name='description' content=\"Test Desc\">", $c);
     $this->assertContains('Content', $c);
     $this->assertContains('<link rel="stylesheet" type="text/css" href="/css/css.css"/>', $c);
     $this->assertContains('<script type="text/javascript" src="/js/js.js"></script>', $c);
     $this->assertContains('<script type="text/javascript">alert("Hi");</script>', $c);
 }
Example #2
0
 /**
  * Serve a specified http response code page by either executing a template or the passed \Closure $fun function, 
  * or loading the \Closure function from the file $this->errorDir . $code.php and executing it or by 
  * a default message set by the function.
  *
  *
  * @param int $code The http repsonse code sent to the client from the server.
  * @param boolean|string|\Closure $action A template or closure to execute when $code != 200.
  * @return void 
  */
 public final function serve($code = 200, $action = false)
 {
     if ($code != 200) {
         //set the response code
         http_response_code($code);
         //clear the body of the view
         \View::body('');
         if (is_string($action)) {
             \Template::with($action);
         } else {
             if ($action !== false && $action instanceof \Closure) {
                 call_user_func($action);
             } else {
                 $file = \App::path() . '/' . trim($this->errorDir, '/') . '/' . $code . '.php';
                 if (is_file($file)) {
                     $action = (require $file);
                     call_user_func($action, \App::instance());
                 }
                 //if
             }
         }
         //el
     }
     //if
     //Print out the Current View.
     if (!\App::instance()->cli) {
         \View::printPage();
     }
     //if
     exit;
 }