‪TYPO3CMS  ‪main
IndexSearchRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
25 use TYPO3\CMS\IndexedSearch\Indexer;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 final class ‪IndexSearchRepositoryTest extends FunctionalTestCase
30 {
31  protected array ‪$coreExtensionsToLoad = [
32  'indexed_search',
33  ];
34 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $indexer = $this->get(Indexer::class);
44  $indexer->init([
45  'id' => 1,
46  'type' => 0,
47  'MP' => '',
48  'staticPageArguments' => null,
49  'sys_language_uid' => 0,
50  'gr_list' => '0,-1',
51  'recordUid' => null,
52  'freeIndexUid' => null,
53  'freeIndexSetId' => null,
54  'index_descrLgd' => 200,
55  'index_metatags' => true,
56  'index_externals' => false,
57  'mtime' => time(),
58  'crdate' => time(),
59  'content' =>
60  '<html>
61  <head>
62  <title>Lorem Ipsum</title>
63  </head>
64  <body>
65  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.
66  </body>
67  </html>',
68  'indexedDocTitle' => '',
69  ]);
70  $indexer->indexerConfig['debugMode'] = false;
71  $indexer->indexTypo3PageContent();
72  GeneralUtility::makeInstance(Context::class)->setAspect('frontend.user', new ‪UserAspect(null, [0, -1]));
73  }
74 
75  #[Test]
76  public function ‪doSearchReturnsLoremIpsumResults(): void
77  {
78  $searchRepository = $this->‪getSearchRepository();
79  $searchResults = $searchRepository->doSearch([['sword' => 'lorem']], -1);
80  self::assertIsArray($searchResults['resultRows'] ?? false);
81  self::assertCount(1, $searchResults['resultRows']);
82  self::assertStringContainsStringIgnoringCase('lorem', $searchResults['resultRows'][0]['item_description']);
83  }
84 
85  #[Test]
86  public function ‪doSearchProperlyQuotesSearchWord(): void
87  {
88  $searchRepository = $this->‪getSearchRepository();
89  $searchResults = $searchRepository->doSearch([['sword' => 'l%rem']], -1);
90  self::assertIsNotArray($searchResults['resultRows'] ?? false);
91  }
92 
93  private function ‪getSearchRepository(‪SearchType $searchType = SearchType::PART_OF_WORD): ‪IndexSearchRepository
94  {
95  $searchRepository = $this->get(IndexSearchRepository::class);
96  $searchRepositoryDefaultOptions = [
97  'defaultOperand' => 0,
98  'sections' => 0,
99  'mediaType' => -1,
100  'sortOrder' => 'rank_flag',
101  'languageUid' => 'current',
102  'sortDesc' => 1,
103  'searchType' => $searchType->value,
104  'extResume' => 1,
105  ];
106  $searchRepository->‪initialize([], $searchRepositoryDefaultOptions, [], -1);
107  return $searchRepository;
108  }
109 }
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest\getSearchRepository
‪getSearchRepository(SearchType $searchType=SearchType::PART_OF_WORD)
Definition: IndexSearchRepositoryTest.php:93
‪TYPO3\CMS\IndexedSearch\Type\SearchType
‪SearchType
Definition: SearchType.php:24
‪TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository
Definition: IndexSearchRepository.php:43
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\initialize
‪initialize(array $settings, array $searchData, array $externalParsers, int|string $searchRootPageIdList)
Definition: IndexSearchRepository.php:146
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest\setUp
‪setUp()
Definition: IndexSearchRepositoryTest.php:40
‪TYPO3\CMS\IndexedSearch\Tests\Functional
Definition: IndexerTest.php:18
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest\doSearchProperlyQuotesSearchWord
‪doSearchProperlyQuotesSearchWord()
Definition: IndexSearchRepositoryTest.php:86
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: IndexSearchRepositoryTest.php:31
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest\doSearchReturnsLoremIpsumResults
‪doSearchReturnsLoremIpsumResults()
Definition: IndexSearchRepositoryTest.php:76
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexSearchRepositoryTest
Definition: IndexSearchRepositoryTest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37