예제 #1
0
파일: PageTest.php 프로젝트: erenon/Light
 /**
  * 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());
 }
예제 #2
0
 /**
  * Persists the given model on the backend.
  *
  * Creates a language dir if not presented, and writes a file into it.
  * Filename is the page alias.
  *
  * @param Default_Model_Page $page Page model to save
  * @return bool true
  * @throws Light_Exception_InvalidParameter
  * If language or alias not presented in the model
  */
 public function save(Default_Model_Page $page)
 {
     if ("" == $page->getLanguage()) {
         require_once 'Light/Exception/InvalidParameter.php';
         throw new Light_Exception_InvalidParameter("Language not provided");
     }
     if ("" == $page->getAlias()) {
         require_once 'Light/Exception/InvalidParameter.php';
         throw new Light_Exception_InvalidParameter("Alias not provided");
     }
     $fileUri = $this->getDirectoryRoot() . DIRECTORY_SEPARATOR . $page->getLanguage() . DIRECTORY_SEPARATOR . $page->getAlias();
     $fileContent = $this->_contentFromTitleAndContent($page->getTitle(), $page->getContent());
     $this->_createDirIfNeeded($page->getLanguage());
     file_put_contents($fileUri, $fileContent);
     return true;
 }