Inject \OCP\IURLGenerator to make tests work

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
This commit is contained in:
Lukas Reschke 2017-08-18 15:32:40 +02:00
parent a04feff9a7
commit 2e4cd44556
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
4 changed files with 16 additions and 5 deletions

View File

@ -70,7 +70,7 @@ class TwoFactorChallengeController extends Controller {
* @return string * @return string
*/ */
protected function getLogoutUrl() { protected function getLogoutUrl() {
return OC_User::getLogoutUrl(); return OC_User::getLogoutUrl($this->urlGenerator);
} }
/** /**

View File

@ -187,7 +187,7 @@ class NavigationManager implements INavigationManager {
'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'), 'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
]); ]);
$logoutUrl = \OC_User::getLogoutUrl(); $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
if($logoutUrl !== '') { if($logoutUrl !== '') {
// Logout // Logout
$this->add([ $this->add([

View File

@ -283,15 +283,16 @@ class OC_User {
/** /**
* Returns the current logout URL valid for the currently logged-in user * Returns the current logout URL valid for the currently logged-in user
* *
* @param \OCP\IURLGenerator $urlGenerator
* @return string * @return string
*/ */
public static function getLogoutUrl() { public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
$backend = self::findFirstActiveUsedBackend(); $backend = self::findFirstActiveUsedBackend();
if ($backend) { if ($backend) {
return $backend->getLogoutUrl(); return $backend->getLogoutUrl();
} }
$logoutUrl = \OC::$server->getURLGenerator()->linkToRouteAbsolute( $logoutUrl = $urlGenerator->linkToRouteAbsolute(
'core.login.logout', 'core.login.logout',
[ [
'requesttoken' => \OCP\Util::callRegister(), 'requesttoken' => \OCP\Util::callRegister(),

View File

@ -217,6 +217,16 @@ class NavigationManagerTest extends TestCase {
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() { $this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function() {
return "/apps/test/"; return "/apps/test/";
}); });
$this->urlGenerator
->expects($this->once())
->method('linkToRouteAbsolute')
->with(
'core.login.logout',
[
'requesttoken' => \OCP\Util::callRegister(),
]
)
->willReturn('https://example.com/logout');
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$user->expects($this->any())->method('getUID')->willReturn('user001'); $user->expects($this->any())->method('getUID')->willReturn('user001');
$this->userSession->expects($this->any())->method('getUser')->willReturn($user); $this->userSession->expects($this->any())->method('getUser')->willReturn($user);
@ -260,7 +270,7 @@ class NavigationManagerTest extends TestCase {
[ [
'id' => 'logout', 'id' => 'logout',
'order' => 99999, 'order' => 99999,
'href' => \OC_User::getLogoutUrl(), 'href' => 'https://example.com/logout',
'icon' => '/apps/core/img/actions/logout.svg', 'icon' => '/apps/core/img/actions/logout.svg',
'name' => 'Log out', 'name' => 'Log out',
'active' => false, 'active' => false,