/** * Setup before tests * * @return void */ public function setUp() { mkdir('foobar'); mkdir('foobar' . DIRECTORY_SEPARATOR . 'templates'); file_put_contents('foobar' . DIRECTORY_SEPARATOR . 'layout.html', '{{ layout.content|raw }}'); file_put_contents('foobar' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'main.html', '{{ content | raw }}'); $testThemesDir = APP_PATH . DIRECTORY_SEPARATOR . 'tests'; $theme = new Theme('foobar', '/baseurl', $testThemesDir); $view = new View($theme); $view->setContentDir(realpath('.')); file_put_contents('mycontentfile.md', '#contents'); $this->_object = new Content('mycontentfile.md', $view); }
/** * Handle thrown exceptions * * @param \Exception $exception The Exception object * @return void */ public static function handleException(\Exception $exception) { $request = new Request(); try { $theme = new Theme(self::getKernel()->getConfig('theme'), $request->getBaseUrl()); $view = new View($theme); $view->setParams(self::getKernel()->getConfig()); if ($exception instanceof \Greengrape\Exception\NotFoundException) { $httpHeader = 'HTTP/1.1 404 Not Found'; $templateFile = '404.html'; } else { $httpHeader = 'HTTP/1.1 500 Internal Server Error'; $templateFile = 'error.html'; } if (!headers_sent()) { header($httpHeader); } $content = new Content('', $view); $content->setTemplateFile($templateFile); $content->setContent($exception->getMessage() . '<pre>' . $exception->getTraceAsString() . '</pre>'); $vars = array('trace' => self::displayException($exception)); echo $view->render($content, $vars); } catch (\Exception $newException) { $errorTitle = 'Exception found while handling exception:'; $message = htmlentities($newException->getMessage()); printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message); print self::displayException($newException); if ($newException->getMessage() != $exception->getMessage()) { $errorTitle = 'This was the original exception:'; $message = htmlentities($exception->getMessage()); printf(self::EXCEPTION_MESSAGE_CAPSULE, $errorTitle, $message); } } }
/** * testGetLayoutFileNotExist * * @expectedException Greengrape\Exception\NotFoundException * @return void */ public function testGetLayoutFileNotExist() { $view = new View(new MockTheme('foo')); $layout = $view->getLayout(); }
/** * Set up the navigation items and assign them to the view * * @param Greengrape\Request $sitemap Sitemap object * @param string $uri Current URI * @param Greengrape\View $view View object * @return void */ public function setupNavigationItems(Request $request, $uri, View $view) { $mainNavigationCollection = new NavigationCollection($this->getContentDir(), $request->getBaseUrl()); foreach ($mainNavigationCollection as $item) { // If the first part of the URI matches this item's href then this // should be the active navigation item if (strpos($uri, $item->getHref()) === 0) { $item->setActive(true); $view->setActiveNavigationItem($item); } } $view->setNavigationItems($mainNavigationCollection); if (!$view->getActiveNavigationItem()) { // If we don't have an active navigation item, don't try to get the // sub navigation return false; } $subNavigationCollection = new NavigationCollection($this->getContentDir(), $request->getBaseUrl(), $view->getActiveNavigationItem()); foreach ($subNavigationCollection as $subItem) { // If the first part of the URI matches this item's href then this // should be the active navigation item if (strpos($uri, $subItem->getHref()) === 0) { $subItem->setActive(true); $view->setActiveSubNavigationItem($subItem); } } $view->setSubNavigationItems($subNavigationCollection); }