|
|
@@ -0,0 +1,64 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Opentalent\OtCore\Tests\Unit\Controller;
|
|
|
+
|
|
|
+use Nimut\TestingFramework\TestCase\UnitTestCase;
|
|
|
+use Opentalent\OtCore\Controller\SelectedSiteController;
|
|
|
+
|
|
|
+class SelectedSiteControllerTest extends UnitTestCase
|
|
|
+{
|
|
|
+ public function injectBeUserWithMountpoints(array $mountpoints) {
|
|
|
+ $be_user = $this->prophesize(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
|
|
|
+ $be_user->returnWebmounts()->shouldBeCalled()->willReturn([1]);
|
|
|
+ $GLOBALS['BE_USER'] = $be_user->reveal();
|
|
|
+ }
|
|
|
+
|
|
|
+ private function callActionMethodProxy() {
|
|
|
+ $controller = new SelectedSiteController();
|
|
|
+
|
|
|
+ $reflection = new \ReflectionObject($controller);
|
|
|
+ $method = $reflection->getMethod('callActionMethod');
|
|
|
+ $method->setAccessible(true);
|
|
|
+
|
|
|
+ $argumentsProperty = $reflection->getProperty('preventPropagation');
|
|
|
+ $argumentsProperty->setAccessible(true);;
|
|
|
+ $argumentsProperty->setValue($controller, true);
|
|
|
+
|
|
|
+ $method->invokeArgs($controller, []);
|
|
|
+
|
|
|
+ $currentRootUidProperty = $reflection->getProperty('currentRootUid');
|
|
|
+ $currentRootUidProperty->setAccessible(true);
|
|
|
+
|
|
|
+ return $currentRootUidProperty->getValue($controller);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the current Be-user has only one website mounted,
|
|
|
+ * then the currentRootUid should this website root uid
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function callActionMethodForSingleSite() {
|
|
|
+
|
|
|
+ $this->injectBeUserWithMountpoints([1]);
|
|
|
+
|
|
|
+ $currentRootUid = $this->callActionMethodProxy();
|
|
|
+
|
|
|
+ $this->assertEquals(1, $currentRootUid);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the current Be-user has only one website mounted,
|
|
|
+ * then the currentRootUid should this website root uid
|
|
|
+ *
|
|
|
+ * @test
|
|
|
+ */
|
|
|
+ public function callActionMethodForMultiSite() {
|
|
|
+
|
|
|
+ $this->injectBeUserWithMountpoints([1, 2]);
|
|
|
+
|
|
|
+ $currentRootUid = $this->callActionMethodProxy();
|
|
|
+
|
|
|
+ $this->assertEquals(0, $currentRootUid);
|
|
|
+ }
|
|
|
+}
|