mirror of https://github.com/nextcloud/contacts
Fix tests
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
fec1798301
commit
b3ae06f371
|
@ -28,7 +28,6 @@ use OCP\Contacts\ContactsMenu\IActionFactory;
|
|||
use OCP\Contacts\ContactsMenu\IEntry;
|
||||
use OCP\Contacts\ContactsMenu\IProvider;
|
||||
use OCP\Contacts\IManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
|
||||
|
@ -46,9 +45,6 @@ class DetailsProvider implements IProvider {
|
|||
/** @var IManager */
|
||||
private $manager;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IURLGenerator $urlGenerator
|
||||
* @param IActionFactory $actionFactory
|
||||
|
@ -56,13 +52,11 @@ class DetailsProvider implements IProvider {
|
|||
public function __construct(IURLGenerator $urlGenerator,
|
||||
IActionFactory $actionFactory,
|
||||
IL10N $l10n,
|
||||
IManager $manager,
|
||||
IConfig $config) {
|
||||
IManager $manager) {
|
||||
$this->actionFactory = $actionFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->l10n = $l10n;
|
||||
$this->manager = $manager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,22 +105,18 @@ class DetailsProvider implements IProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
// We need $this->manager->getAddressbooksUris() to add this function
|
||||
$ncVersion = $this->config->getSystemValue('version', '0.0.0');
|
||||
if (version_compare($ncVersion, '16.0.0', '>=')) {
|
||||
$addressBookUri = $this->getAddressBookUri($entry->getProperty('addressbook-key'));
|
||||
$addressBookUri = $this->getAddressBookUri($entry->getProperty('addressbook-key'));
|
||||
|
||||
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/info.svg'));
|
||||
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/info.svg'));
|
||||
|
||||
$contactsUrl = $this->urlGenerator->getAbsoluteURL(
|
||||
$this->urlGenerator->linkToRoute('contacts.contacts.direct', [
|
||||
'contact' => $uid . '~' . $addressBookUri
|
||||
])
|
||||
);
|
||||
$contactsUrl = $this->urlGenerator->getAbsoluteURL(
|
||||
$this->urlGenerator->linkToRoute('contacts.contacts.direct', [
|
||||
'contact' => $uid . '~' . $addressBookUri
|
||||
])
|
||||
);
|
||||
|
||||
$action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Details'), $contactsUrl);
|
||||
$action->setPriority(0);
|
||||
$entry->addAction($action);
|
||||
}
|
||||
$action = $this->actionFactory->newLinkAction($iconUrl, $this->l10n->t('Details'), $contactsUrl);
|
||||
$action->setPriority(0);
|
||||
$entry->addAction($action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,34 +63,15 @@ class DetailsProviderTest extends Base {
|
|||
$this->actionFactory = $this->createMock(IActionFactory::class);
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->manager = $this->createMock(IManager::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->provider = new DetailsProvider(
|
||||
$this->urlGenerator,
|
||||
$this->actionFactory,
|
||||
$this->l10n,
|
||||
$this->manager,
|
||||
$this->config
|
||||
$this->manager
|
||||
);
|
||||
}
|
||||
|
||||
public function eventProvider() {
|
||||
return [
|
||||
['16.0.0', true, 'https://cloud.example.com/apps/contacts/All contacts/e3a71614-c602-4eb5-9994-47eec551542b~contacts-1'],
|
||||
['16.0.10', false, 'https://cloud.example.com/index.php/apps/contacts/All contacts/e3a71614-c602-4eb5-9994-47eec551542b~contacts-1'],
|
||||
['17.0.0', true, 'https://cloud.example.com/apps/contacts/All contacts/e3a71614-c602-4eb5-9994-47eec551542b~contacts-1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* only NC16+ have the contactsmenu integration
|
||||
* https://github.com/nextcloud/server/pull/13642
|
||||
*
|
||||
* @dataProvider eventProvider
|
||||
* @param string $version
|
||||
* @param boolean $frontController
|
||||
* @param string $resultUri
|
||||
*/
|
||||
public function testProcessNC16AndAbove($version, $frontControllerActive, $resultUri) {
|
||||
public function testProcessContact() {
|
||||
$entry = $this->createMock(IEntry::class);
|
||||
$action = $this->createMock(ILinkAction::class);
|
||||
$addressbook = $this->createMock(IAddressBook::class);
|
||||
|
@ -100,19 +81,7 @@ class DetailsProviderTest extends Base {
|
|||
$uid = 'e3a71614-c602-4eb5-9994-47eec551542b';
|
||||
$abUri = 'contacts-1';
|
||||
$iconUrl = 'core/img/actions/info.svg';
|
||||
$defaultGroup = 'All contacts';
|
||||
$index = $frontControllerActive ? '' : '/index.php';
|
||||
|
||||
|
||||
$this->config->expects($this->at(0))
|
||||
->method('getSystemValue')
|
||||
->with('version', '0.0.0')
|
||||
->willReturn($version);
|
||||
|
||||
$this->config->expects($this->at(1))
|
||||
->method('getSystemValue')
|
||||
->with('htaccess.IgnoreFrontController', false)
|
||||
->willReturn($frontControllerActive);
|
||||
$resultUri = "$domain/index.php/apps/contacts/direct/contact/$uid~$abUri";
|
||||
|
||||
$entry->expects($this->exactly(3))
|
||||
->method('getProperty')
|
||||
|
@ -140,20 +109,24 @@ class DetailsProviderTest extends Base {
|
|||
->with('core', 'actions/info.svg')
|
||||
->willReturn($iconUrl);
|
||||
|
||||
//
|
||||
$this->urlGenerator->expects($this->once())
|
||||
->method('linkToRoute')
|
||||
->with('contacts.contacts.direct', [
|
||||
'contact' => $uid . '~' . $abUri
|
||||
])
|
||||
->willReturn("/apps/contacts/direct/contact/$uid~$abUri");
|
||||
|
||||
// Action icon and contact absolute urls
|
||||
$this->urlGenerator->expects($this->exactly(2))
|
||||
->method('getAbsoluteURL')
|
||||
->will($this->returnValueMap([
|
||||
[$iconUrl, "$domain/$iconUrl"],
|
||||
["$index/apps/contacts/$defaultGroup/$uid~$abUri", "$domain$index/apps/contacts/$defaultGroup/$uid~$abUri"]
|
||||
["/apps/contacts/direct/contact/$uid~$abUri", $resultUri]
|
||||
]));
|
||||
|
||||
// Translations
|
||||
$this->l10n->expects($this->at(0))
|
||||
->method('t')
|
||||
->with($defaultGroup)
|
||||
->willReturn($defaultGroup);
|
||||
$this->l10n->expects($this->at(1))
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t')
|
||||
->with('Details')
|
||||
->willReturnArgument(0);
|
||||
|
@ -172,27 +145,6 @@ class DetailsProviderTest extends Base {
|
|||
$this->provider->process($entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* NC15 doesn't have the contactsmenu integration
|
||||
* https://github.com/nextcloud/server/pull/13642
|
||||
*/
|
||||
public function testProcessNC15() {
|
||||
$this->config->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('version', '0.0.0')
|
||||
->willReturn('15.0.0.0');
|
||||
|
||||
$entry = $this->createMock(IEntry::class);
|
||||
$entry->expects($this->exactly(2))
|
||||
->method('getProperty')
|
||||
->will($this->returnValueMap([
|
||||
['UID', 'e3a71614-c602-4eb5-9994-47eec551542b'],
|
||||
['isLocalSystemBook', null]
|
||||
]));
|
||||
|
||||
$this->assertNull($this->provider->process($entry));
|
||||
}
|
||||
|
||||
public function testProcessNoUID() {
|
||||
$entry = $this->createMock(IEntry::class);
|
||||
$entry->expects($this->once())
|
||||
|
|
Loading…
Reference in New Issue