Exemple #1
0
 /**
  * @dataProvider pageWithAssetDataProvider
  */
 public function testPageWithAsset($siteRoot, $prettyUrls, $name, $expectedName, $expectedAsset)
 {
     $fs = MockFileSystem::create()->withConfig(array('site' => array('root' => $siteRoot, 'pretty_urls' => $prettyUrls)))->withPage($name, array('layout' => 'none', 'format' => 'none'), "Some contents:\n{{ assets.foo }}")->withAsset('_content/pages/blah-assets/foo.txt', 'FOO!');
     $app = new PieCrust(array('root' => $fs->url('kitchen')));
     $page = Page::createFromUri($app, '/' . $name, false);
     $baker = new PageBaker($app, $fs->url('counter'), null, array('copy_assets' => true));
     $baker->bake($page);
     $this->assertFalse($baker->wasPaginationDataAccessed());
     $this->assertEquals(1, $baker->getPageCount());
     $this->assertEquals(array($fs->url('counter/' . $expectedName)), $baker->getBakedFiles());
     $this->assertFileExists($fs->url('counter/' . $expectedName));
     $this->assertEquals("Some contents:\n" . $expectedAsset, file_get_contents($fs->url('counter/' . $expectedName)));
     $expectedAssetPath = substr($expectedAsset, strlen($siteRoot));
     $this->assertFileExists($fs->url('counter/' . $expectedAssetPath));
     $this->assertEquals('FOO!', file_get_contents($fs->url('counter/' . $expectedAssetPath)));
 }
 protected function bakeCategories()
 {
     if ($this->bakeRecord == null) {
         throw new PieCrustException("Can't bake categories without a bake-record active.");
     }
     $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs');
     foreach ($blogKeys as $blogKey) {
         // Check that there is a category listing page to bake.
         $prefix = '';
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             $prefix = $blogKey . DIRECTORY_SEPARATOR;
         }
         $categoryPageName = $prefix . PieCrustDefaults::CATEGORY_PAGE_NAME . '.html';
         $categoryPagePath = PathHelper::getUserOrThemeOrResPath($this->pieCrust, $categoryPageName);
         if ($categoryPagePath === false) {
             continue;
         }
         // Order categories so it looks nicer when we bake.
         $categoriesToBake = $this->bakeRecord->getCategoriesToBake($blogKey);
         sort($categoriesToBake);
         // Bake!
         $pageRepository = $this->pieCrust->getEnvironment()->getPageRepository();
         foreach ($categoriesToBake as $category) {
             $start = microtime(true);
             $postInfos = $this->bakeRecord->getPostsInCategory($blogKey, $category);
             if (count($postInfos) > 0) {
                 $uri = UriBuilder::buildCategoryUri($this->pieCrust->getConfig()->getValue($blogKey . '/category_url'), $category);
                 $page = $pageRepository->getOrCreatePage($uri, $categoryPagePath, IPage::TYPE_CATEGORY, $blogKey, $category);
                 $baker = new PageBaker($this->getBakeDir(), $this->getPageBakerParameters());
                 $baker->bake($page);
                 $pageCount = $baker->getPageCount();
                 $this->logger->info(self::formatTimed($start, 'category:' . $category . ($pageCount > 1 ? " [{$pageCount}]" : "")));
             }
         }
     }
 }