public function testExceptions() { $exp = Exception::GetHTTPInfo(Exception::NOT_FOUND, true); $r = new Router(new URL('hello'), $this->path); $p = $r->process(true); $h = $p->render(); $this->assertEquals($exp, $p->getTitle(), 'Ошибка: страница не найдена'); $this->assertSelectCount('html body h1', true, $h, 'Заголовок страницы с ошибкой'); $this->assertSelectCount('html body h3', false, $h, 'Debug=off Описания нет'); $this->assertSelectCount('html body p', false, $h, 'Debug=off Стека вызовов нет'); $r = new Router(); //Путь к контроллерам не прописан $r->enableDebug(); //В режиме отладки выводится доп.информация при ошибках $p = $r->process(true); $h = $p->render(); $this->assertEquals($exp, $p->getTitle(), 'Отсутствие контроллера по-умолчанию'); $this->assertSelectCount('html body h1', true, $h, 'Заголовок страницы с ошибкой'); $this->assertSelectCount('html body h3', true, $h, 'Описание'); $this->assertSelectCount('html body p', true, $h, 'Стек вызовов'); }
function testMessage() { try { Controller::Redirect('/some/path.html'); $this->fail('Редирект выбрасывает исключение'); } catch (\CMSx\Controller\Exception $e) { $m = Exception::GetHTTPInfo($e->getCode(), true); $s = Exception::GetHTTPInfo($e->getCode()); $h = 'HTTP/1.0 ' . $e->getCode() . ' ' . $s; $this->assertNotEmpty($m, 'Текст ошибки есть'); $this->assertNotEmpty($s, 'Статус ошибки есть'); $this->assertEquals($m, $e->getHumanMessage(), 'Текст ошибки для человеков'); $this->assertEquals($s, $e->getHTTPStatus(), 'HTTP Status для роботов'); $this->assertEquals($h, $e->getHTTPHeader(), 'Сформированный HTTP Header'); } }
/** * Редирект на заданный URL * $permanent - постоянный или временный редирект * * @throws Exception */ public static function Redirect($url, $permanent = false) { Exception::Redirect($url, $permanent); }