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);
 }
Exemple #2
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 run(ChefContext $context)
 {
     $pieCrust = $context->getApp();
     $result = $context->getResult();
     $outputDir = $result->command->options['output'];
     // Warn about deprecated stuff.
     if ($result->command->options['file_urls']) {
         $context->getLog()->warning("The `--fileurls` option has been deprecated. Please use `--portable` instead.");
         $result->command->options['portable_urls'] = true;
     }
     if ($result->command->options['pretty_urls_old']) {
         $context->getLog()->err("The `--prettyurls` option has been deprecated. Please use a config variant instead.");
         return;
     }
     if ($result->command->options['root_url_old']) {
         $context->getLog()->err("The `--rooturl` option has been deprecated. Please use a config variant instead.");
         return;
     }
     // Set-up the app and the baker.
     $bakerParameters = array('smart' => !$result->command->options['force'], 'clean_cache' => $result->command->options['force'], 'info_only' => $result->command->options['info_only'], 'config_variant' => $result->command->options['config_variant']);
     $baker = new PieCrustBaker($pieCrust, $bakerParameters, $context->getLog());
     if ($outputDir) {
         $baker->setBakeDir($outputDir);
     }
     if ($result->command->options['portable_urls']) {
         $pieCrust->getConfig()->setValue('baker/portable_urls', true);
         // Also disable pretty URLs because it doesn't make much sense
         // when there's no web server handling default documents.
         $pieCrust->getConfig()->setValue('site/pretty_urls', false);
     }
     // Start baking!
     $baker->bake();
 }
 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')));
 }
Exemple #5
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')));
    }
 /**
  * @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);
 }
Exemple #7
0
 public function run(ChefContext $context)
 {
     $pieCrust = $context->getApp();
     $result = $context->getResult();
     // Set-up the app and the baker.
     $bakerParameters = array('smart' => !$result->command->options['force'], 'clean_cache' => $result->command->options['force'], 'config_variant' => $result->command->options['config_variant']);
     if ($result->command->options['output']) {
         $bakerParameters['output'] = $result->command->options['output'];
     }
     $baker = new PieCrustBaker($pieCrust, $bakerParameters);
     if ($result->command->options['portable_urls']) {
         $pieCrust->getConfig()->setValue('baker/portable_urls', true);
         // Also disable pretty URLs because it doesn't make much sense
         // when there's no web server handling default documents.
         $pieCrust->getConfig()->setValue('site/pretty_urls', false);
     }
     // Start baking!
     $baker->bake();
 }
Exemple #8
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 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')));
    }
    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 #11
0
 protected function triggerBakeEvent($eventName, $func)
 {
     foreach ($this->getProcessors() as $proc) {
         $start = microtime(true);
         $func($proc);
         $end = microtime(true);
         $elapsed = ($end - $start) * 1000.0;
         if ($elapsed > 5) {
             $message = "[{$eventName} for {$proc->getName()}]";
             $this->logger->info(PieCrustBaker::formatTimed($start, $message));
         }
     }
 }
 protected function bakeFile($path, $rootDir, $rootDirLength)
 {
     // Start timing this.
     $start = microtime(true);
     // Figure out the root-relative path.
     $relative = substr($path, $rootDirLength);
     // Figure out if a previously baked file has overridden this one.
     // This can happen for example when a theme's file (baked via a
     // special mount point) is overridden in the user's website (baked
     // via the first normal root directory).
     $isOverridden = false;
     foreach ($this->bakedFiles as $bakedFile) {
         if ($bakedFile['relative_input'] == $relative) {
             $isOverridden = true;
         }
     }
     if ($isOverridden) {
         $this->bakedFiles[$path] = array('relative_input' => $relative, 'was_baked' => false, 'was_overridden' => true);
         $this->logger->info(PieCrustBaker::formatTimed($start, $relative) . ' [not baked, overridden]');
         return;
     }
     // Get the processing tree for that file.
     $builder = new ProcessingTreeBuilder($rootDir, $this->tmpDir, $this->bakeDir, $this->getProcessors());
     $treeRoot = $builder->build($relative);
     // Add an entry in the baked files' metadata.
     $bakeDir = $this->bakeDir;
     $treeLeaves = $treeRoot->getLeaves();
     $this->bakedFiles[$path] = array('relative_input' => $relative, 'relative_outputs' => array_map(function ($n) {
         return $n->getPath();
     }, $treeLeaves), 'outputs' => array_map(function ($n) use($bakeDir) {
         return $bakeDir . $n->getPath();
     }, $treeLeaves), 'was_baked' => false, 'was_overridden' => false);
     // See if we should force bake the file.
     $forceBake = !$this->parameters['smart'];
     if (!$forceBake) {
         foreach ($this->parameters['force_patterns'] as $p) {
             if (preg_match($p, $relative)) {
                 $forceBake = true;
                 break;
             }
         }
     }
     if ($forceBake) {
         $treeRoot->setState(ProcessingTreeNode::STATE_DIRTY, true);
     }
     // Bake!
     $runner = new ProcessingTreeRunner($rootDir, $this->tmpDir, $this->bakeDir, $this->logger);
     if ($runner->bakeSubTree($treeRoot)) {
         $this->bakedFiles[$path]['was_baked'] = true;
         $this->logger->info(PieCrustBaker::formatTimed($start, $relative));
     }
 }