‪TYPO3CMS  ‪main
IndexerTest.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 Doctrine\DBAL\Exception\UniqueConstraintViolationException;
21 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\CMS\IndexedSearch\Indexer;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪IndexerTest extends FunctionalTestCase
26 {
27  protected array ‪$coreExtensionsToLoad = [
28  'indexed_search',
29  ];
30 
31  #[Test]
32  public function ‪indexerIndexesLoremIpsumContent(): void
33  {
34  $indexer = $this->get(Indexer::class);
35  $indexer->init([
36  'id' => 1,
37  'type' => 0,
38  'MP' => '',
39  'staticPageArguments' => null,
40  'sys_language_uid' => 0,
41  'gr_list' => '0,-1',
42  'recordUid' => null,
43  'freeIndexUid' => null,
44  'freeIndexSetId' => null,
45  'index_descrLgd' => 200,
46  'index_metatags' => true,
47  'index_externals' => false,
48  'mtime' => time(),
49  'crdate' => time(),
50  'content' =>
51  '<html>
52  <head>
53  <title>Lorem Ipsum</title>
54  </head>
55  <body>
56  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.
57  </body>
58  </html>',
59  'indexedDocTitle' => '',
60  ]);
61  $indexer->indexerConfig['debugMode'] = false;
62  $indexer->indexTypo3PageContent();
63  self::assertCSVDataSet(__DIR__ . '/Fixtures/Indexer/index_dataset.csv');
64  }
65 
66  #[Test]
68  {
69  $indexer = $this->get(Indexer::class);
70  $indexer->init([
71  'id' => 1,
72  'type' => 0,
73  'MP' => '',
74  'staticPageArguments' => null,
75  'sys_language_uid' => 0,
76  'gr_list' => '0,-1',
77  'recordUid' => null,
78  'freeIndexUid' => null,
79  'freeIndexSetId' => null,
80  'index_descrLgd' => 200,
81  'index_metatags' => true,
82  'index_externals' => false,
83  'mtime' => time(),
84  'crdate' => time(),
85  'content' =>
86  '<html>
87  <head>
88  <title>Test</title>
89  </head>
90  <body>
91  graf gettogethers abfluss erworbener
92  </body>
93  </html>',
94  'indexedDocTitle' => '',
95  ]);
96  $indexer->indexerConfig['debugMode'] = false;
97 
98  try {
99  $indexer->indexTypo3PageContent();
100  } catch (UniqueConstraintViolationException) {
101  self::fail('Indexer failed to index words with phash collision');
102  }
103  self::assertCSVDataSet(__DIR__ . '/Fixtures/Indexer/phash_collision.csv');
104  }
105 
106  #[Test]
108  {
109  $indexerConfig = [
110  'id' => 1,
111  'type' => 0,
112  'MP' => '',
113  'staticPageArguments' => null,
114  'sys_language_uid' => 0,
115  'gr_list' => '0,-1',
116  'recordUid' => null,
117  'freeIndexUid' => null,
118  'freeIndexSetId' => null,
119  'index_descrLgd' => 200,
120  'index_metatags' => true,
121  'index_externals' => false,
122  'mtime' => time(),
123  'crdate' => time(),
124  'content' =>
125  '<html>
126  <head>
127  <title>Test</title>
128  </head>
129  <body>
130  graf gettogethers abfluss erworbener
131  </body>
132  </html>',
133  'indexedDocTitle' => '',
134  ];
135 
136  $indexer = $this->get(Indexer::class);
137  $indexer->init($indexerConfig);
138  $indexer->indexerConfig['debugMode'] = false;
139  $indexer->indexTypo3PageContent();
140  self::assertCSVDataSet(__DIR__ . '/Fixtures/Indexer/indexing_words_twice_first.csv');
141 
142  $indexer = $this->get(Indexer::class);
143  $indexer->init($indexerConfig);
144  $indexer->indexerConfig['debugMode'] = false;
145  $indexer->forceIndexing = true;
146  $indexer->indexTypo3PageContent();
147  self::assertCSVDataSet(__DIR__ . '/Fixtures/Indexer/indexing_words_twice_second.csv');
148  }
149 }
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexerTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: IndexerTest.php:27
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexerTest\indexerIndexesLoremIpsumContent
‪indexerIndexesLoremIpsumContent()
Definition: IndexerTest.php:32
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexerTest\indexerDoesNotFailForWordsWithPhashCollision
‪indexerDoesNotFailForWordsWithPhashCollision()
Definition: IndexerTest.php:67
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexerTest
Definition: IndexerTest.php:26
‪TYPO3\CMS\IndexedSearch\Tests\Functional
Definition: IndexerTest.php:18
‪TYPO3\CMS\IndexedSearch\Tests\Functional\IndexerTest\indexerBuildsCorrectWordIndexWhenIndexingWordsTwice
‪indexerBuildsCorrectWordIndexWhenIndexingWordsTwice()
Definition: IndexerTest.php:107