Example #1
0
 public function testSetData()
 {
     $page = new Page(new Request());
     $page->setData('place', 'Norway');
     $page->setData(['city' => 'Oslo', 'height' => 12]);
     $ref_data = new \ReflectionProperty($page, '_data');
     $ref_data->setAccessible(true);
     $expected = ['place' => 'Norway', 'city' => 'Oslo', 'height' => 12];
     $result = $ref_data->getvalue($page);
     $this->assertEquals($expected, $result);
 }
Example #2
0
 /**
  * @throws \Error
  */
 public function render()
 {
     $h = $this->_config['header_func'] ?? 'header';
     if (is_callable($h) == false) {
         throw new \Error("Header function injected to Error is not callable");
     }
     $errorPage = null;
     switch ($this->code) {
         case 404:
             $h("HTTP/1.0 404 Not Found");
             $errorPage = new Page(new Request(['url' => '404']), $this->_config);
             break;
         case 400:
             $h("HTTP/1.0 400 {$this->message}");
             break;
         default:
             $h("HTTP/1.0 {$this->code} Bad request");
             $errorPage = new Page(new Request(['url' => '500']), $this->_config);
             break;
     }
     if ($errorPage) {
         // TODO only do this if request accepts html?
         try {
             $errorPage->setData('message', $this->message);
             echo $errorPage->render();
         } catch (\alkemann\h2l\exceptions\InvalidUrl $e) {
             if (defined('DEBUG') && DEBUG) {
                 echo "No error page made at " . $e->getMessage();
             }
         }
     }
 }
 public function testSetData()
 {
     $this->page->setData($this->data);
     $this->assertEquals($this->data, $this->page->getData());
 }