Пример #1
0
 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());
 }
Пример #2
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());
 }
Пример #3
0
 /**
  * @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 runQuery($pieCrust, $uri, $cleanCache = false)
 {
     if ($cleanCache) {
         ensure_cache(PIECRUST_BENCHMARKS_CACHE_DIR, true);
     }
     $page = Page::createFromUri($pieCrust, $uri);
     $renderer = new PageRenderer($page);
     return $renderer->get();
 }
Пример #5
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']);
 }
Пример #6
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 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']);
    }
Пример #8
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)));
 }
Пример #9
0
    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);
    }
Пример #10
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);
    }
Пример #11
0
 /**
  * Runs PieCrust on the given URI with the given extra page rendering data,
  * but without any error handling.
  */
 public function runUnsafe($uri = null, array $server = null, $extraPageData = null, array &$headers = null)
 {
     // Create an execution context.
     $executionContext = $this->pieCrust->getEnvironment()->getExecutionContext(true);
     // Check the cache validity, and clean it automatically.
     if ($this->pieCrust->isCachingEnabled()) {
         $cacheInfo = new PieCrustCacheInfo($this->pieCrust);
         $cacheValidity = $cacheInfo->getValidity(true);
         $executionContext->isCacheValid = $cacheValidity['is_valid'];
         $executionContext->wasCacheCleaned = $cacheValidity['was_cleaned'];
     }
     // Get the resource URI and corresponding physical path.
     if ($server == null) {
         $server = $_SERVER;
     }
     if ($uri == null) {
         $uri = ServerHelper::getRequestUri($server, $this->pieCrust->getConfig()->getValueUnchecked('site/pretty_urls'));
     }
     // Do the heavy lifting.
     $page = Page::createFromUri($this->pieCrust, $uri);
     $executionContext->pushPage($page);
     if ($extraPageData != null) {
         $page->setExtraPageData($extraPageData);
     }
     $pageRenderer = new PageRenderer($page);
     $output = $pageRenderer->get();
     // Set or return the HTML headers.
     HttpHeaderHelper::setOrAddHeaders(PageRenderer::getHeaders($page->getConfig()->getValue('content_type'), $server), $headers);
     // Handle caching.
     if (!$this->pieCrust->isDebuggingEnabled()) {
         $hash = md5($output);
         HttpHeaderHelper::setOrAddHeader('Etag', '"' . $hash . '"', $headers);
         $clientHash = null;
         if (isset($server['HTTP_IF_NONE_MATCH'])) {
             $clientHash = $server['HTTP_IF_NONE_MATCH'];
         }
         if ($clientHash != null) {
             $clientHash = trim($clientHash, '"');
             if ($hash == $clientHash) {
                 HttpHeaderHelper::setOrAddHeader(0, 304, $headers);
                 HttpHeaderHelper::setOrAddHeader('Content-Length', '0', $headers);
                 return;
             }
         }
     }
     if ($this->pieCrust->isDebuggingEnabled()) {
         HttpHeaderHelper::setOrAddHeader('Cache-Control', 'no-cache, must-revalidate', $headers);
     } else {
         $cacheTime = PageHelper::getConfigValue($page, 'cache_time', 'site');
         if ($cacheTime) {
             HttpHeaderHelper::setOrAddHeader('Cache-Control', 'public, max-age=' . $cacheTime, $headers);
         }
     }
     // Output with or without GZip compression.
     $gzipEnabled = ($this->pieCrust->getConfig()->getValueUnchecked('site/enable_gzip') === true and array_key_exists('HTTP_ACCEPT_ENCODING', $server) and strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip') !== false);
     if ($gzipEnabled) {
         $zippedOutput = gzencode($output);
         if ($zippedOutput === false) {
             HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($output), $headers);
             echo $output;
         } else {
             HttpHeaderHelper::setOrAddHeader('Content-Encoding', 'gzip', $headers);
             HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($zippedOutput), $headers);
             echo $zippedOutput;
         }
     } else {
         HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($output), $headers);
         echo $output;
     }
 }
Пример #12
0
 public function testSiteWithPageAssets()
 {
     $fs = MockFileSystem::create()->withPage('foo', array(), '')->withPageAsset('foo', 'bar1')->withPageAsset('foo', 'bar2')->withPage('something-assets', array(), '');
     $pc = $fs->getApp();
     $page = Page::createFromUri($pc, '/foo', false);
     $data = DataBuilder::getSiteData($page);
     $linker = $data['site']->pages();
     $this->assertLinkerIsPagesArray($linker, array($this->makeLinkData('foo', '/?/foo', true), $this->makeLinkData('something-assets', '/?/something-assets')));
     $page = Page::createFromUri($pc, '/something-assets', false);
     $data = DataBuilder::getSiteData($page);
     $linker = $data['site']->pages();
     $this->assertLinkerIsPagesArray($linker, array($this->makeLinkData('foo', '/?/foo'), $this->makeLinkData('something-assets', '/?/something-assets', true)));
 }
Пример #13
0
    public function testSortDateWithPostsOnSameDay()
    {
        $fs = MockFileSystem::create()->withConfig(array('site' => array('post_url' => '%slug%', 'default_format' => 'none', 'posts_per_page' => 10)))->withPost('post1', 31, 12, 2013, array('time' => '15:07:05'))->withPost('post2', 31, 12, 2013, array('time' => '15:17:30'))->withPost('post3', 31, 12, 2013, array('time' => '20:03:42'))->withPost('post4', 1, 1, 2014, array('time' => '14:07:07'))->withPost('post5', 1, 1, 2014, array('time' => '14:08:09'))->withPost('post6', 1, 1, 2014, array('time' => '14:09:11'))->withPost('post7', 1, 1, 2014, array('time' => '14:10:13'))->withPost('post8', 1, 1, 2014, array('time' => '14:11:14'))->withPage('/foos', array('format' => 'none'), <<<EOD
{% for p in pagination.posts %}
{{p.slug}}
{% endfor %}
EOD
);
        $pc = $fs->getApp();
        $page = Page::createFromUri($pc, '/foos', false);
        $this->assertEquals(<<<EOD
post8
post7
post6
post5
post4
post3
post2
post1

EOD
, $page->getContentSegment());
    }