-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix search with categories on translated pages
Results from repositories have the uid of the default language, even when the rest is translated. However, the foreign uid filter for the index table needs the translated uid. Additionally, the category filters are now translated and provided as objects.
- Loading branch information
Showing
7 changed files
with
177 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HDNET\Calendarize\Domain\Repository; | ||
|
||
use TYPO3\CMS\Extbase\Domain\Model\Category; | ||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; | ||
|
||
class CategoryRepository extends AbstractRepository | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->objectType = Category::class; | ||
} | ||
|
||
public function findByIds(array $categoryIds, array $orderings = []): array|QueryResultInterface | ||
{ | ||
$query = $this->createQuery(); | ||
$query->getQuerySettings()->setRespectStoragePage(false); | ||
$query->getQuerySettings()->setRespectSysLanguage(false); | ||
|
||
$query->matching($query->in('uid', $categoryIds)); | ||
|
||
if (!empty($orderings)) { | ||
$query->setOrderings($orderings); | ||
} | ||
|
||
return $query->execute(); | ||
} | ||
} |
This file contains 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 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 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 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
34 changes: 34 additions & 0 deletions
34
Tests/Functional/Domain/Repository/Fixtures/EventsWithCategories.csv
This file contains 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,34 @@ | ||
"pages" | ||
,"uid","pid",doktype,"sorting","deleted","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","title" | ||
,1,0,1,256,0,0,0,0,0,0,"Parent page" | ||
,2,1,254,256,0,0,0,0,0,0,"Events" | ||
,3,2,254,256,0,0,0,0,0,0,"Events with Categories" | ||
|
||
"sys_category", | ||
,"uid","pid","sorting","deleted","sys_language_uid","l10n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","title","parent","items","l10n_diffsource","description" | ||
,28,0,256,0,0,0,0,0,0,0,0,"Category A",0,0,, | ||
,29,0,512,0,0,0,0,0,0,0,0,"Category B",0,0,, | ||
,30,0,768,0,0,0,0,0,0,0,0,"Category C",0,0,, | ||
,31,0,1024,0,0,0,0,0,0,0,0,"Category A.A",28,0,, | ||
|
||
"sys_category_record_mm", | ||
,"uid_local","uid_foreign","tablenames","sorting","sorting_foreign","fieldname" | ||
,28,20,"tx_calendarize_domain_model_event",0,1,"categories" | ||
,28,21,"tx_calendarize_domain_model_event",0,2,"categories" | ||
,29,30,"tx_calendarize_domain_model_event",0,3,"categories" | ||
|
||
"tx_calendarize_domain_model_event" | ||
,uid,pid,sys_language_uid,l10n_parent,title,calendarize,categories | ||
,10,2,0,0,No Category,10,0 | ||
,11,2,1,10,[Translated to German] No Category,11,0 | ||
,20,3,0,0,Only Category A,20,1 | ||
,21,3,1,20,[Translated to German] Only Category A,21,1 | ||
,30,3,0,0,Only Category B,30,0 | ||
|
||
"tx_calendarize_domain_model_configuration" | ||
,"uid","pid","type","handling","start_date","all_day","t3ver_oid","t3ver_wsid","t3ver_state" | ||
,10,2,"time","include","2025-03-01",1,0,0,0 | ||
,11,2,"time","include","2025-03-01",1,0,0,0 | ||
,20,3,"time","include","2025-03-02",1,0,0,0 | ||
,21,3,"time","include","2025-03-02",1,0,0,0 | ||
,30,3,"time","include","2025-03-03",1,0,0,0 |
73 changes: 73 additions & 0 deletions
73
Tests/Functional/Domain/Repository/IndexRepositoryTest.php
This file contains 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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace HDNET\Calendarize\Tests\Functional\Domain\Repository; | ||
|
||
use HDNET\Calendarize\Domain\Repository\IndexRepository; | ||
use HDNET\Calendarize\Register; | ||
use HDNET\Calendarize\Service\IndexerService; | ||
use TYPO3\CMS\Core\Context\Context; | ||
use TYPO3\CMS\Core\Context\LanguageAspect; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class IndexRepositoryTest extends FunctionalTestCase | ||
{ | ||
protected array $testExtensionsToLoad = ['typo3conf/ext/calendarize']; | ||
|
||
protected IndexerService $indexerService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->importCSVDataSet(__DIR__ . '/Fixtures/EventsWithCategories.csv'); | ||
|
||
$this->indexerService = GeneralUtility::makeInstance(IndexerService::class); | ||
$this->indexerService->reindexAll(); | ||
} | ||
|
||
/** | ||
* @dataProvider findBySearchDataProvider | ||
*/ | ||
public function testFindBySearch( | ||
int $language, | ||
?\DateTimeInterface $startDate, | ||
?\DateTimeInterface $endDate, | ||
array $customSearch, | ||
int $limit, | ||
array $expectedEventIds | ||
): void { | ||
$context = GeneralUtility::makeInstance(Context::class); | ||
$context->setAspect('language', new LanguageAspect($language, $language, LanguageAspect::OVERLAYS_ON)); | ||
|
||
$subject = GeneralUtility::makeInstance(IndexRepository::class); | ||
$subject->setIndexTypes([Register::UNIQUE_REGISTER_KEY]); | ||
$subject->setOverridePageIds([2, 3]); | ||
|
||
$result = $subject->findBySearch($startDate, $endDate, $customSearch, $limit)->toArray(); | ||
$eventIds = array_map(static fn ($i) => $i->getForeignUid(), $result); | ||
|
||
self::assertEquals($expectedEventIds, $eventIds); | ||
} | ||
|
||
public static function findBySearchDataProvider(): array | ||
{ | ||
return [ | ||
'no filter' => [0, null, null, [], 0, [10, 20, 30]], | ||
'category' => [0, null, null, ['categories' => ['28']], 0, [20]], | ||
'category translated' => [1, null, null, ['categories' => ['28']], 0, [21]], | ||
'fullText' => [0, null, null, ['fullText' => 'Only'], 0, [20, 30]], | ||
'fullText translated' => [1, null, null, ['fullText' => 'No'], 0, [11]], | ||
'start and end date' => [0, new \DateTime('2025-02-28'), new \DateTime('2025-03-01'), [], 0, [10]], | ||
'dates + categories + text' => [ | ||
0, | ||
new \DateTime('2025-02-28'), | ||
new \DateTime('2025-03-05'), | ||
['categories' => ['28', '29'], 'fullText' => 'B'], | ||
0, | ||
[30], | ||
], | ||
]; | ||
} | ||
} |