Skip to content

Commit

Permalink
EZP-29577: As a developer, I want a API to count user preferences (ez…
Browse files Browse the repository at this point in the history
…systems#2433)

* EZP-29577: As a developer, I want a API to count user preference

* [Integration tests] As a developer, I want a API to count user preference

* [signal slot] As a developer, I want a API to count user preference
  • Loading branch information
mikadamczyk authored and Łukasz Serwatka committed Sep 3, 2018
1 parent 0e016e5 commit c19ff27
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions eZ/Publish/API/Repository/Tests/UserPreferenceServiceTest.php
Expand Up @@ -125,4 +125,19 @@ public function testSetUserPreferenceThrowsInvalidArgumentExceptionOnEmptyName()
$userPreferenceService->setUserPreference([$setStruct]);
/* END: Use Case */
}

/**
* @covers \eZ\Publish\API\Repository\UserPreferenceService::getUserPreferenceCount()
*/
public function testGetUserPreferenceCount()
{
$repository = $this->getRepository();

/* BEGIN: Use Case */
$userPreferenceService = $repository->getUserPreferenceService();
$userPreferenceCount = $userPreferenceService->getUserPreferenceCount();
/* END: Use Case */

$this->assertEquals(5, $userPreferenceCount);
}
}
7 changes: 7 additions & 0 deletions eZ/Publish/API/Repository/UserPreferenceService.php
Expand Up @@ -51,4 +51,11 @@ public function getUserPreference(string $userPreferenceName): UserPreference;
* @return \eZ\Publish\API\Repository\Values\UserPreference\UserPreferenceList
*/
public function loadUserPreferences(int $offset = 0, int $limit = 25): UserPreferenceList;

/**
* Get count of total preferences for currently logged user.
*
* @return int
*/
public function getUserPreferenceCount(): int;
}
Expand Up @@ -171,6 +171,24 @@ public function testLoadUserPreferences()
$this->assertEquals($expectedItems, $userPreferences->items);
}

/**
* @covers \eZ\Publish\Core\Repository\UserPreferenceService::getUserPreferenceCount()
*/
public function testGetUserPreferenceCount()
{
$expectedTotalCount = 10;

$this->userSPIPreferenceHandler
->expects($this->once())
->method('countUserPreferences')
->with(self::CURRENT_USER_ID)
->willReturn($expectedTotalCount);

$APIUserPreference = $this->createAPIUserPreferenceService()->getUserPreferenceCount();

$this->assertEquals($expectedTotalCount, $APIUserPreference);
}

/**
* @return \eZ\Publish\API\Repository\UserPreferenceService|\PHPUnit\Framework\MockObject\MockObject
*/
Expand Down
Expand Up @@ -42,6 +42,12 @@ public function serviceProvider()
'value' => $setStruct->value,
],
],
[
'getUserPreferenceCount',
[],
10,
0,
],
];
}

Expand Down
8 changes: 8 additions & 0 deletions eZ/Publish/Core/SignalSlot/UserPreferenceService.php
Expand Up @@ -65,4 +65,12 @@ public function loadUserPreferences(int $offset = 0, int $limit = 25): UserPrefe
{
return $this->service->loadUserPreferences($offset, $limit);
}

/**
* {@inheritdoc}
*/
public function getUserPreferenceCount(): int
{
return $this->service->getUserPreferenceCount();
}
}

0 comments on commit c19ff27

Please sign in to comment.