Olivier Massot 4 gadi atpakaļ
vecāks
revīzija
e76134eb1d

+ 8 - 16
ot_core/Tests/Unit/Controller/SelectedSiteControllerTest.php

@@ -15,19 +15,15 @@ class SelectedSiteControllerTest extends UnitTestCase
         $this->controller = new SelectedSiteController();
     }
 
-    private function injectBeUserWithMountpoints(array $mountpoints) {
-        $be_user = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
-        $be_user->returnWebmounts()->shouldBeCalled()->willReturn($mountpoints);
-        $GLOBALS['BE_USER'] = $be_user->reveal();
-    }
-
-    private function injectPageRepositoryWithSelectedUid(?int $selectedUid) {
+    private function injectPageRepositoryWithSelectedUidAndMountpoints(?int $selectedUid, array $mountpoints = []) {
         $otPageRepository = $this->prophesize(OtPageRepository::class);
+
         if ($selectedUid != null) {
-            $otPageRepository->getCurrentRootUid()->shouldBeCalled()->willReturn($selectedUid);
+            $otPageRepository->getCurrentRootUid()->willReturn($selectedUid);
         } else {
-            $otPageRepository->getCurrentRootUid()->shouldBeCalled()->willThrow(new NoSiteSelected());
+            $otPageRepository->getCurrentRootUid()->willThrow(new NoSiteSelected());
         }
+        $otPageRepository->getCurrentBeUserMountpoints()->shouldBeCalled()->willReturn($mountpoints);
         $this->controller->injectOtPageRepository($otPageRepository->reveal());
     }
 
@@ -58,7 +54,7 @@ class SelectedSiteControllerTest extends UnitTestCase
      */
     public function callActionMethodForSingleSite() {
 
-        $this->injectBeUserWithMountpoints([1]);
+        $this->injectPageRepositoryWithSelectedUidAndMountpoints(null, [1]);
 
         $currentRootUid = $this->callActionMethodProxy();
 
@@ -73,9 +69,7 @@ class SelectedSiteControllerTest extends UnitTestCase
      */
     public function callActionMethodForMultiSite() {
 
-        $this->injectBeUserWithMountpoints([1, 2]);
-
-        $this->injectPageRepositoryWithSelectedUid(2);
+        $this->injectPageRepositoryWithSelectedUidAndMountpoints(2, [1, 2]);
 
         $currentRootUid = $this->callActionMethodProxy();
 
@@ -90,9 +84,7 @@ class SelectedSiteControllerTest extends UnitTestCase
      */
     public function callActionMethodForNoSite() {
 
-        $this->injectBeUserWithMountpoints([1, 2]);
-
-        $this->injectPageRepositoryWithSelectedUid(null);
+        $this->injectPageRepositoryWithSelectedUidAndMountpoints(null, [1, 2]);
 
         $currentRootUid = $this->callActionMethodProxy();
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
ot_core/Tests/Unit/Fixtures/PageFixtures.php


+ 39 - 0
ot_core/Tests/Unit/Page/OtPageRepositoryTest.php

@@ -223,6 +223,45 @@ class OtPageRepositoryTest extends UnitTestCase
         $this->assertEquals($expected, $actual);
     }
 
+    /**
+     * Calling getPageWithSubpages() should return the page itself, along with all of its subpages
+     * No need to test more cases, since this method only extends the well tested getAllSubpagesForPage method.
+     *
+     * @test
+     */
+    public function getPageWithSubpagesForRootPage() {
+        // Prepare prophecies
+        $page_uid = 200;
+
+        $sub_pages = [];
+        foreach ($this->pageFixtures->getAll() as $page) {
+            if ($page['uid'] > 200) {
+                $sub_pages[] = $page;
+            }
+        }
+
+        $willReturn = [$this->pageFixtures->getDirectSubpagesFor($page_uid)];
+        foreach ($sub_pages as $page) {
+            $willReturn[] = $this->pageFixtures->getDirectSubpagesFor($page['uid']);
+        }
+
+        $prophet = new QueryBuilderProphet(...$willReturn);
+        $queryBuilder = $prophet->prophesize();
+        $this->connectionPool->getQueryBuilderForTable('pages')->willReturn($queryBuilder);
+        $this->injectProphecies();
+
+        $page = $this->pageFixtures->getByUid($page_uid);
+
+        $this->pageRepository->getPage($page_uid, true)->willReturn($page);
+        $this->otPageRepository->injectPageRepository($this->pageRepository->reveal());
+
+        // Test
+        $expected = array_merge([$page], $sub_pages);
+        $actual = $this->otPageRepository->getPageWithSubpages($page_uid);
+
+        $this->assertEquals($expected, $actual);
+    }
+
     /**
      * Calling getSiteByRootPageId() on a site's root page should return the site object
      * as the typo3 SiteFinder class would do

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels