Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add functional tests for indexed_search
Added tests for: - indexing contents and words - a basic search - metaphone search Resolves: #97732 Releases: main, 12.4 Change-Id: Id56e09f129de4bd13092f584e97eedc9fd326b5c Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79737 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
Showing
3 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
typo3/sysext/indexed_search/Tests/Functional/Fixtures/Indexer/index_dataset.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,145 @@ | ||
index_words | ||
,"wid","baseword","metaphone","is_stopword" | ||
,"1207810","lacus","101783064","0" | ||
,"11850619","venenatis","142749675","0" | ||
,"13375323","a","133977639","0" | ||
,"16210397","leo","220252908","0" | ||
,"17257325","augue","103931454","0" | ||
,"20132824","cras","19564167","0" | ||
,"20667390","in","210169357","0" | ||
,"21729028","non","147598962","0" | ||
,"24597578","sed","248046973","0" | ||
,"28584654","pretium","79383008","0" | ||
,"33219623","eleifend","248177785","0" | ||
,"36278244","egestas","262128669","0" | ||
,"37117712","viverra","197636875","0" | ||
,"56138914","suspendisse","33046219","0" | ||
,"59538215","placerat","45931561","0" | ||
,"60747557","eros","31979501","0" | ||
,"62376532","rutrum","306733","0" | ||
,"73488389","magna","34571788","0" | ||
,"75666210","eu","61073920","0" | ||
,"79133185","elit","129191514","0" | ||
,"79986866","consectetur","81553681","0" | ||
,"81346246","semper","195084738","0" | ||
,"89733790","condimentum","124812234","0" | ||
,"97965025","dignissim.","249574104","0" | ||
,"98995368","vel","180819856","0" | ||
,"103344447","fringilla","156371528","0" | ||
,"107766989","justo","212713437","0" | ||
,"109729132","pellentesque","43457860","0" | ||
,"114079424","aliquam","144755614","0" | ||
,"115288844","pulvinar","157101420","0" | ||
,"123467403","mauris","22363898","0" | ||
,"128507025","hendrerit","140651248","0" | ||
,"131128120","at","262694984","0" | ||
,"133802371","amet","154154951","0" | ||
,"136108712","mattis","214599039","0" | ||
,"136179624","odio","92527841","0" | ||
,"136880505","sapien","102039870","0" | ||
,"139833853","vitae","31651947","0" | ||
,"142314578","sagittis","99879193","0" | ||
,"142429931","sit","248046973","0" | ||
,"143469417","neque","154416985","0" | ||
,"149006214","aliquet","144689851","0" | ||
,"155617720","luctus","117852334","0" | ||
,"157225862","nullam","125585217","0" | ||
,"168987818","donec","11662837","0" | ||
,"176274035","quam","232030450","0" | ||
,"177771293","dolor","78952025","0" | ||
,"182569414","commodo","268310939","0" | ||
,"183515889","suscipit","149980127","0" | ||
,"186277157","ut","142455148","0" | ||
,"188135064","scelerisque","164136945","0" | ||
,"192985975","id","215163142","0" | ||
,"196709710","quis","171062627","0" | ||
,"198257199","feugiat","81566898","0" | ||
,"198421915","tortor","19193031","0" | ||
,"198812305","sem","81843446","0" | ||
,"199215818","nulla","127304526","0" | ||
,"213120199","consequat","68737813","0" | ||
,"221124326","lorem","37044109","0" | ||
,"223612826","adipiscing","221862699","0" | ||
,"230833863","posuere","162503667","0" | ||
,"231731486","morbi","69282823","0" | ||
,"231975571","ullamcorper","9854148","0" | ||
,"232842899","proin","150842452","0" | ||
,"233657728","vehicula","102794977","0" | ||
,"237008199","ac","103931454","0" | ||
,"242808131","ipsum","35014743","0" | ||
,"255122571","phasellus","167211593","0" | ||
,"264875202","fermentum","61273389","0" | ||
index_phash | ||
,"phash","phash_grouping","static_page_arguments","data_filename","data_page_id","data_page_type","data_page_mp","gr_list","item_type","item_title","item_description","item_size","contentHash","sys_language_uid","externalUrl","recordUid","freeIndexUid","freeIndexSetId" | ||
,"217146713","29264104","","","1","0","","0,-1","0","Lorem Ipsum","Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut luctus fringilla tortor sit amet feugiat. Sed mattis semper sapien, in eleifend quam condimentum vel. Aliquam pellentesque feugiat ipsum sed","928","179727944","0","0","0","0","0" | ||
index_rel | ||
,"phash","wid","count","first","freq","flags" | ||
,"217146713","221124326","4","0","12075","128" | ||
,"217146713","242808131","3","0","9056","128" | ||
,"217146713","177771293","2","2","6037","0" | ||
,"217146713","142429931","2","3","6037","0" | ||
,"217146713","133802371","2","4","6037","0" | ||
,"217146713","79986866","1","5","3018","0" | ||
,"217146713","223612826","1","6","3018","0" | ||
,"217146713","79133185","1","7","3018","0" | ||
,"217146713","186277157","2","8","6037","0" | ||
,"217146713","155617720","2","9","6037","0" | ||
,"217146713","103344447","3","10","9056","0" | ||
,"217146713","198421915","1","11","3018","0" | ||
,"217146713","198257199","3","14","9056","0" | ||
,"217146713","24597578","5","15","15094","0" | ||
,"217146713","136108712","1","16","3018","0" | ||
,"217146713","81346246","1","17","3018","0" | ||
,"217146713","136880505","2","18","6037","0" | ||
,"217146713","20667390","2","19","6037","0" | ||
,"217146713","33219623","1","20","3018","0" | ||
,"217146713","176274035","2","21","6037","0" | ||
,"217146713","89733790","2","22","6037","0" | ||
,"217146713","98995368","2","23","6037","0" | ||
,"217146713","114079424","2","24","6037","0" | ||
,"217146713","109729132","1","25","3018","0" | ||
,"217146713","230833863","1","29","3018","0" | ||
,"217146713","231731486","1","30","3018","0" | ||
,"217146713","115288844","1","31","3018","0" | ||
,"217146713","60747557","2","32","6037","0" | ||
,"217146713","131128120","1","33","3018","0" | ||
,"217146713","264875202","1","34","3018","0" | ||
,"217146713","231975571","3","35","9056","0" | ||
,"217146713","123467403","1","36","3018","0" | ||
,"217146713","198812305","2","37","6037","0" | ||
,"217146713","37117712","1","38","3018","0" | ||
,"217146713","149006214","2","40","6037","0" | ||
,"217146713","213120199","2","41","6037","0" | ||
,"217146713","199215818","1","42","3018","0" | ||
,"217146713","17257325","1","43","3018","0" | ||
,"217146713","75666210","1","44","3018","0" | ||
,"217146713","59538215","1","47","3018","0" | ||
,"217146713","16210397","2","48","6037","0" | ||
,"217146713","142314578","1","50","3018","0" | ||
,"217146713","183515889","1","51","3018","0" | ||
,"217146713","73488389","1","52","3018","0" | ||
,"217146713","1207810","1","53","3018","0" | ||
,"217146713","11850619","2","54","6037","0" | ||
,"217146713","143469417","5","55","15094","0" | ||
,"217146713","196709710","1","56","3018","0" | ||
,"217146713","21729028","1","60","3018","0" | ||
,"217146713","192985975","1","65","3018","0" | ||
,"217146713","182569414","1","67","3018","0" | ||
,"217146713","20132824","1","68","3018","0" | ||
,"217146713","13375323","1","69","3018","0" | ||
,"217146713","128507025","2","70","6037","0" | ||
,"217146713","232842899","1","72","3018","0" | ||
,"217146713","233657728","1","73","3018","0" | ||
,"217146713","28584654","1","74","3018","0" | ||
,"217146713","139833853","1","76","3018","0" | ||
,"217146713","107766989","1","78","3018","0" | ||
,"217146713","168987818","1","81","3018","0" | ||
,"217146713","237008199","1","84","3018","0" | ||
,"217146713","188135064","1","86","3018","0" | ||
,"217146713","56138914","1","87","3018","0" | ||
,"217146713","36278244","1","89","3018","0" | ||
,"217146713","136179624","1","90","3018","0" | ||
,"217146713","62376532","1","92","3018","0" | ||
,"217146713","255122571","1","96","3018","0" | ||
,"217146713","157225862","1","100","3018","0" | ||
,"217146713","97965025","1","103","3018","0" |
125 changes: 125 additions & 0 deletions
125
typo3/sysext/indexed_search/Tests/Functional/IndexSearchRepositoryTest.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,125 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\IndexedSearch\Tests\Functional; | ||
|
||
use TYPO3\CMS\Core\Context\Context; | ||
use TYPO3\CMS\Core\Context\UserAspect; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository; | ||
use TYPO3\CMS\IndexedSearch\Indexer; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
final class IndexSearchRepositoryTest extends FunctionalTestCase | ||
{ | ||
protected $coreExtensionsToLoad = [ | ||
'indexed_search', | ||
]; | ||
|
||
/** | ||
* Indexes a "Lorem Ipsum"-page | ||
* and adds a UserAspect to the context providing a "grlist" used in | ||
* @see IndexSearchRepository::$frontendUserGroupList. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
parent::setUp(); | ||
$indexer = new Indexer(); | ||
$indexer->init([ | ||
'id' => 1, | ||
'type' => 0, | ||
'MP' => '', | ||
'staticPageArguments' => null, | ||
'sys_language_uid' => 0, | ||
'gr_list' => '0,-1', | ||
'recordUid' => null, | ||
'freeIndexUid' => null, | ||
'freeIndexSetId' => null, | ||
'index_descrLgd' => 200, | ||
'index_metatags' => true, | ||
'index_externals' => false, | ||
'mtime' => time(), | ||
'crdate' => time(), | ||
'metaCharset' => 'UTF-8', | ||
'content' => | ||
'<html> | ||
<head> | ||
<title>Lorem Ipsum</title> | ||
</head> | ||
<body> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut luctus fringilla tortor sit amet feugiat. Sed mattis semper sapien, in eleifend quam condimentum vel. Aliquam pellentesque feugiat ipsum sed posuere. Morbi pulvinar, eros at fermentum ullamcorper, mauris sem viverra eros, aliquet consequat nulla augue eu sem. Ut placerat, leo sed sagittis suscipit, magna lacus venenatis neque, quis venenatis neque lorem non leo. Sed ullamcorper lorem id ullamcorper commodo. Cras a hendrerit neque. Proin vehicula pretium neque, vitae feugiat justo consequat aliquam. Donec fringilla dolor ac fringilla scelerisque. Suspendisse condimentum egestas odio, vel rutrum neque aliquet sed. Phasellus in sapien quam. Nullam luctus hendrerit dignissim. | ||
</body> | ||
</html>', | ||
'indexedDocTitle' => '', | ||
]); | ||
$indexer->indexerConfig['debugMode'] = false; | ||
$indexer->indexTypo3PageContent(); | ||
GeneralUtility::makeInstance(Context::class)->setAspect('frontend.user', new UserAspect(null, [0, -1])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function doSearchReturnsLoremIpsumResults(): void | ||
{ | ||
$searchRepository = $this->getSearchRepository(); | ||
$searchResults = $searchRepository->doSearch([['sword' => 'lorem']], -1); | ||
self::assertIsArray($searchResults['resultRows'] ?? false); | ||
self::assertCount(1, $searchResults['resultRows']); | ||
self::assertStringContainsStringIgnoringCase('lorem', $searchResults['resultRows'][0]['item_description']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function doSearchProperlyQuotesSearchWord(): void | ||
{ | ||
$searchRepository = $this->getSearchRepository(); | ||
$searchResults = $searchRepository->doSearch([['sword' => 'l%rem']], -1); | ||
self::assertIsNotArray($searchResults['resultRows'] ?? false); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function doSearchReturnsLurimIpasomResultsWithMetaphoneSearch(): void | ||
{ | ||
$searchRepository = $this->getSearchRepository(10); | ||
$searchResults = $searchRepository->doSearch([['sword' => 'lurim']], -1); | ||
self::assertTrue(isset($searchResults['resultRows'])); | ||
self::assertCount(1, $searchResults['resultRows']); | ||
self::assertStringContainsStringIgnoringCase('lorem', $searchResults['resultRows'][0]['item_description']); | ||
} | ||
|
||
private function getSearchRepository($searchType = 1): IndexSearchRepository | ||
{ | ||
$searchRepository = GeneralUtility::makeInstance(IndexSearchRepository::class); | ||
$searchRepositoryDefaultOptions = [ | ||
'defaultOperand' => 0, | ||
'sections' => 0, | ||
'mediaType' => -1, | ||
'sortOrder' => 'rank_flag', | ||
'languageUid' => 'current', | ||
'sortDesc' => 1, | ||
'searchType' => $searchType, | ||
'extResume' => 1, | ||
]; | ||
$searchRepository->initialize([], $searchRepositoryDefaultOptions, [], '-1'); | ||
return $searchRepository; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
typo3/sysext/indexed_search/Tests/Functional/IndexerTest.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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\IndexedSearch\Tests\Functional; | ||
|
||
use TYPO3\CMS\IndexedSearch\Indexer; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
final class IndexerTest extends FunctionalTestCase | ||
{ | ||
protected $coreExtensionsToLoad = [ | ||
'indexed_search', | ||
]; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function indexerIndexesLoremIpsumContent(): void | ||
{ | ||
$indexer = new Indexer(); | ||
$indexer->init([ | ||
'id' => 1, | ||
'type' => 0, | ||
'MP' => '', | ||
'staticPageArguments' => null, | ||
'sys_language_uid' => 0, | ||
'gr_list' => '0,-1', | ||
'recordUid' => null, | ||
'freeIndexUid' => null, | ||
'freeIndexSetId' => null, | ||
'index_descrLgd' => 200, | ||
'index_metatags' => true, | ||
'index_externals' => false, | ||
'mtime' => time(), | ||
'crdate' => time(), | ||
'metaCharset' => 'UTF-8', | ||
'content' => | ||
'<html> | ||
<head> | ||
<title>Lorem Ipsum</title> | ||
</head> | ||
<body> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut luctus fringilla tortor sit amet feugiat. Sed mattis semper sapien, in eleifend quam condimentum vel. Aliquam pellentesque feugiat ipsum sed posuere. Morbi pulvinar, eros at fermentum ullamcorper, mauris sem viverra eros, aliquet consequat nulla augue eu sem. Ut placerat, leo sed sagittis suscipit, magna lacus venenatis neque, quis venenatis neque lorem non leo. Sed ullamcorper lorem id ullamcorper commodo. Cras a hendrerit neque. Proin vehicula pretium neque, vitae feugiat justo consequat aliquam. Donec fringilla dolor ac fringilla scelerisque. Suspendisse condimentum egestas odio, vel rutrum neque aliquet sed. Phasellus in sapien quam. Nullam luctus hendrerit dignissim. | ||
</body> | ||
</html>', | ||
'indexedDocTitle' => '', | ||
]); | ||
$indexer->indexerConfig['debugMode'] = false; | ||
$indexer->indexTypo3PageContent(); | ||
|
||
self::assertCSVDataSet(__DIR__ . '/Fixtures/Indexer/index_dataset.csv'); | ||
} | ||
} |