|
@@ -1,15 +1,27 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
|
|
+namespace Opentalent\OtCore\Tests\Unit\Page;
|
|
|
|
|
+
|
|
|
use Opentalent\OtCore\Page\OtPageRepository;
|
|
use Opentalent\OtCore\Page\OtPageRepository;
|
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase;
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase;
|
|
|
|
|
+use Opentalent\OtCore\Tests\Unit\Fixtures\PageFixtures;
|
|
|
|
|
+use Opentalent\OtCore\Tests\Unit\QueryBuilderProphet;
|
|
|
|
|
+use Prophecy\Argument;
|
|
|
|
|
+use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
|
|
|
|
|
|
|
|
|
|
|
|
|
class OtPageRepositoryTest extends UnitTestCase
|
|
class OtPageRepositoryTest extends UnitTestCase
|
|
|
{
|
|
{
|
|
|
protected $pageService;
|
|
protected $pageService;
|
|
|
protected $pageRepository;
|
|
protected $pageRepository;
|
|
|
|
|
+ protected $connectionPool;
|
|
|
|
|
+ protected $siteFinder;
|
|
|
|
|
+ protected $pageFixtures;
|
|
|
protected $otPageRepository;
|
|
protected $otPageRepository;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @var array[] a typical rootline
|
|
|
|
|
+ */
|
|
|
protected $rootLine = [
|
|
protected $rootLine = [
|
|
|
0 => ['uid' => 1, 'pid' => 0, 'title' => 'Folder', 'hidden' => 0, 'doktype' => 254, 'is_siteroot' => 0, 'nav_hide' => 0],
|
|
0 => ['uid' => 1, 'pid' => 0, 'title' => 'Folder', 'hidden' => 0, 'doktype' => 254, 'is_siteroot' => 0, 'nav_hide' => 0],
|
|
|
1 => ['uid' => 2, 'pid' => 1, 'title' => 'Rootpage', 'hidden' => 0, 'doktype' => 1, 'is_siteroot' => 1, 'nav_hide' => 0],
|
|
1 => ['uid' => 2, 'pid' => 1, 'title' => 'Rootpage', 'hidden' => 0, 'doktype' => 1, 'is_siteroot' => 1, 'nav_hide' => 0],
|
|
@@ -20,12 +32,19 @@ class OtPageRepositoryTest extends UnitTestCase
|
|
|
public function setUp() {
|
|
public function setUp() {
|
|
|
$this->pageService = $this->prophesize(\FluidTYPO3\Vhs\Service\PageService::class);
|
|
$this->pageService = $this->prophesize(\FluidTYPO3\Vhs\Service\PageService::class);
|
|
|
$this->pageRepository = $this->prophesize(\TYPO3\CMS\Frontend\Page\PageRepository::class);
|
|
$this->pageRepository = $this->prophesize(\TYPO3\CMS\Frontend\Page\PageRepository::class);
|
|
|
|
|
+ $this->connectionPool = $this->prophesize(\TYPO3\CMS\Core\Database\ConnectionPool::class);
|
|
|
|
|
+ $this->siteFinder = $this->prophesize(\TYPO3\CMS\Core\Site\SiteFinder::class);
|
|
|
|
|
+
|
|
|
|
|
+ $this->pageFixtures = new PageFixtures();
|
|
|
|
|
+
|
|
|
$this->otPageRepository = new OtPageRepository();
|
|
$this->otPageRepository = new OtPageRepository();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected function injectProphecies() {
|
|
protected function injectProphecies() {
|
|
|
$this->otPageRepository->injectPageService($this->pageService->reveal());
|
|
$this->otPageRepository->injectPageService($this->pageService->reveal());
|
|
|
$this->otPageRepository->injectPageRepository($this->pageRepository->reveal());
|
|
$this->otPageRepository->injectPageRepository($this->pageRepository->reveal());
|
|
|
|
|
+ $this->otPageRepository->injectConnectionPool($this->connectionPool->reveal());
|
|
|
|
|
+ $this->otPageRepository->injectSiteFinder($this->siteFinder->reveal());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -34,14 +53,17 @@ class OtPageRepositoryTest extends UnitTestCase
|
|
|
* @test
|
|
* @test
|
|
|
*/
|
|
*/
|
|
|
public function getRootPageForSiteSubpage() {
|
|
public function getRootPageForSiteSubpage() {
|
|
|
|
|
+ $start_page = $this->pageFixtures->getByUid(210);
|
|
|
|
|
+ $root_page = $this->pageFixtures->getByUid(200);
|
|
|
|
|
+ $root_line = $this->pageFixtures->getRootlineFor($start_page['uid']);
|
|
|
|
|
|
|
|
- $this->pageService->getRootLine(4)->shouldBeCalled()->willReturn($this->rootLine);
|
|
|
|
|
- $this->pageRepository->getPage(2)->shouldBeCalled()->willReturn($this->rootLine[1]);
|
|
|
|
|
|
|
+ $this->pageService->getRootLine($start_page['uid'])->shouldBeCalled()->willReturn($root_line);
|
|
|
|
|
+ $this->pageRepository->getPage($root_page['uid'])->shouldBeCalled()->willReturn($root_page);
|
|
|
$this->injectProphecies();
|
|
$this->injectProphecies();
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
$this->assertEquals(
|
|
|
- $this->rootLine[1],
|
|
|
|
|
- $this->otPageRepository->getRootPageFor(4)
|
|
|
|
|
|
|
+ $root_page,
|
|
|
|
|
+ $this->otPageRepository->getRootPageFor($start_page['uid'])
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -52,13 +74,16 @@ class OtPageRepositoryTest extends UnitTestCase
|
|
|
*/
|
|
*/
|
|
|
public function getRootPageForSiteRootpage() {
|
|
public function getRootPageForSiteRootpage() {
|
|
|
|
|
|
|
|
- $this->pageService->getRootLine(2)->shouldBeCalled()->willReturn(array_slice($this->rootLine, 0, 2, true));
|
|
|
|
|
- $this->pageRepository->getPage(2)->shouldBeCalled()->willReturn($this->rootLine[1]);
|
|
|
|
|
|
|
+ $start_and_root_page = $this->pageFixtures->getByUid(200);
|
|
|
|
|
+ $root_line = $this->pageFixtures->getRootlineFor($start_and_root_page['uid']);
|
|
|
|
|
+
|
|
|
|
|
+ $this->pageService->getRootLine($start_and_root_page['uid'])->shouldBeCalled()->willReturn($root_line);
|
|
|
|
|
+ $this->pageRepository->getPage($start_and_root_page['uid'])->shouldBeCalled()->willReturn($start_and_root_page);
|
|
|
$this->injectProphecies();
|
|
$this->injectProphecies();
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
$this->assertEquals(
|
|
|
- $this->rootLine[1],
|
|
|
|
|
- $this->otPageRepository->getRootPageFor(2)
|
|
|
|
|
|
|
+ $start_and_root_page,
|
|
|
|
|
+ $this->otPageRepository->getRootPageFor($start_and_root_page['uid'])
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -68,14 +93,107 @@ class OtPageRepositoryTest extends UnitTestCase
|
|
|
* @test
|
|
* @test
|
|
|
*/
|
|
*/
|
|
|
public function getRootPageForNonSitePage() {
|
|
public function getRootPageForNonSitePage() {
|
|
|
- $this->pageService->getRootLine(1)->shouldBeCalled()->willReturn(array_slice($this->rootLine, 0, 1, true));
|
|
|
|
|
|
|
+ $non_site_page_uid = 100;
|
|
|
|
|
+ $rootline = $this->pageFixtures->getRootlineFor($non_site_page_uid);
|
|
|
|
|
+
|
|
|
|
|
+ $this->pageService->getRootLine($non_site_page_uid)->shouldBeCalled()->willReturn($rootline);
|
|
|
$this->injectProphecies();
|
|
$this->injectProphecies();
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
$this->assertEquals(
|
|
|
[],
|
|
[],
|
|
|
- $this->otPageRepository->getRootPageFor(1)
|
|
|
|
|
|
|
+ $this->otPageRepository->getRootPageFor($non_site_page_uid)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @test
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getAllSubpagesForPageFromSubPage() {
|
|
|
|
|
+
|
|
|
|
|
+ // Start page is 230, subpages shall be 231, 232, 233
|
|
|
|
|
+ $sub_page_uid = 230;
|
|
|
|
|
+
|
|
|
|
|
+ $expected = [
|
|
|
|
|
+ $this->pageFixtures->getByUid(231),
|
|
|
|
|
+ $this->pageFixtures->getByUid(232),
|
|
|
|
|
+ $this->pageFixtures->getByUid(233),
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ $prophet = new QueryBuilderProphet($expected, [], [], []);
|
|
|
|
|
+ $queryBuilder = $prophet->prophesize();
|
|
|
|
|
+ $this->connectionPool->getQueryBuilderForTable('pages')->willReturn($queryBuilder);
|
|
|
|
|
+ $this->injectProphecies();
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ $expected,
|
|
|
|
|
+ $this->otPageRepository->getAllSubpagesForPage($sub_page_uid)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @test
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getAllSubpagesForPageFromEndpage() {
|
|
|
|
|
+
|
|
|
|
|
+ // Start page is 230, subpages shall be 231, 232, 233
|
|
|
|
|
+ $sub_page_uid = 211;
|
|
|
|
|
+ $expected = [];
|
|
|
|
|
+
|
|
|
|
|
+ $prophet = new QueryBuilderProphet([]);
|
|
|
|
|
+ $queryBuilder = $prophet->prophesize();
|
|
|
|
|
+ $this->connectionPool->getQueryBuilderForTable('pages')->willReturn($queryBuilder);
|
|
|
|
|
+ $this->injectProphecies();
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ $expected,
|
|
|
|
|
+ $this->otPageRepository->getAllSubpagesForPage($sub_page_uid)
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @test
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getSiteForSiteRootPage() {
|
|
|
|
|
+ $root_uid = 200;
|
|
|
|
|
+
|
|
|
|
|
+ $root_page = $this->pageFixtures->getByUid($root_uid);
|
|
|
|
|
+ $root_line = $this->pageFixtures->getRootlineFor($root_uid);
|
|
|
|
|
|
|
|
|
|
+ $this->pageService->getRootLine($root_uid)->shouldBeCalled()->willReturn($root_line);
|
|
|
|
|
+ $this->pageRepository->getPage($root_uid)->shouldBeCalled()->willReturn($root_page);
|
|
|
|
|
+
|
|
|
|
|
+ $site = $this->prophesize(\TYPO3\CMS\Core\Site\Entity\Site::class);
|
|
|
|
|
+ $this->siteFinder->getSiteByRootPageId($root_uid)->shouldBeCalled()->willReturn($site->reveal());
|
|
|
|
|
+
|
|
|
|
|
+ $this->injectProphecies();
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ $site->reveal(),
|
|
|
|
|
+ $this->otPageRepository->getSiteFor($root_uid)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @test
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getSiteForSiteSubPage() {
|
|
|
|
|
+ $page_uid = 211;
|
|
|
|
|
+
|
|
|
|
|
+ $page = $this->pageFixtures->getByUid($page_uid);
|
|
|
|
|
+ $root_page = $this->pageFixtures->getByUid(200);
|
|
|
|
|
+ $root_line = $this->pageFixtures->getRootlineFor($page_uid);
|
|
|
|
|
+
|
|
|
|
|
+ $this->pageService->getRootLine($page_uid)->shouldBeCalled()->willReturn($root_line);
|
|
|
|
|
+ $this->pageRepository->getPage($page_uid)->shouldBeCalled()->willReturn($page);
|
|
|
|
|
+
|
|
|
|
|
+ $site = $this->prophesize(\TYPO3\CMS\Core\Site\Entity\Site::class);
|
|
|
|
|
+ $this->siteFinder->getSiteByRootPageId($root_page['uid'])->shouldBeCalled()->willReturn($site->reveal());
|
|
|
|
|
+
|
|
|
|
|
+ $this->injectProphecies();
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals(
|
|
|
|
|
+ $site->reveal(),
|
|
|
|
|
+ $this->otPageRepository->getSiteFor($page_uid)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|