|
|
@@ -4,37 +4,55 @@ namespace Opentalent\OtCore\Tests\Unit\Controller;
|
|
|
|
|
|
use Nimut\TestingFramework\TestCase\UnitTestCase;
|
|
|
use Opentalent\OtCore\Controller\SelectedSiteController;
|
|
|
+use Opentalent\OtCore\Exception\NoSiteSelected;
|
|
|
+use Opentalent\OtCore\Page\OtPageRepository;
|
|
|
|
|
|
class SelectedSiteControllerTest extends UnitTestCase
|
|
|
{
|
|
|
- public function injectBeUserWithMountpoints(array $mountpoints) {
|
|
|
+ private $controller;
|
|
|
+
|
|
|
+ public function setUp() {
|
|
|
+ $this->controller = new SelectedSiteController();
|
|
|
+ }
|
|
|
+
|
|
|
+ private function injectBeUserWithMountpoints(array $mountpoints) {
|
|
|
$be_user = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
|
|
|
- $be_user->returnWebmounts()->shouldBeCalled()->willReturn([1]);
|
|
|
+ $be_user->returnWebmounts()->shouldBeCalled()->willReturn($mountpoints);
|
|
|
$GLOBALS['BE_USER'] = $be_user->reveal();
|
|
|
}
|
|
|
|
|
|
- private function callActionMethodProxy() {
|
|
|
- $controller = new SelectedSiteController();
|
|
|
+ private function injectPageRepositoryWithSelectedUid(?int $selectedUid) {
|
|
|
+ $otPageRepository = $this->prophesize(OtPageRepository::class);
|
|
|
+ if ($selectedUid != null) {
|
|
|
+ $otPageRepository->getCurrentRootUid()->shouldBeCalled()->willReturn($selectedUid);
|
|
|
+ } else {
|
|
|
+ $otPageRepository->getCurrentRootUid()->shouldBeCalled()->willThrow(new NoSiteSelected());
|
|
|
+ }
|
|
|
+ $this->controller->injectOtPageRepository($otPageRepository->reveal());
|
|
|
+ }
|
|
|
|
|
|
- $reflection = new \ReflectionObject($controller);
|
|
|
+ private function callActionMethodProxy() {
|
|
|
+ $reflection = new \ReflectionObject($this->controller);
|
|
|
$method = $reflection->getMethod('callActionMethod');
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
$argumentsProperty = $reflection->getProperty('preventPropagation');
|
|
|
$argumentsProperty->setAccessible(true);;
|
|
|
- $argumentsProperty->setValue($controller, true);
|
|
|
+ $argumentsProperty->setValue($this->controller, true);
|
|
|
|
|
|
- $method->invokeArgs($controller, []);
|
|
|
+ $method->invokeArgs($this->controller, []);
|
|
|
|
|
|
$currentRootUidProperty = $reflection->getProperty('currentRootUid');
|
|
|
$currentRootUidProperty->setAccessible(true);
|
|
|
|
|
|
- return $currentRootUidProperty->getValue($controller);
|
|
|
+ return $currentRootUidProperty->getValue($this->controller);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* If the current Be-user has only one website mounted,
|
|
|
- * then the currentRootUid should this website root uid
|
|
|
+ * then the currentRootUid should be this website root uid
|
|
|
*
|
|
|
* @test
|
|
|
*/
|
|
|
@@ -48,8 +66,8 @@ class SelectedSiteControllerTest extends UnitTestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * If the current Be-user has only one website mounted,
|
|
|
- * then the currentRootUid should this website root uid
|
|
|
+ * If the current Be-user has many websites mounted and a website page is selected,
|
|
|
+ * then the currentRootUid should be the currently selected website root page uid
|
|
|
*
|
|
|
* @test
|
|
|
*/
|
|
|
@@ -57,8 +75,27 @@ class SelectedSiteControllerTest extends UnitTestCase
|
|
|
|
|
|
$this->injectBeUserWithMountpoints([1, 2]);
|
|
|
|
|
|
+ $this->injectPageRepositoryWithSelectedUid(2);
|
|
|
+
|
|
|
+ $currentRootUid = $this->callActionMethodProxy();
|
|
|
+
|
|
|
+ $this->assertEquals(2, $currentRootUid);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the current Be-user has many websites mounted and no website page is selected,
|
|
|
+ * then the currentRootUid should be null
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function callActionMethodForNoSite() {
|
|
|
+
|
|
|
+ $this->injectBeUserWithMountpoints([1, 2]);
|
|
|
+
|
|
|
+ $this->injectPageRepositoryWithSelectedUid(null);
|
|
|
+
|
|
|
$currentRootUid = $this->callActionMethodProxy();
|
|
|
|
|
|
- $this->assertEquals(0, $currentRootUid);
|
|
|
+ $this->assertNull($currentRootUid);
|
|
|
}
|
|
|
}
|