Exemple #1
0
 /**
  * @dataProvider getPostPathInfoDataProvider
  */
 public function testGetPostPathInfo($fsType, $wildcardComponent)
 {
     $pc = new MockPieCrust();
     $pc->setPostsDir(PIECRUST_UNITTESTS_DATA_DIR . 'posts/' . $fsType . '/');
     $pc->getConfig()->setValue('site/posts_fs', $fsType);
     $pc->getPluginLoader()->fileSystems = array(new \PieCrust\IO\FlatFileSystem(), new \PieCrust\IO\ShallowFileSystem(), new \PieCrust\IO\HierarchicalFileSystem());
     $fs = FileSystemFactory::create($pc);
     $postFiles = $fs->getPostFiles('blog');
     $postFiles = MockFileSystem::sortPostInfos($postFiles);
     $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('blog', $groups, FileSystem::PATHINFO_PARSING);
         $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']));
     }
 }