示例#1
0
 /**
  * @dataProvider buildCategoryUriDataProvider
  */
 public function testBuildCategoryUri($category, $expectedUri)
 {
     $pc = new MockPieCrust();
     $pc->getConfig()->setValue('blog/category_url', '/%category%');
     $uri = UriBuilder::buildCategoryUri($pc, 'blog', $category);
     $this->assertEquals($expectedUri, $uri);
 }
示例#2
0
 private function getApp($supportedFormats)
 {
     $app = new MockPieCrust();
     $app->getConfig()->set(array('site' => array('default_format' => 'doesnt_exist')));
     $loader = $app->getPluginLoader();
     $loader->formatters[] = new MockFormatter($supportedFormats);
     return $app;
 }
示例#3
0
 /**
  * @dataProvider getOutputPathDataProvider
  */
 public function testGetOutputPath($uri, $pageNumber, $prettyUrls, $expectedPath)
 {
     $app = new MockPieCrust();
     $page = new MockPage($app);
     $page->uri = $uri;
     $page->pageNumber = $pageNumber;
     if ($prettyUrls) {
         $app->getConfig()->setValue('site/pretty_urls', true);
     }
     $baker = new PageBaker($app, '/tmp');
     $path = $baker->getOutputPath($page);
     $expectedPath = '/tmp/' . $expectedPath;
     $this->assertEquals($expectedPath, $path);
 }
 /**
  * @dataProvider parsePageContentsDataProvider
  */
 public function testParsePageContents($testFilename, $expectedResultsFilename)
 {
     $fs = MockFileSystem::create()->withPagesDir();
     // Create the page that will load our test file.
     $pc = new MockPieCrust();
     $pc->setPagesDir($fs->url('kitchen/_content/pages/'));
     $pc->getConfig()->set(array('site' => array('root' => 'http://whatever/', 'pretty_urls' => false, 'default_format' => 'none', 'default_template_engine' => 'none')));
     // Default template engines.
     $pc->addTemplateEngine('mustache', 'MustacheTemplateEngine');
     $pc->addTemplateEngine('twig', 'TwigTemplateEngine');
     // Get the stuff we are expecting.
     $expectedResults = Yaml::parse(file_get_contents($expectedResultsFilename));
     // Add needed template engines/formatters.
     if (isset($expectedResults['needs'])) {
         $needs = $expectedResults['needs'];
         if (isset($needs['formatter'])) {
             foreach ($needs['formatter'] as $name => $f) {
                 $pc->addFormatter($name, $f);
             }
         }
         if (isset($needs['template_engine'])) {
             foreach ($needs['template_engine'] as $name => $te) {
                 $pc->addTemplateEngine($name, $te);
             }
         }
         unset($expectedResults['needs']);
     }
     // Build a test page and get the full expected config.
     $p = new Page($pc, '/test', $testFilename);
     $expectedConfig = PageConfiguration::getValidatedConfig($p, $expectedResults['config']);
     unset($expectedResults['config']);
     foreach ($expectedResults as $key => $content) {
         $expectedConfig['segments'][] = $key;
     }
     // Start asserting!
     $actualConfig = $p->getConfig()->get();
     $this->assertEquals($expectedConfig, $actualConfig, 'The configurations are not equivalent.');
     $actualSegments = $p->getContentSegments();
     foreach ($expectedResults as $key => $content) {
         $this->assertContains($key, $actualConfig['segments'], 'Expected a declared content segment named: ' . $key);
         $this->assertArrayHasKey($key, $actualSegments, 'Expected a content segment named: ' . $key);
         $this->assertEquals($content, $actualSegments[$key], 'The content segments are not equivalent.');
     }
 }
示例#5
0
 public function getMockApp()
 {
     $app = new MockPieCrust($this->getAppRoot() . '/');
     $app->getPluginLoader()->fileSystems = array(new \PieCrust\IO\FlatFileSystem(), new \PieCrust\IO\ShallowFileSystem(), new \PieCrust\IO\HierarchicalFileSystem());
     return $app;
 }
示例#6
0
 /**
  * @dataProvider previousAndNextPostsDataProvider
  */
 public function testPreviousAndNextPosts($postCount, $currentPostIndex)
 {
     $pc = new MockPieCrust();
     $pc->getConfig()->setValue('blog/posts_per_page', 5);
     $pc->getConfig()->setValue('blog/date_format', 'F j, Y');
     $posts = $this->buildPaginationDataSource($pc, $postCount);
     // The pagination data source is ordered in reverse
     // chronological order. Let's reverse it to be able
     // to index next/current/previous posts easily.
     // (the Paginator will reorder them internally)
     $posts = array_reverse($posts);
     $page = $posts[$currentPostIndex];
     $paginator = new Paginator($page);
     $paginator->setPaginationDataSource($posts);
     $nextPost = $paginator->next_post();
     $prevPost = $paginator->prev_post();
     if ($currentPostIndex > 0) {
         $this->assertEquals($posts[$currentPostIndex - 1]->getUri(), $prevPost['slug']);
     } else {
         $this->assertNull($prevPost);
     }
     if ($currentPostIndex < $postCount - 1) {
         $this->assertEquals($posts[$currentPostIndex + 1]->getUri(), $nextPost['slug']);
     } else {
         $this->assertNull($nextPost);
     }
 }
示例#7
0
 public function testChainedProcessors()
 {
     $fs = MockFileSystem::create(false)->withFile('something.foo', 'Some contents.')->withDir('_cache')->withDir('_counter');
     $pc = new MockPieCrust();
     $pc->rootDir = $fs->url('');
     $pc->cacheDir = $fs->url('_cache/');
     $pc->isCachingEnabled = true;
     $pc->getPluginLoader()->processors[] = new MockProcessor('uppercase', 'foo', function ($c) {
         return strtoupper($c);
     }, IProcessor::PRIORITY_HIGH);
     $pc->getPluginLoader()->processors[] = new MockProcessor('prefix', 'html', function ($c) {
         return 'prefixed: ' . $c;
     });
     $pc->getPluginLoader()->processors[] = new MockProcessor('wraptag', array('foo' => 'html'), function ($c) {
         return "<b>{$c}</b>";
     });
     $pc->getPluginLoader()->processors[] = new CopyFileProcessor();
     $bakeDir = $fs->url('_counter');
     $parameters = array('processors' => array('*'));
     $baker = new DirectoryBaker($pc, $bakeDir, $parameters);
     $outFile = $fs->url('_counter/something.html');
     $this->assertFalse(is_file($outFile));
     $baker->bake();
     $this->assertTrue(is_file($outFile));
     $this->assertEquals('prefixed: <b>SOME CONTENTS.</b>', file_get_contents($outFile));
 }
示例#8
0
 public function testGetPageFiles()
 {
     $fs = MockFileSystem::create()->withPage('test1')->withPage('testxml.xml')->withPage('foo/test2')->withPage('foo/testtxt.txt')->withPage('foo/bar/test3')->withPage('foo/test-stuff')->withPage('bar/blah')->withPage('_tag')->withPage('_category')->withPage('otherblog/_tag')->withPage('otherblog/_category')->withPageAsset('bar/blah', 'something.txt')->withAsset('_content/pages/.whatever', 'fake')->withAsset('_content/pages/.DS_Store', 'fake')->withAsset('_content/pages/.svn/blah', 'fake')->withAsset('_content/pages/Thumbs.db', 'fake')->withAsset('_content/pages/foo/.DS_Store', 'fake')->withAsset('_content/pages/foo/Thumbs.db', 'fake')->withAsset('_content/pages/foo/test-stuff.html~', 'fake')->withAsset('_content/pages/foo/.svn/blah', 'fake');
     $pc = new MockPieCrust();
     $pc->setPagesDir($fs->url('kitchen/_content/pages'));
     $pc->getConfig()->setValue('site/posts_fs', 'flat');
     $pc->getPluginLoader()->fileSystems = array(new \PieCrust\IO\FlatFileSystem(), new \PieCrust\IO\ShallowFileSystem(), new \PieCrust\IO\HierarchicalFileSystem());
     $pcFs = FileSystemFactory::create($pc);
     $pageFiles = $pcFs->getPageFiles();
     foreach ($pageFiles as &$pf) {
         // Fix slash/backslash problems on Windows that make
         // the test fail (PHP won't care about it so it's
         // functionally the same AFAIK).
         $pf->path = str_replace('\\', '/', $pf->path);
         $pf->relativePath = str_replace('\\', '/', $pf->relativePath);
     }
     $rootDir = $fs->url('kitchen/_content/pages');
     $expected = array(new PageInfo($rootDir, $fs->url('kitchen/_content/pages/test1.html')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/testxml.xml')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/foo/test2.html')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/foo/testtxt.txt')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/foo/bar/test3.html')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/foo/test-stuff.html')), new PageInfo($rootDir, $fs->url('kitchen/_content/pages/bar/blah.html')));
     $this->assertEquals($expected, $pageFiles);
 }
 public function testGetPageFiles()
 {
     $fs = MockFileSystem::create()->withPage('test1')->withPage('testxml.xml')->withPage('foo/test2')->withPage('foo/testtxt.txt')->withPage('foo/bar/test3')->withPage('foo/test-stuff')->withPage('bar/blah')->withPage('_tag')->withPage('_category')->withPage('otherblog/_tag')->withPage('otherblog/_category')->withPageAsset('bar/blah', 'something.txt')->withAsset('_content/pages/.whatever', 'fake')->withAsset('_content/pages/.DS_Store', 'fake')->withAsset('_content/pages/.svn/blah', 'fake')->withAsset('_content/pages/Thumbs.db', 'fake')->withAsset('_content/pages/foo/.DS_Store', 'fake')->withAsset('_content/pages/foo/Thumbs.db', 'fake')->withAsset('_content/pages/foo/.svn/blah', 'fake');
     $pc = new MockPieCrust();
     $pc->setPagesDir($fs->url('kitchen/_content/pages'));
     $pc->getConfig()->setValue('site/posts_fs', 'flat');
     $pcFs = FileSystem::create($pc);
     $pageFiles = $pcFs->getPageFiles();
     foreach ($pageFiles as &$pf) {
         // Fix slash/backslash problems on Windows that make
         // the test fail (PHP won't care about it so it's
         // functionally the same AFAIK).
         $pf['path'] = str_replace('\\', '/', $pf['path']);
         $pf['relative_path'] = str_replace('\\', '/', $pf['relative_path']);
     }
     $expected = array(array('path' => $fs->url('kitchen/_content/pages/test1.html'), 'relative_path' => 'test1.html'), array('path' => $fs->url('kitchen/_content/pages/testxml.xml'), 'relative_path' => 'testxml.xml'), array('path' => $fs->url('kitchen/_content/pages/foo/test2.html'), 'relative_path' => 'foo/test2.html'), array('path' => $fs->url('kitchen/_content/pages/foo/testtxt.txt'), 'relative_path' => 'foo/testtxt.txt'), array('path' => $fs->url('kitchen/_content/pages/foo/bar/test3.html'), 'relative_path' => 'foo/bar/test3.html'), array('path' => $fs->url('kitchen/_content/pages/foo/test-stuff.html'), 'relative_path' => 'foo/test-stuff.html'), array('path' => $fs->url('kitchen/_content/pages/bar/blah.html'), 'relative_path' => 'bar/blah.html'));
     $this->assertEquals($expected, $pageFiles);
 }