Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/Service/SocialApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

use OCA\Contacts\AppInfo\Application;
use OCA\Contacts\Service\Social\CompositeSocialProvider;

use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
use OCA\DAV\Db\PropertyMapper;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -24,21 +21,21 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use Psr\Container\ContainerInterface;

class SocialApiService {
private $appName;

public function __construct(
private CompositeSocialProvider $socialProvider,
private ContainerInterface $serverContainer,
private IManager $manager,
private IConfig $config,
private IClientService $clientService,
private IL10N $l10n,
private IURLGenerator $urlGen,
private CardDavBackend $davBackend,
private ITimeFactory $timeFactory,
private ImageResizer $imageResizer,
private PropertyMapper $propertyMapper,
) {
$this->appName = Application::APP_ID;
}
Expand Down Expand Up @@ -116,7 +113,7 @@ protected function getAddressBook(string $addressbookId, ?IManager $manager = nu
* @param {IManager} the contact manager to load
*/
protected function registerAddressbooks($userId, IManager $manager) {
$coma = new ContactsManager($this->davBackend, $this->l10n, $this->propertyMapper);
$coma = $this->serverContainer->get(ContactsManager::class);
$coma->setupContactsProvider($manager, $userId, $this->urlGen);
$this->manager = $manager;
}
Expand Down Expand Up @@ -228,9 +225,8 @@ public function updateContact(string $addressbookId, string $contactId, ?string
*/
public function existsAddressBook(string $searchBookId, string $userId): bool {
$manager = $this->manager;
$coma = new ContactsManager($this->davBackend, $this->l10n, $this->propertyMapper);
$coma = $this->serverContainer->get(ContactsManager::class);
$coma->setupContactsProvider($manager, $userId, $this->urlGen);
$addressBooks = $manager->getUserAddressBooks();
return $this->getAddressBook($searchBookId, $manager) !== null;
}

Expand All @@ -246,7 +242,7 @@ public function existsAddressBook(string $searchBookId, string $userId): bool {
public function existsContact(string $searchContactId, string $searchBookId, string $userId): bool {
// load address books for the user
$manager = $this->manager;
$coma = new ContactsManager($this->davBackend, $this->l10n, $this->propertyMapper);
$coma = $this->serverContainer->get(ContactsManager::class);
$coma->setupContactsProvider($manager, $userId, $this->urlGen);
$addressBook = $this->getAddressBook($searchBookId, $manager);
if ($addressBook == null) {
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/Service/SocialApiServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
namespace OCA\Contacts\Service;

use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Contacts\Service\Social\CompositeSocialProvider;

use OCA\Contacts\Service\Social\CompositeSocialProvider;
use OCA\Contacts\Service\Social\ISocialProvider;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\Db\PropertyMapper;
use OCA\DAV\CardDAV\ContactsManager;

use OCP\AppFramework\Http;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Contacts\IManager;
Expand All @@ -23,9 +23,10 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;

use OCP\Util;

use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;

class SocialApiServiceTest extends TestCase {
private SocialApiService $service;
Expand All @@ -42,14 +43,12 @@ class SocialApiServiceTest extends TestCase {
private $l10n;
/** @var IURLGenerator&MockObject */
private $urlGen;
/** @var CardDavBackend&MockObject */
private $davBackend;
/** @var ITimeFactory&MockObject */
private $timeFactory;
/** @var ImageResizer&MockObject */
private $imageResizer;
/** @var PropertyMapper&MockObject */
private $propertyMapper;
/** @var ContainerInterface&MockObject */
private $container;

public function allSocialProfileProviders(): array {
$body = 'the body';
Expand Down Expand Up @@ -113,21 +112,22 @@ protected function setUp(): void {
$this->clientService = $this->createMock(IClientService::class);
$this->l10n = $this->createMock(IL10N::class);
$this->urlGen = $this->createMock(IURLGenerator::class);
$this->davBackend = $this->createMock(CardDavBackend::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->imageResizer = $this->createMock(ImageResizer::class);
$this->propertyMapper = $this->createMock(PropertyMapper::class);
$this->container = $this->createMock(ContainerInterface::class);
$this->container
->method('get')
->willReturn($this->createMock(ContactsManager::class));
$this->service = new SocialApiService(
$this->socialProvider,
$this->container,
$this->manager,
$this->config,
$this->clientService,
$this->l10n,
$this->urlGen,
$this->davBackend,
$this->timeFactory,
$this->imageResizer,
$this->propertyMapper,
);
}

Expand Down