/**
  * @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.');
     }
 }
Пример #2
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);
 }
Пример #3
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/.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);
 }