Exemple #1
0
    public function testUrlInTemplateWithMultipleBlogs()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('blogs' => array('one', 'two')), 'two' => array('tag_url' => 'tagged/%tag%')))->withTemplate('default', "{{content|raw}}\nTPL:{{pctagurl('foo')}}")->withTemplate('post', "{{content|raw}}\nTPL:{{pctagurl('bar')}}")->withPage('normal', array('format' => 'none'), <<<'EOD'
{% for post in one.posts %}
{{post.content|raw}}
{% endfor %}
{% for post in two.posts %}
{{post.content|raw}}
{% endfor %}
EOD
)->withPage('second', array('format' => 'none', 'blog' => 'two'), <<<'EOD'
{% for post in one.posts %}
{{post.content|raw}}
{% endfor %}
{% for post in two.posts %}
{{post.content|raw}}
{% endfor %}
EOD
)->withPost('post1', 1, 1, 2012, array('format' => 'none'), "POST ONE {{pctagurl('foo')}}", 'one')->withPost('post2', 1, 1, 2012, array('format' => 'none'), "POST TWO {{pctagurl('bar')}}", 'two');
        $app = $fs->getApp();
        $baker = new PieCrustBaker($app);
        $baker->bake();
        $this->assertEquals("POST ONE /one/tag/foo.html\nPOST TWO /tagged/bar.html\n\nTPL:/one/tag/foo.html", file_get_contents($fs->url('kitchen/_counter/normal.html')));
        $this->assertEquals("POST ONE /one/tag/foo.html\nPOST TWO /tagged/bar.html\n\nTPL:/tagged/foo.html", file_get_contents($fs->url('kitchen/_counter/second.html')));
        $this->assertEquals("POST ONE /one/tag/foo.html\nTPL:/one/tag/bar.html", file_get_contents($fs->url('kitchen/_counter/one/2012/01/01/post1.html')));
        $this->assertEquals("POST TWO /tagged/bar.html\nTPL:/tagged/bar.html", file_get_contents($fs->url('kitchen/_counter/two/2012/01/01/post2.html')));
    }
 public function testCreateDefaultCategoryPage()
 {
     $app = MockFileSystem::create()->withConfig(array('site' => array('category_url' => 'cat/%category%')))->getApp();
     $page = Page::createFromUri($app, '/cat/foo');
     $expected = PathHelper::getUserOrThemeOrResPath($app, '_category.html');
     $this->assertEquals($expected, $page->getPath());
 }
 public function testBakerAssistant()
 {
     $fs = MockFileSystem::create();
     $fs->withPage('foo', array('layout' => 'none'), 'Something');
     $fs->withPage('bar', array('layout' => 'none'), 'Whatever');
     $fs->withPostsDir();
     $app = $fs->getMockApp();
     $app->getConfig()->setValue('site/default_template_engine', 'none');
     $app->getConfig()->setValue('site/default_format', 'none');
     $testAssistant = new TestBakerAssistant('test1');
     $app->pluginLoader->bakerAssistants = array($testAssistant);
     $baker = new PieCrustBaker($app);
     sleep(1);
     $baker->bake();
     $this->assertTrue(is_file($fs->url('kitchen/_counter/foo.html')));
     $this->assertTrue(is_file($fs->url('kitchen/_counter/bar.html')));
     $this->assertEquals(2, $testAssistant->pagesBaked);
     $this->assertEquals(0, $testAssistant->pagesSkipped);
     $testAssistant->pagesBaked = 0;
     $testAssistant->pagesSkipped = 0;
     clearstatcache();
     sleep(1);
     $baker->bake();
     $this->assertEquals(0, $testAssistant->pagesBaked);
     $this->assertEquals(2, $testAssistant->pagesSkipped);
 }
 public function testParseRegularOnlyUriThatDoesntExist()
 {
     $fs = MockFileSystem::create()->withPage('existing-page');
     $pc = new PieCrust(array('root' => $fs->getAppRoot(), 'cache' => false));
     $uriInfo = UriParser::parseUri($pc, '/non-existing-page', UriParser::PAGE_URI_REGULAR);
     $this->assertNull($uriInfo);
 }
Exemple #5
0
 public function testCategoryPages()
 {
     $app = MockFileSystem::create()->withConfig(array('site' => array('default_format' => 'none')))->withPost('test1', 1, 1, 2012, array('category' => 'cat one'), 'Test one')->withPost('test2', 1, 2, 2012, array('category' => 'foo'), 'Test two')->withPost('test3', 1, 3, 2012, array('category' => 'foo'), 'Test three')->withPost('test4', 1, 4, 2012, array('category' => 'cat one'), 'Test four')->withPost('test5', 1, 5, 2012, array('category' => 'cat one'), 'Test five')->withPage('_category', array('layout' => 'none'), "{{category}}\n{% for p in pagination.posts %}\n{{p.content|raw}}\n{% endfor %}")->getApp();
     $page = Page::createFromUri($app, '/foo');
     $this->assertEquals("foo\nTest three\nTest two\n", $page->getContentSegment());
     $page = Page::createFromUri($app, '/cat-one');
     $this->assertEquals("cat one\nTest five\nTest four\nTest one\n", $page->getContentSegment());
 }
 /**
  * @dataProvider formatUriDataProviderWhenBaked
  */
 public function testFormatUriWhenBaked($pageUri, $expectedUri, $siteRoot = '/', $prettyUrls = true, $debug = false, $trailingSlash = false)
 {
     $fs = MockFileSystem::create();
     $fs->withConfig(array('site' => array('root' => $siteRoot, 'pretty_urls' => $prettyUrls), 'baker' => array('is_baking' => true, 'trailing_slash' => $trailingSlash)));
     $pc = new PieCrust(array('root' => $fs->getAppRoot(), 'cache' => false, 'debug' => $debug));
     $uri = PieCrustHelper::formatUri($pc, $pageUri);
     $this->assertEquals($expectedUri, $uri);
 }
 /**
  * @expectedException \PieCrust\PieCrustException
  */
 public function testSeveralAssetsWithSameFilename()
 {
     $fs = MockFileSystem::create()->withPage('foo/bar')->withPageAsset('foo/bar', 'one.txt', 'one')->withPageAsset('foo/bar', 'one.xml', 'another one');
     $pc = new PieCrust(array('root' => $fs->getAppRoot()));
     $page = Page::createFromUri($pc, 'foo/bar', false);
     $assetor = new Assetor($page);
     $tmp = $assetor['one'];
 }
 public function testOverrideTemplate()
 {
     $fs = MockFileSystem::create()->withConfig(array('site' => array('templates_dirs' => '_content/override')))->withPage('blah', array('layout' => 'default', 'format' => 'none'), 'Blah blah blah.')->withTemplate('default', 'DEFAULT TEMPLATE: {{content}}')->withCustomTemplate('default', 'override', 'OVERRIDE TEMPLATE: {{content}}');
     $pc = $fs->getApp();
     $baker = new PieCrustBaker($pc);
     $baker->bake();
     $this->assertFileExists($fs->url('kitchen/_counter/blah.html'));
     $this->assertEquals('OVERRIDE TEMPLATE: Blah blah blah.', file_get_contents($fs->url('kitchen/_counter/blah.html')));
 }
 public function testGetSimpleSitePages()
 {
     $fs = MockFileSystem::create()->withPage('_index', array(), 'Blah.');
     $app = $fs->getApp();
     $pages = $app->getEnvironment()->getPages();
     $this->assertEquals(1, count($pages));
     $this->assertEquals('_index.html', PageHelper::getRelativePath($pages[0]));
     $this->assertEquals(str_replace('\\', '/', $fs->url('kitchen/_content/pages/_index.html')), str_replace('\\', '/', $pages[0]->getPath()));
 }
Exemple #10
0
 /**
  * @dataProvider tagSlugifyDataProvider
  */
 public function testTagSlugify($value, $expectedValue, $slugifyMode = null, $locale = null)
 {
     $fs = MockFileSystem::create();
     if ($slugifyMode) {
         $fs->withConfig(array('site' => array('slugify' => $slugifyMode)));
     }
     $pc = $fs->getApp();
     $flags = $pc->getConfig()->getValue('site/slugify_flags');
     $actualValue = UriBuilder::slugify($value, $flags);
     $this->assertEquals($expectedValue, $actualValue);
 }
Exemple #11
0
 public function testSmartyPantsFormatter()
 {
     $fs = MockFileSystem::create()->withConfig(array('smartypants' => array('enabled' => true)));
     $app = $fs->getApp();
     $text = PieCrustHelper::formatText($app, 'Something...');
     $this->assertEquals("<p>Something&#8230;</p>\n", $text);
     // At the beginning you enabled SmartyPants with 'enable', and not 'enabled'.
     $fs = MockFileSystem::create()->withConfig(array('smartypants' => array('enable' => true)));
     $app = $fs->getApp();
     $text = PieCrustHelper::formatText($app, 'Something...');
     $this->assertEquals("<p>Something&#8230;</p>\n", $text);
 }
Exemple #12
0
 public function testPaginationData()
 {
     $fs = MockFileSystem::create()->withPage('blah', array('title' => "My Blah", 'foo' => "My Foo", 'format' => 'none'), 'Some contents.');
     $app = new PieCrust(array('root' => $fs->url('kitchen')));
     $page = Page::createFromUri($app, '/blah');
     $data = new PaginationData($page);
     $this->assertEquals('My Blah', $data['title']);
     $this->assertEquals('My Foo', $data['foo']);
     $this->assertEquals('/?/blah', $data['url']);
     $this->assertEquals('blah', $data['slug']);
     $this->assertEquals('Some contents.', $data['content']);
     $this->assertFalse($data['has_more']);
 }
Exemple #13
0
    public function testCompass()
    {
        $temp = array();
        $returnCode = 0;
        //TODO: this may output stuff to `stderr`...
        @exec('compass --help', $temp, $returnCode);
        if ($returnCode != 0) {
            $this->markTestIncomplete("Compass doesn't seem to be available. Skipping test.");
            return;
        }
        $fs = MockFileSystem::create(true, true)->withConfig(array('compass' => array('use_compass' => true)))->withTemplate('default', '{{content|raw}}')->withAsset('sass/theme.scss', <<<EOD
#navbar {
  width: 80%;
  height: 23px;

  ul { list-style-type: none; }
  li {
    float: left;
    a { font-weight: bold; }
  }
}
EOD
);
        @exec('compass init stand_alone "' . $fs->url('kitchen') . '"');
        $pc = $fs->getApp();
        $baker = new PieCrustBaker($pc);
        $baker->bake();
        $this->assertEquals(<<<EOD
/* line 1, ../sass/theme.scss */
#navbar {
  width: 80%;
  height: 23px;
}
/* line 5, ../sass/theme.scss */
#navbar ul {
  list-style-type: none;
}
/* line 6, ../sass/theme.scss */
#navbar li {
  float: left;
}
/* line 8, ../sass/theme.scss */
#navbar li a {
  font-weight: bold;
}

EOD
, file_get_contents($fs->url('kitchen/_counter/stylesheets/theme.css')));
    }
Exemple #14
0
    public function testGeshiWithClassesAndOverallId()
    {
        $fs = MockFileSystem::create()->withPage('/foo', array(), <<<EOD
{% geshi 'python' use_classes id='my-code' %}
foo = 42
{% endgeshi %}
EOD
);
        $pc = $fs->getApp();
        $page = Page::createFromUri($pc, '/foo', false);
        $this->assertEquals(<<<EOD
<pre class="python" id="my-code">foo <span class="sy0">=</span> <span class="nu0">42</span></pre>

EOD
, $page->getContentSegment());
    }
 public function testImportWordpress()
 {
     $fs = MockFileSystem::create()->withPagesDir()->withPostsDir();
     $app = new PieCrust(array('root' => $fs->getAppRoot()));
     $importer = new PieCrustImporter($app);
     $sampleXml = PIECRUST_UNITTESTS_TEST_DATA_DIR . 'import/wordpress.test-data.2011-01-17.xml';
     $importer->import('wordpress', $sampleXml, array());
     // Re-create the app to load from the new values.
     $app = new PieCrust(array('root' => $fs->getAppRoot()));
     // Check the content.
     $pcFs = FileSystem::create($app);
     $pageFiles = $pcFs->getPageFiles();
     $this->assertCount(11, $pageFiles);
     $postFiles = $pcFs->getPostFiles();
     $this->assertCount(22, $postFiles);
 }
Exemple #16
0
 /**
  * @dataProvider findDataProvider
  */
 public function testFind($what, $expected)
 {
     $fs = MockFileSystem::create()->withPost('first', 2, 6, 2012, array(), '')->withPost('second', 3, 6, 2012, array('time' => '13:53:44'), '')->withPost('third', 4, 6, 2012, array(), '')->withPost('third-same-day', 4, 6, 2012, array(), '')->withPost('some-foo', 5, 6, 2012, array(), '')->withPage('foo', array(), '')->withPage('foo/something', array(), '')->withPage('foo/otherwise', array(), '')->withPage('bar', array(), '')->withPage('bar/foo', array(), '')->withTemplate('default', '')->withTemplate('post', '')->withTemplate('foos', '');
     $logFile = $fs->url('tmp/log');
     if (!is_array($what)) {
         $what = array($what);
     }
     // VFS behaves differently than the real one. Create an
     // empty file to not upset PHP...
     mkdir(dirname($logFile), 0777, true);
     file_put_contents($logFile, '');
     $args = array_merge(array('--log', $logFile, 'find'), $what);
     $this->runChef($fs, $args);
     $actual = file_get_contents($logFile);
     $actual = $this->stripLog($actual);
     $this->assertEquals($expected, $actual);
 }
 /**
  * @dataProvider dataProviderDataProvider
  */
 public function testDataProviderInTemplate($endPoint, $value, $accessor, $accessedValue)
 {
     $fs = MockFileSystem::create();
     $fs->withPage('foo', array('layout' => 'special', 'format' => 'none'), 'stuff');
     $fs->withTemplate('special', "Something: {{" . $accessor . "}} {{content|raw}}");
     $fs->withPostsDir();
     $app = $fs->getMockApp();
     $app->addTemplateEngine('twig', 'TwigTemplateEngine');
     $testProvider = new TestDataProvider($endPoint, $value);
     $app->pluginLoader->dataProviders = array($testProvider);
     $baker = new PieCrustBaker($app);
     $baker->bake();
     $path = $fs->url('kitchen/_counter/foo.html');
     $actual = file_get_contents($path);
     $expected = 'Something: ' . $accessedValue . ' stuff';
     $this->assertEquals($expected, $actual);
 }
 /**
  * @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.');
     }
 }
Exemple #19
0
 /**
  * @dataProvider parseAutoFormatUrisDataProvider
  */
 public function testParseAutoFormatUris($config, $uri, $expectedUriInfo)
 {
     if (!isset($config['site'])) {
         $config['site'] = array();
     }
     $config['site']['category_url'] = 'cat/%category%';
     $config['site']['auto_formats'] = array('md' => 'markdown', 'text' => 'textile');
     // We have to use a "real" mock FS (i.e. it will use real files instead
     // of vfsStream) because that's the place in the PieCrust code where we
     // need to use `glob()`, which isn't supported with virtual streams.
     $fs = MockFileSystem::create(true, true)->withConfig($config)->withPost('some-post', 3, 2, 2011, array(), 'Blah.', null, 'md')->withPost('other-post', 4, 2, 2011, array(), 'Blah.', null, 'text')->withPage('_index.md')->withPage('_category.md')->withPage('_tag.md')->withPage('textile/page.text')->withPage('markdown/page.md')->withPage('normal/page.html');
     $pc = $fs->getApp();
     $uriInfo = UriParser::parseUri($pc, $uri);
     if ($expectedUriInfo != null && isset($expectedUriInfo['path'])) {
         $pagesDir = $fs->url('kitchen/_content/pages/');
         $postsDir = $fs->url('kitchen/_content/posts/');
         $expectedUriInfo['path'] = str_replace(array('%pages_dir%', '%posts_dir%'), array($pagesDir, $postsDir), $expectedUriInfo['path']);
     }
     $this->assertEquals($expectedUriInfo, $uriInfo, 'The URI info was not what was expected.');
 }
 /**
  * @dataProvider templateDirectoriesWithTemeDataProvider
  */
 public function testTemplateDirectoriesWithTheme($config, $themeConfig, $expectedDirs)
 {
     if ($config != null) {
         $config = array('site' => array('templates_dirs' => $config));
     } else {
         $config = array();
     }
     if ($themeConfig != null) {
         $themeConfig = array('site' => array('templates_dirs' => $themeConfig));
     } else {
         $themeConfig = array();
     }
     $fs = MockFileSystem::create()->withTemplatesDir()->withConfig($config)->withThemeConfig($themeConfig);
     $app = $fs->getApp();
     foreach ($expectedDirs as &$dir) {
         $dir = $fs->url($dir);
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     }
     $this->assertEquals($expectedDirs, $app->getTemplatesDirs());
 }
Exemple #21
0
    /**
     * @dataProvider lessDataProvider
     */
    public function testLess($usingJsTool)
    {
        $fs = MockFileSystem::create(true, true)->withTemplate('default', '{{content|raw}}')->withAsset('screen.less', <<<EOD
@red: #ff0000;
.foo {
    background: @red;
    .bar {
        border: 1px;
    }
}
EOD
);
        if ($usingJsTool) {
            // Mark test as incomplete if `lessc` is not availble in
            // the PATH.
            $temp = array();
            $returnCode = 0;
            //TODO: this may output stuff to `stderr`...
            @exec('lessc --help', $temp, $returnCode);
            if ($returnCode != 0) {
                $this->markTestIncomplete("`lessc` doesn't seem to be available. Skipping test.");
                return;
            }
            $fs->withConfig(array('less' => array('use_lessc' => true)));
        }
        $pc = $fs->getApp();
        $baker = new PieCrustBaker($pc);
        $baker->bake();
        $this->assertEquals(<<<EOD
.foo {
  background: #ff0000;
}
.foo .bar {
  border: 1px;
}

EOD
, file_get_contents($fs->url('kitchen/_counter/screen.css')));
    }
    public function testPageContents()
    {
        $content = <<<EOD
These are the contents.
They're quite awesome.
EOD;
        $summary = <<<EOD
This is the summary.
Yep.
EOD;
        $all = <<<EOD
{$content}
---summary---
{$summary}
EOD;
        $fs = MockFileSystem::create()->withPage('foo', array('format' => 'none'), $all);
        $pc = $fs->getApp();
        $page = Page::createFromUri($pc, '/foo', false);
        $data = new PaginationData($page);
        $this->assertTrue(isset($data['content']));
        $this->assertEquals($content . "\n", $data['content']);
        $this->assertTrue(isset($data['summary']));
        $this->assertEquals($summary, $data['summary']);
    }
Exemple #23
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)));
 }
 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);
 }
    public function testTagUrlFunctionsWithBlogData()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('root' => 'localhost', 'pretty_urls' => true, 'default_format' => 'none')))->withPost('post1', 1, 1, 2012, array('tags' => array('one')))->withPost('post2', 1, 2, 2012, array('tags' => array('one', 'two')))->withPost('post3', 1, 3, 2012, array('tags' => array('one')))->withPost('post4', 1, 4, 2012, array('tags' => array('two')))->withPage('test', array('layout' => 'none'), <<<EOD
{% for t in blog.tags %}
TAG: {{t}} / {{t.name}}
LINK: {{pctagurl(t)}}
{% for p in t.posts %}
* {{p.slug}}
{% endfor %}
{% endfor %}
EOD
);
        $app = $fs->getApp();
        $page = Page::createFromUri($app, '/test');
        $actual = $page->getContentSegment();
        $expected = <<<EOD
TAG: one / one
LINK: localhost/tag/one
* 2012/03/01/post3
* 2012/02/01/post2
* 2012/01/01/post1
TAG: two / two
LINK: localhost/tag/two
* 2012/04/01/post4
* 2012/02/01/post2

EOD;
        $this->assertEquals($expected, $actual);
    }
    public function testBakeCategoryPage()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('default_format' => 'none')))->withTemplate('post', '{{content|raw}}')->withPage('_category', array('layout' => 'none'), <<<EOD
{% for post in pagination.posts %}
{{ post.content|raw }}
{% endfor %}
EOD
)->withPost('post1', 1, 1, 2010, array('category' => 'foo'), 'POST ONE')->withPost('post2', 2, 1, 2010, array('category' => 'foo'), 'POST TWO')->withPost('post3', 3, 1, 2010, array('category' => 'bar'), 'POST THREE')->withPost('post4', 4, 1, 2010, array('category' => 'bar'), 'POST FOUR')->withPost('post5', 5, 1, 2010, array('category' => 'foo'), 'POST FIVE');
        $app = $fs->getApp();
        $baker = new PieCrustBaker($app);
        $baker->setBakeDir($fs->url('counter'));
        $baker->bake();
        $this->assertEquals("POST FIVE\nPOST TWO\nPOST ONE\n", file_get_contents($fs->url('counter/foo.html')));
        $this->assertEquals("POST FOUR\nPOST THREE\n", file_get_contents($fs->url('counter/bar.html')));
    }
Exemple #27
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 testThemeMountOverride()
 {
     $fs = MockFileSystem::create()->withAsset('normal-styles.css', ".rule { color: blue; }")->withAsset('extra-styles.css', ".override { color: white; }")->withAsset('_content/theme/_content/theme_config.yml', '')->withAsset('_content/theme/extra-styles.css', ".other { color: black; }");
     $app = $fs->getApp();
     $bakeDir = $fs->url('counter');
     $baker = new DirectoryBaker($app, $bakeDir);
     $baker->bake();
     $this->assertFileEquals($fs->url('kitchen/normal-styles.css'), $fs->url('counter/normal-styles.css'));
     $this->assertFileEquals($fs->url('kitchen/extra-styles.css'), $fs->url('counter/extra-styles.css'));
     $bakedFiles = $baker->getBakedFiles();
     $overriddenInfo = $bakedFiles[$fs->url('kitchen/_content/theme/extra-styles.css')];
     $this->assertFalse($overriddenInfo['was_baked']);
     $this->assertTrue($overriddenInfo['was_overridden']);
 }
    public function testPageDeletionByPagination()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('default_format' => 'none', 'posts_per_page' => 4)))->withTemplate('default', '{{content|raw}}')->withTemplate('post', '{{content|raw}}')->withPost('post1', 1, 1, 2010, array(), 'POST ONE')->withPost('post2', 5, 2, 2010, array(), 'POST TWO')->withPost('post3', 10, 3, 2010, array(), 'POST THREE')->withPost('post4', 1, 4, 2010, array(), 'POST FOUR')->withPost('post5', 5, 5, 2010, array(), 'POST FIVE')->withPost('post6', 10, 6, 2010, array(), 'POST SIX')->withPost('post7', 15, 7, 2010, array(), 'POST SEVEN')->withPost('post8', 1, 8, 2010, array(), 'POST EIGHT')->withPost('post9', 5, 9, 2010, array(), 'POST NINE')->withPost('post10', 1, 10, 2010, array(), 'POST TEN')->withPage('_index', array(), <<<EOD
{% for p in pagination.posts %}
{{ p.title }}
{% endfor %}
EOD
)->withPage('foo', array(), <<<EOD
{% for p in pagination.posts %}
{{ p.title }}
{% endfor %}
EOD
);
        $app = $fs->getApp();
        $baker = new PieCrustBaker($app);
        $baker->setBakeDir($fs->url('counter'));
        $baker->bake();
        $structure = $fs->getStructure();
        $counter = $structure[$fs->getRootName()]['counter'];
        $this->assertEquals(array('2010', 'index.html', '2.html', '3.html', 'foo.html', 'foo'), $this->getVfsEntries($counter));
        $this->assertEquals(array('2.html', '3.html'), array_keys($counter['foo']));
        $fs->withConfig(array('site' => array('default_format' => 'none', 'posts_per_page' => 11)));
        $app = $fs->getApp();
        $baker = new PieCrustBaker($app);
        $baker->setBakeDir($fs->url('counter'));
        $baker->bake();
        $structure = $fs->getStructure();
        $counter = $structure[$fs->getRootName()]['counter'];
        $this->assertEquals(array('2010', 'index.html', 'foo.html', 'foo'), $this->getVfsEntries($counter));
        $this->assertEquals(array(), array_keys($counter['foo']));
    }
Exemple #30
0
    public function testAssetsInPagination()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('default_format' => 'none')))->withPost('foo1', 1, 10, 2013, array('title' => 'Foo 1'))->withAsset('_content/posts/2013-10-01_foo1-assets/thumbnail.jpg', 'Thumb 1')->withPost('foo2', 2, 10, 2013, array('title' => 'Foo 2'))->withAsset('_content/posts/2013-10-02_foo2-assets/thumbnail.jpg', 'Thumb 2')->withPost('foo3', 3, 10, 2013, array('title' => 'Foo 3'))->withAsset('_content/posts/2013-10-03_foo3-assets/thumbnail.jpg', 'Thumb 3')->withPost('foo4', 4, 10, 2013, array('title' => 'Foo 4'))->withAsset('_content/posts/2013-10-04_foo4-assets/thumbnail.jpg', 'Thumb 4')->withPage('whatever', array(), <<<EOD
{% for p in pagination.posts %}
{{ p.title }}: {{ p.assets.thumbnail }}
{% endfor %}
EOD
);
        $app = $fs->getApp();
        $page = Page::createFromUri($app, '/whatever', false);
        $actual = $page->getContentSegment();
        $expected = <<<EOD
Foo 4: /_content/posts/2013-10-04_foo4-assets/thumbnail.jpg
Foo 3: /_content/posts/2013-10-03_foo3-assets/thumbnail.jpg
Foo 2: /_content/posts/2013-10-02_foo2-assets/thumbnail.jpg
Foo 1: /_content/posts/2013-10-01_foo1-assets/thumbnail.jpg

EOD;
        $this->assertEquals($expected, $actual);
    }