|
|
@ -9,10 +9,13 @@ |
|
|
|
namespace Test; |
|
|
|
|
|
|
|
use OC\Route\Router; |
|
|
|
use OCP\App\IAppManager; |
|
|
|
use OCP\ICacheFactory; |
|
|
|
use OCP\IConfig; |
|
|
|
use OCP\IRequest; |
|
|
|
use OCP\IURLGenerator; |
|
|
|
use OCP\IUser; |
|
|
|
use OCP\IUserSession; |
|
|
|
|
|
|
|
/** |
|
|
|
* Class UrlGeneratorTest |
|
|
@ -23,6 +26,10 @@ class UrlGeneratorTest extends \Test\TestCase { |
|
|
|
|
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|IConfig */ |
|
|
|
private $config; |
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|IUserSession */ |
|
|
|
private $userSession; |
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|IAppManager */ |
|
|
|
private $appManager; |
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|ICacheFactory */ |
|
|
|
private $cacheFactory; |
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|IRequest */ |
|
|
@ -37,11 +44,15 @@ class UrlGeneratorTest extends \Test\TestCase { |
|
|
|
protected function setUp(): void { |
|
|
|
parent::setUp(); |
|
|
|
$this->config = $this->createMock(IConfig::class); |
|
|
|
$this->userSession = $this->createMock(IUserSession::class); |
|
|
|
$this->appManager = $this->createMock(IAppManager::class); |
|
|
|
$this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
|
|
$this->request = $this->createMock(IRequest::class); |
|
|
|
$this->router = $this->createMock(Router::class); |
|
|
|
$this->urlGenerator = new \OC\URLGenerator( |
|
|
|
$this->config, |
|
|
|
$this->userSession, |
|
|
|
$this->appManager, |
|
|
|
$this->cacheFactory, |
|
|
|
$this->request, |
|
|
|
$this->router |
|
|
@ -234,4 +245,66 @@ class UrlGeneratorTest extends \Test\TestCase { |
|
|
|
$_REQUEST['redirect_url'] = 'myRedirectUrl.com@foo.com:a'; |
|
|
|
$this->assertSame('http://localhost'.\OC::$WEBROOT.'/apps/files/', $this->urlGenerator->linkToDefaultPageUrl()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @dataProvider provideDefaultApps |
|
|
|
*/ |
|
|
|
public function testGetDefaultPageUrlWithDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { |
|
|
|
$oldDefaultApps = \OC::$server->getConfig()->getSystemValue('defaultapp', ''); |
|
|
|
|
|
|
|
/** @var \PHPUnit\Framework\MockObject\MockObject|IUser $userMock */ |
|
|
|
$userMock = $this->createMock(IUser::class); |
|
|
|
$userMock->expects($this->once()) |
|
|
|
->method('getUID') |
|
|
|
->willReturn($this->getUniqueID()); |
|
|
|
|
|
|
|
$this->userSession->expects($this->once()) |
|
|
|
->method('isLoggedIn') |
|
|
|
->willReturn(true); |
|
|
|
$this->userSession->expects($this->once()) |
|
|
|
->method('getUser') |
|
|
|
->willReturn($userMock); |
|
|
|
$this->appManager->expects($this->any()) |
|
|
|
->method('isEnabledForUser') |
|
|
|
->willReturnCallback(function ($appId) use ($enabledApps) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function provideDefaultApps() { |
|
|
|
return [ |
|
|
|
// none specified, default to files
|
|
|
|
[ |
|
|
|
'', |
|
|
|
'apps/files/', |
|
|
|
['files'], |
|
|
|
], |
|
|
|
// unexisting or inaccessible app specified, default to files
|
|
|
|
[ |
|
|
|
'unexist', |
|
|
|
'apps/files/', |
|
|
|
['files'], |
|
|
|
], |
|
|
|
// non-standard app
|
|
|
|
[ |
|
|
|
'calendar', |
|
|
|
'apps/calendar/', |
|
|
|
['files', 'calendar'], |
|
|
|
], |
|
|
|
// non-standard app with fallback
|
|
|
|
[ |
|
|
|
'contacts,calendar', |
|
|
|
'apps/calendar/', |
|
|
|
['files', 'calendar'], |
|
|
|
], |
|
|
|
]; |
|
|
|
} |
|
|
|
} |