Skip to content

Commit

Permalink
Merge pull request #1972 from nextcloud/bugfix/noid/direct-url
Browse files Browse the repository at this point in the history
Fix generating the redirect url
  • Loading branch information
skjnldsv authored Dec 14, 2020
2 parents 49d7d5e + 6d7fd24 commit b925bf3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/Controller/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function __construct(IRequest $request,
* @param string $uuid
*/
public function direct(string $contact): RedirectResponse {
$url = $this->urlGenerator->getAbsoluteURL('/apps/contacts/' . $this->l10n->t('All contacts') . '/' . $contact);
$url = $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute('contacts.page.index') . $this->l10n->t('All contacts') . '/' . $contact
);
return new RedirectResponse($url);
}
}
11 changes: 8 additions & 3 deletions tests/unit/Controller/ContactsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ public function testRedirect() {
->with('All contacts')
->willReturn('All contacts');

$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('contacts.page.index')
->willReturn('/index.php/apps/contacts/');

$this->urlGenerator->expects($this->once())
->method('getAbsoluteURL')
->with('/apps/contacts/All contacts/' . $contact)
->willReturn('/apps/contacts/All contacts/' . $contact);
->with('/index.php/apps/contacts/All contacts/' . $contact)
->willReturn('/index.php/apps/contacts/All contacts/' . $contact);

$result = $this->controller->direct('uuid~addressbook');
$this->assertTrue($result instanceof RedirectResponse);
$this->assertEquals('/apps/contacts/All contacts/' . $contact, $result->getRedirectURL());
$this->assertEquals('/index.php/apps/contacts/All contacts/' . $contact, $result->getRedirectURL());
}
}

0 comments on commit b925bf3

Please sign in to comment.