diff options
author | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-04 16:38:45 +0200 |
---|---|---|
committer | Daniel Rudolf <github.com@daniel-rudolf.de> | 2021-08-04 18:52:53 +0200 |
commit | b768cade2b2c6664851de6462a17ef3531305971 (patch) | |
tree | 145d33a8edb2e60d911b961fa805eee5166f02d7 /tests/lib/UrlGeneratorTest.php | |
parent | 1e5962ae98ba43a68fc33967aea30a1645f9bf17 (diff) | |
download | nextcloud-server-b768cade2b2c6664851de6462a17ef3531305971.tar.gz nextcloud-server-b768cade2b2c6664851de6462a17ef3531305971.zip |
Fix UrlGeneratorTest
Again... :unamused:
Signed-off-by: Daniel Rudolf <github.com@daniel-rudolf.de>
Diffstat (limited to 'tests/lib/UrlGeneratorTest.php')
-rw-r--r-- | tests/lib/UrlGeneratorTest.php | 72 |
1 files changed, 44 insertions, 28 deletions
diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index d16f78ed18c..27f08c42f36 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -21,7 +21,6 @@ use OCP\IUserSession; * Class UrlGeneratorTest * * @package Test - * @group DB */ class UrlGeneratorTest extends \Test\TestCase { @@ -217,49 +216,72 @@ class UrlGeneratorTest extends \Test\TestCase { ]; } - public function testGetDefaultPageUrlWithRedirectUrlWithoutFrontController() { - putenv('front_controller_active=false'); - \OC::$server->getConfig()->deleteSystemValue('htaccess.IgnoreFrontController'); + private function mockLinkToDefaultPageUrl(string $defaultAppConfig = '', bool $ignoreFrontControllerConfig = false) { + $this->config->expects($this->exactly(2)) + ->method('getSystemValue') + ->withConsecutive( + ['defaultapp', $this->anything()], + ['htaccess.IgnoreFrontController', $this->anything()], + ) + ->will($this->onConsecutiveCalls( + $defaultAppConfig, + $ignoreFrontControllerConfig + )); + } + + public function testLinkToDefaultPageUrlWithRedirectUrlWithoutFrontController() { + $this->mockBaseUrl(); $_REQUEST['redirect_url'] = 'myRedirectUrl.com'; - $this->assertSame('http://localhost'.\OC::$WEBROOT.'/myRedirectUrl.com', $this->urlGenerator->linkToDefaultPageUrl()); + $this->assertSame('http://localhost' . \OC::$WEBROOT . '/myRedirectUrl.com', $this->urlGenerator->linkToDefaultPageUrl()); } - public function testGetDefaultPageUrlWithRedirectUrlRedirectBypassWithoutFrontController() { + public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithoutFrontController() { + $this->mockBaseUrl(); + $this->mockLinkToDefaultPageUrl(); putenv('front_controller_active=false'); - \OC::$server->getConfig()->deleteSystemValue('htaccess.IgnoreFrontController'); $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a'; - $this->assertSame('http://localhost'.\OC::$WEBROOT.'/index.php/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); + $this->assertSame('http://localhost' . \OC::$WEBROOT . '/index.php/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); } - public function testGetDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontController() { + public function testLinkToDefaultPageUrlWithRedirectUrlRedirectBypassWithFrontController() { + $this->mockBaseUrl(); + $this->mockLinkToDefaultPageUrl(); putenv('front_controller_active=true'); + $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a'; - $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); + $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); } - public function testGetDefaultPageUrlWithRedirectUrlWithIgnoreFrontController() { + public function testLinkToDefaultPageUrlWithRedirectUrlWithIgnoreFrontController() { + $this->mockBaseUrl(); + $this->mockLinkToDefaultPageUrl('', true); putenv('front_controller_active=false'); - \OC::$server->getConfig()->setSystemValue('htaccess.IgnoreFrontController', true); $_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a'; - $this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); + $this->assertSame('http://localhost' . \OC::$WEBROOT . '/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); } /** * @dataProvider provideDefaultApps - * @group DB */ - public function testGetDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { - $oldDefaultApps = \OC::$server->getConfig()->getSystemValue('defaultapp', ''); + public function testLinkToDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { + $userId = $this->getUniqueID(); /** @var \PHPUnit\Framework\MockObject\MockObject|IUser $userMock */ $userMock = $this->createMock(IUser::class); $userMock->expects($this->once()) ->method('getUID') - ->willReturn($this->getUniqueID()); + ->willReturn($userId); + + $this->mockBaseUrl(); + $this->mockLinkToDefaultPageUrl($defaultAppConfig); + $this->config->expects($this->once()) + ->method('getUserValue') + ->with($userId, 'core', 'defaultapp') + ->willReturn(''); $this->userSession->expects($this->once()) ->method('isLoggedIn') ->willReturn(true); @@ -272,13 +294,7 @@ class UrlGeneratorTest extends \Test\TestCase { return in_array($appId, $enabledApps); }); - try { - \OC::$server->getConfig()->setSystemValue('defaultapp', $defaultAppConfig); - $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl()); - } finally { - // restore old state - \OC::$server->getConfig()->setSystemValue('defaultapp', $oldDefaultApps); - } + $this->assertEquals('http://localhost' . \OC::$WEBROOT . $expectedPath, $this->urlGenerator->linkToDefaultPageUrl()); } public function provideDefaultApps() { @@ -286,25 +302,25 @@ class UrlGeneratorTest extends \Test\TestCase { // none specified, default to files [ '', - 'apps/files/', + '/index.php/apps/files/', ['files'], ], // unexisting or inaccessible app specified, default to files [ 'unexist', - 'apps/files/', + '/index.php/apps/files/', ['files'], ], // non-standard app [ 'calendar', - 'apps/calendar/', + '/index.php/apps/calendar/', ['files', 'calendar'], ], // non-standard app with fallback [ 'contacts,calendar', - 'apps/calendar/', + '/index.php/apps/calendar/', ['files', 'calendar'], ], ]; |