/** * Test alias generator * * @dataProvider provideTitleAlias */ public function testSetAliasFromTitle($title, $alias) { $page = new Default_Model_Page(); $page->setTitle($title); $page->setAliasFromTitle(); $this->assertEquals($alias, $page->getAlias()); }
/** * Reads content from the filesystem * based on the given contentAlias and language. * * @param string $contentAlias * @param string $lang * @param Default_Model_Page $page * @return Default_Model_Page * @throws Light_Exception_NotFound If file not found or not readable * @uses TITLE_CONTENT_SEPARATOR */ public function find($contentAlias, $lang, Default_Model_Page $page) { if (empty($contentAlias)) { require_once 'Light/Exception/InvalidParameter.php'; throw new Light_Exception_InvalidParameter('content alias was empty'); } if (empty($lang)) { require_once 'Light/Exception/InvalidParameter.php'; throw new Light_Exception_InvalidParameter('language was empty'); } $filteredAlias = $this->filterContentAlias($contentAlias); //prevent content duplication by referring to filtered pages if ($filteredAlias !== $contentAlias) { require_once 'Light/Exception/InvalidParameter.php'; throw new Light_Exception_InvalidParameter('Invalid content alias provided'); } $filteredLang = $this->filterLanguage($lang); if ($filteredLang !== $lang) { require_once 'Light/Exception/InvalidParameter.php'; throw new Light_Exception_InvalidParameter('Invalid language provided'); } $filePath = $this->getDirectoryRoot() . DIRECTORY_SEPARATOR . $lang . DIRECTORY_SEPARATOR . $filteredAlias; if (!is_readable($filePath)) { require_once 'Light/Exception/NotFound.php'; throw new Light_Exception_NotFound('File not found or not readable'); } $file = file_get_contents($filePath); $fileTitleContent = explode(self::TITLE_CONTENT_SEPARATOR, $file, 2); if (isset($fileTitleContent[1])) { //content has title $title = $fileTitleContent[0]; $page->setTitle($title); $content = $fileTitleContent[1]; $page->setContent($content); } else { $content = $fileTitleContent[0]; $page->setContent($content); } $page->setAlias($filteredAlias); $page->setLanguage($lang); return $page; }