/**
  * @dataProvider getPostPathInfoDataProvider
  */
 public function testGetPostPathInfo($fsType, $wildcardComponent)
 {
     $pc = new MockPieCrust();
     $pc->setPostsDir(PIECRUST_UNITTESTS_TEST_DATA_DIR . 'posts/' . $fsType . '/');
     $pc->getConfig()->setValue('site/posts_fs', $fsType);
     $fs = FileSystem::create($pc);
     $postFiles = $fs->getPostFiles();
     $this->assertNotNull($postFiles);
     $this->assertEquals(6, count($postFiles));
     $years = array('2009', '2010', '2010', '2011', '2011', '2011');
     $months = array('05', '01', '11', '09', '09', '09');
     $days = array('16', '08', '02', '23', '24', '24');
     $slugs = array('first-post', 'second-post', 'third-post', 'fourth-post', 'a-sixth-post', 'b-fifth-post');
     for ($i = 0; $i < 6; ++$i) {
         $groups = array('year' => $years[$i], 'month' => $months[$i], 'day' => $days[$i], 'slug' => $slugs[$i]);
         if ($wildcardComponent != null) {
             unset($groups[$wildcardComponent]);
         }
         $pathInfo = $fs->getPostPathInfo($groups);
         $this->assertEquals($years[$i], $pathInfo['year']);
         $this->assertEquals($months[$i], $pathInfo['month']);
         $this->assertEquals($days[$i], $pathInfo['day']);
         $this->assertEquals($slugs[$i], $pathInfo['slug']);
         $this->assertEquals(str_replace('\\', '/', $postFiles[5 - $i]['path']), str_replace('\\', '/', $pathInfo['path']));
     }
 }
示例#2
0
 public function testIgnoreFile()
 {
     $fs = MockFileSystem::create()->withAsset('_content/posts/no-date.html', '')->withAsset('_content/posts/2013-01-12_foo-bar.html', '');
     $pc = new MockPieCrust();
     $pc->setPostsDir($fs->url('kitchen/_content/posts'));
     $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);
     $postFiles = $pcFs->getPostFiles('blog');
     foreach ($postFiles as &$pf) {
         // Fix backslashes when running tests on Windows.
         $pf->path = str_replace('\\', '/', $pf->path);
     }
     $this->assertEquals(array(PostInfo::fromStrings('2013', '01', '12', 'foo-bar', 'html', $fs->url('kitchen/_content/posts/2013-01-12_foo-bar.html'))), $postFiles);
 }