mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 04:17:09 +02:00
✅ More Pages class tests
This commit is contained in:
@@ -38,11 +38,195 @@ class PagesTest extends \Codeception\TestCase\Test
|
||||
|
||||
}
|
||||
|
||||
public function testBase()
|
||||
{
|
||||
$this->assertSame('', $this->pages->base());
|
||||
$this->pages->base('/test');
|
||||
$this->assertSame('/test', $this->pages->base());
|
||||
}
|
||||
|
||||
public function testLastModified()
|
||||
{
|
||||
$this->assertSame(null, $this->pages->lastModified());
|
||||
$this->pages->lastModified('test');
|
||||
$this->assertSame('test', $this->pages->lastModified());
|
||||
}
|
||||
|
||||
public function testInstances()
|
||||
{
|
||||
$this->assertTrue(is_array($this->pages->instances()));
|
||||
foreach($this->pages->instances() as $instance) {
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $instance);
|
||||
}
|
||||
}
|
||||
|
||||
public function testRoutes()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
$this->assertTrue(is_array($this->pages->routes()));
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/01.home', $this->pages->routes()['/']);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/01.home', $this->pages->routes()['/home']);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog', $this->pages->routes()['/blog']);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', $this->pages->routes()['/blog/post-one']);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', $this->pages->routes()['/blog/post-two']);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.about', $this->pages->routes()['/about']);
|
||||
}
|
||||
|
||||
public function testAddPage()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
$path = $locator->findResource('tests://') . '/fake/single-pages/01.simple-page/default.md';
|
||||
$aPage = new Page();
|
||||
$aPage->init(new \SplFileInfo($path));
|
||||
|
||||
$this->pages->addPage($aPage, '/new-page');
|
||||
|
||||
$this->assertTrue(in_array('/new-page', array_keys($this->pages->routes())));
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/single-pages/01.simple-page', $this->pages->routes()['/new-page']);
|
||||
}
|
||||
|
||||
public function testSort()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
$aPage = $this->pages->dispatch('/blog');
|
||||
$subPagesSorted = $this->pages->sort($aPage);
|
||||
|
||||
$this->assertTrue(is_array($subPagesSorted));
|
||||
$this->assertTrue(count($subPagesSorted) === 2);
|
||||
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[0]);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[1]);
|
||||
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
|
||||
|
||||
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
|
||||
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
|
||||
|
||||
$subPagesSorted = $this->pages->sort($aPage, null, 'desc');
|
||||
|
||||
$this->assertTrue(is_array($subPagesSorted));
|
||||
$this->assertTrue(count($subPagesSorted) === 2);
|
||||
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[0]);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[1]);
|
||||
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
|
||||
|
||||
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
|
||||
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
|
||||
}
|
||||
|
||||
public function testSortCollection()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
$aPage = $this->pages->dispatch('/blog');
|
||||
$subPagesSorted = $this->pages->sortCollection($aPage->children(), $aPage->orderBy());
|
||||
|
||||
$this->assertTrue(is_array($subPagesSorted));
|
||||
$this->assertTrue(count($subPagesSorted) === 2);
|
||||
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[0]);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[1]);
|
||||
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
|
||||
|
||||
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
|
||||
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
|
||||
|
||||
$subPagesSorted = $this->pages->sortCollection($aPage->children(), $aPage->orderBy(), 'desc');
|
||||
|
||||
$this->assertTrue(is_array($subPagesSorted));
|
||||
$this->assertTrue(count($subPagesSorted) === 2);
|
||||
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)[0]);
|
||||
$this->assertSame($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)[1]);
|
||||
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one', array_keys($subPagesSorted)));
|
||||
$this->assertTrue(in_array($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two', array_keys($subPagesSorted)));
|
||||
|
||||
$this->assertSame(["slug" => "post-one"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-one']);
|
||||
$this->assertSame(["slug" => "post-two"], $subPagesSorted[$locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog/post-two']);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
//Page existing
|
||||
$aPage = $this->pages->get($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.about');
|
||||
$this->assertTrue(is_object($aPage));
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
|
||||
|
||||
//Page not existing
|
||||
$anotherPage = $this->pages->get($locator->findResource('tests://') . '/fake/simple-site/user/pages/03.non-existing');
|
||||
$this->assertFalse(is_object($anotherPage));
|
||||
$this->assertNull($anotherPage);
|
||||
}
|
||||
|
||||
public function testChildren()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $this->grav['locator'];
|
||||
|
||||
//Page existing
|
||||
$children = $this->pages->children($locator->findResource('tests://') . '/fake/simple-site/user/pages/02.blog');
|
||||
$this->assertInstanceOf('Grav\Common\Page\Collection', $children);
|
||||
|
||||
//Page not existing
|
||||
$children = $this->pages->children($locator->findResource('tests://') . '/fake/whatever/non-existing');
|
||||
$this->assertSame([], $children->toArray());
|
||||
}
|
||||
|
||||
public function testDispatch()
|
||||
{
|
||||
$aPage = $this->pages->dispatch('/blog');
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
|
||||
|
||||
$aPage = $this->pages->dispatch('/about');
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
|
||||
|
||||
$aPage = $this->pages->dispatch('/blog/post-one');
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $aPage);
|
||||
|
||||
//Page not existing
|
||||
$aPage = $this->pages->dispatch('/non-existing');
|
||||
$this->assertNull($aPage);
|
||||
}
|
||||
|
||||
public function testRoot()
|
||||
{
|
||||
$root = $this->pages->root();
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $root);
|
||||
$this->assertSame('pages', $root->folder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testBlueprints()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$this->assertTrue(is_object($this->pages->all()));
|
||||
$this->assertTrue(is_array($this->pages->all()->toArray()));
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $this->pages->all()->first());
|
||||
foreach($this->pages->all() as $page) {
|
||||
$this->assertInstanceOf('Grav\Common\Page\Page', $page);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
@@ -52,4 +236,77 @@ class PagesTest extends \Codeception\TestCase\Test
|
||||
$this->assertSame('Home', $list['/']);
|
||||
$this->assertSame('Blog', $list['/blog']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testGetTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testModularTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testPageTypes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testAccessLevels()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testParents()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testParentsRawRoutes()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testGetHomeRoute()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo
|
||||
*/
|
||||
public function testResetPages()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user