-
Notifications
You must be signed in to change notification settings - Fork 18
IBX-10735: Leverage new Content Type Search API #1730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
barw4
wants to merge
9
commits into
4.6
Choose a base branch
from
use-findContentTypes-in-content-type-list
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−74
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0462d36
Used new `findContentTypes` PAPI contract in content type list
barw4 b49abd1
Baseline
barw4 28fcaeb
Baseline
barw4 c2ce4e1
Import
barw4 5c20aa9
Unit test
barw4 99773d4
Review remark
barw4 62722f5
Review remark
barw4 3be5332
Fixup
barw4 c3d2767
Review remark
barw4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Pagination\Pagerfanta; | ||
|
||
use Ibexa\Contracts\Core\Repository\ContentTypeService; | ||
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery; | ||
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause\Identifier; | ||
use Pagerfanta\Adapter\AdapterInterface; | ||
|
||
final class ContentTypeListAdapter implements AdapterInterface | ||
{ | ||
private ContentTypeService $contentTypeService; | ||
|
||
private ContentTypeQuery $query; | ||
|
||
/** @var list<string> */ | ||
private array $languages; | ||
|
||
/** | ||
* @param list<string> $languages | ||
*/ | ||
public function __construct( | ||
ContentTypeService $contentTypeService, | ||
array $languages, | ||
?ContentTypeQuery $query = null | ||
) { | ||
$this->contentTypeService = $contentTypeService; | ||
$this->languages = $languages; | ||
$this->query = $query ?? new ContentTypeQuery(null, [new Identifier()]); | ||
} | ||
|
||
public function getNbResults(): int | ||
{ | ||
$query = clone $this->query; | ||
$query->setLimit(0); | ||
|
||
return $this->contentTypeService->findContentTypes($query, $this->languages)->getTotalCount(); | ||
} | ||
|
||
public function getSlice($offset, $length): iterable | ||
{ | ||
$query = clone $this->query; | ||
$query->setOffset($offset); | ||
$query->setLimit($length); | ||
|
||
return $this->contentTypeService->findContentTypes($query, $this->languages)->getIterator(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
tests/lib/Pagination/Pagerfanta/ContentTypeListAdapterTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
<?php | ||||||
|
||||||
/** | ||||||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||||||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||||||
*/ | ||||||
declare(strict_types=1); | ||||||
|
||||||
namespace Ibexa\Tests\AdminUi\Pagination\Pagerfanta; | ||||||
|
||||||
use Ibexa\AdminUi\Pagination\Pagerfanta\ContentTypeListAdapter; | ||||||
use Ibexa\Contracts\Core\Repository\ContentTypeService; | ||||||
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; | ||||||
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery; | ||||||
use Ibexa\Contracts\Core\Repository\Values\ContentType\SearchResult; | ||||||
use PHPUnit\Framework\TestCase; | ||||||
|
||||||
final class ContentTypeListAdapterTest extends TestCase | ||||||
{ | ||||||
/** @var \Ibexa\Contracts\Core\Repository\ContentTypeService&\PHPUnit\Framework\MockObject\MockObject */ | ||||||
private ContentTypeService $contentTypeService; | ||||||
|
||||||
protected function setUp(): void | ||||||
{ | ||||||
$this->contentTypeService = $this->createMock(ContentTypeService::class); | ||||||
} | ||||||
|
||||||
public function testGetNbResults(): void | ||||||
{ | ||||||
$languages = ['en-GB', 'de-DE']; | ||||||
|
||||||
$searchResults = new SearchResult([ | ||||||
'totalCount' => 10, | ||||||
'items' => [], | ||||||
]); | ||||||
|
||||||
$this->contentTypeService | ||||||
->expects(self::once()) | ||||||
->method('findContentTypes') | ||||||
->with(self::isInstanceOf(ContentTypeQuery::class), $languages) | ||||||
->willReturn($searchResults); | ||||||
|
||||||
$adapter = new ContentTypeListAdapter($this->contentTypeService, $languages); | ||||||
|
||||||
self::assertEquals( | ||||||
10, | ||||||
$adapter->getNbResults() | ||||||
); | ||||||
} | ||||||
|
||||||
public function testGetSlice(): void | ||||||
{ | ||||||
$languages = ['en-GB']; | ||||||
$offset = 5; | ||||||
$limit = 25; | ||||||
|
||||||
$item1 = $this->createMock(ContentType::class); | ||||||
$item2 = $this->createMock(ContentType::class); | ||||||
$items = [$item1, $item2]; | ||||||
|
||||||
$searchResults = new SearchResult([ | ||||||
'totalCount' => 2, | ||||||
'items' => $items, | ||||||
]); | ||||||
|
||||||
$this->contentTypeService | ||||||
->expects(self::once()) | ||||||
->method('findContentTypes') | ||||||
->with($this->isInstanceOf(ContentTypeQuery::class), $languages) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may also want to make the check more specific, utilizing self::callback(function (ContentTypeQuery $query): bool {
// ...
return true;
}) constraint.
Suggested change
|
||||||
->willReturn($searchResults); | ||||||
|
||||||
$adapter = new ContentTypeListAdapter($this->contentTypeService, $languages); | ||||||
|
||||||
self::assertEquals( | ||||||
$searchResults->getIterator(), | ||||||
$adapter->getSlice($offset, $limit) | ||||||
); | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertSame
doesn't seem to work, these won't be exactly the same types?