Esempio n. 1
0
 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']);
 }
Esempio n. 2
0
 /**
  * Reorder collection.
  *
  * @param string $by
  * @param string $dir
  * @param array  $manual
  * @return $this
  */
 public function order($by, $dir = 'asc', $manual = null)
 {
     $this->items = $this->pages->sortCollection($this, $by, $dir, $manual);
     return $this;
 }