|
|
@@ -0,0 +1,81 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+use Opentalent\OtCore\Page\OtPageRepository;
|
|
|
+use Nimut\TestingFramework\TestCase\UnitTestCase;
|
|
|
+
|
|
|
+
|
|
|
+class OtPageRepositoryTest extends UnitTestCase
|
|
|
+{
|
|
|
+ protected $pageService;
|
|
|
+ protected $pageRepository;
|
|
|
+ protected $otPageRepository;
|
|
|
+
|
|
|
+ protected $rootLine = [
|
|
|
+ 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],
|
|
|
+ 2 => ['uid' => 3, 'pid' => 2, 'title' => 'Page', 'hidden' => 0, 'doktype' => 1, 'is_siteroot' => 0, 'nav_hide' => 0],
|
|
|
+ 3 => ['uid' => 4, 'pid' => 3, 'title' => 'Subpage', 'hidden' => 0, 'doktype' => 1, 'is_siteroot' => 0, 'nav_hide' => 0],
|
|
|
+ ];
|
|
|
+
|
|
|
+ public function setUp() {
|
|
|
+ $this->pageService = $this->prophesize(\FluidTYPO3\Vhs\Service\PageService::class);
|
|
|
+ $this->pageRepository = $this->prophesize(\TYPO3\CMS\Frontend\Page\PageRepository::class);
|
|
|
+ $this->otPageRepository = new OtPageRepository();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function injectProphecies() {
|
|
|
+ $this->otPageRepository->injectPageService($this->pageService->reveal());
|
|
|
+ $this->otPageRepository->injectPageRepository($this->pageRepository->reveal());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the given page is a subpage of a root page, the the root page is returned
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function getRootPageForSiteSubpage() {
|
|
|
+
|
|
|
+ $this->pageService->getRootLine(4)->shouldBeCalled()->willReturn($this->rootLine);
|
|
|
+ $this->pageRepository->getPage(2)->shouldBeCalled()->willReturn($this->rootLine[1]);
|
|
|
+ $this->injectProphecies();
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $this->rootLine[1],
|
|
|
+ $this->otPageRepository->getRootPageFor(4)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the given page is already a root page, it is returned as it is
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ 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]);
|
|
|
+ $this->injectProphecies();
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ $this->rootLine[1],
|
|
|
+ $this->otPageRepository->getRootPageFor(2)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the given page is not a subpage of a root page, an empty array is returned
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function getRootPageForNonSitePage() {
|
|
|
+ $this->pageService->getRootLine(1)->shouldBeCalled()->willReturn(array_slice($this->rootLine, 0, 1, true));
|
|
|
+ $this->injectProphecies();
|
|
|
+
|
|
|
+ $this->assertEquals(
|
|
|
+ [],
|
|
|
+ $this->otPageRepository->getRootPageFor(1)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|