Skip to content

Commit 3379672

Browse files
committed
[TASK] add test case for hidden translation in content-fallback and strict mode
This change fixes the issue on integration-tests stack. Previously the integration-tests behave different from real TYPO3 application. Multiple tests, where a TYPO3 components with usage of Core-Context did not fail properly, because the core-context was always initialized for a frontend application, but EXT:solr in indexing context always uses Command or Backend applications. So in real TYPO3 applications the `visibility` aspect was always set to show hidden/disabled records, but on test-stack not... It adds the missing test case for hidden translations in modies: ### In content-fallback mode: 1. The translated and not hidden record must be shown in FE and Search 2. The translated but hidden record must be shown as replaced by original in FE and Search 3. The record without translation must be shown and replaced by original in FE and Search ### In strict mode: 1. The translated and not hidden record must be shown in FE and Search 2. The translated but hidden record must NOT be shown in FE and Search 3. The record without translation must NOT be shown in FE and Search Relates: #4427, #4409
1 parent 9cd2ddc commit 3379672

8 files changed

+339
-45
lines changed

Tests/Integration/Extbase/PersistenceEventListenerTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase;
2222
use Doctrine\DBAL\Exception as DBALException;
2323
use PHPUnit\Framework\Attributes\Test;
24-
use TYPO3\CMS\Core\Context\Context;
25-
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
24+
use TYPO3\CMS\Backend\Utility\BackendUtility;
2625
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
2726
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
2827
use TYPO3\CMS\Core\Http\ServerRequest;
@@ -106,7 +105,6 @@ public function newHiddenEntityIsNotAddedToIndexQueue(): void
106105
}
107106

108107
/**
109-
* @throws AspectNotFoundException
110108
* @throws UnknownObjectException
111109
* @throws IllegalObjectTypeException
112110
* @throws DBALException
@@ -115,21 +113,20 @@ public function newHiddenEntityIsNotAddedToIndexQueue(): void
115113
public function updatedEntityIsUpdatedInIndexQueue(): void
116114
{
117115
$this->importCSVDataSet(__DIR__ . '/Fixtures/update_items.csv');
116+
118117
/** @var Foo $object */
119118
$object = $this->repository->findByUid(2);
120119
$object->setTitle('Updated');
121120
$this->repository->update($object);
122121
$this->persistenceManager->persistAll();
123122

124-
/** @var Context $context */
125-
$context = GeneralUtility::makeInstance(Context::class);
126-
$currentTimestamp = $context->getPropertyFromAspect('date', 'timestamp');
127-
128123
self::assertTrue($this->indexQueue->containsItem('tx_fakeextension_domain_model_foo', 2));
129124

130125
$item = $this->indexQueue->getItem(1);
131126
self::assertSame(2, $item->getRecordUid());
132127
self::assertSame('foo', $item->getIndexingConfigurationName());
128+
// the times must be identical on `..._foo`.`tstamp` and `Item`::`changed`
129+
$currentTimestamp = BackendUtility::getRecord('tx_fakeextension_domain_model_foo', 2)['tstamp'];
133130
self::assertSame($currentTimestamp, $item->getChanged());
134131
}
135132

Tests/Integration/IndexQueue/Fixtures/can_index_custom_translated_record_with_l_param.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
,2,0,1,1,1,1,"/","hallo solr"
55
"tx_fakeextension_domain_model_bar",
66
,"uid","pid","title","sys_language_uid","l10n_parent"
7-
,88,1,"original",0,0
8-
,89,1,"translation",1,88
9-
,777,1,"original2",0,0
10-
,9999,1,"translation2",1,777
7+
,8,1,"original",0,0
8+
,88,1,"translation",1,8
9+
,7,1,"original2",0,0
10+
,77,1,"translation2",1,7
1111
"sys_template",
1212
,"uid","pid","root","clear","sorting","config"
1313
,1,1,1,3,100,"

Tests/Integration/IndexQueue/Fixtures/can_index_custom_translated_record_without_l_param.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
,2,0,1,1,1,1,"/","hallo solr"
55
"tx_fakeextension_domain_model_bar",
66
,"uid","pid","title","sys_language_uid","l10n_parent"
7-
,88,1,"original",0,0
8-
,99,1,"translation",1,88
9-
,777,1,"original2",0,0
10-
,9999,1,"translation2",1,777
7+
,8,1,"original",0,0
8+
,88,1,"translation",1,8
9+
,7,1,"original2",0,0
10+
,77,1,"translation2",1,7
1111
"sys_template",
1212
,"uid","pid","root","clear","sorting","config"
1313
,1,1,1,3,100,"

Tests/Integration/IndexQueue/Fixtures/can_index_custom_translated_record_without_l_param_and_content_fallback.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
,1,0,1,1,0,0,"/","hello solr"
44
"tx_fakeextension_domain_model_bar",
55
,"uid","pid","title","sys_language_uid","l10n_parent"
6-
,88,1,"original",0,0
7-
,777,1,"original2",0,0
6+
,8,1,"original",0,0
7+
,7,1,"original2",0,0
88
"sys_template",
99
,"uid","pid","root","clear","sorting","config"
1010
,1,1,1,3,100,"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"pages",
2+
,"uid","pid","is_siteroot","doktype","sys_language_uid","l10n_parent","slug","title"
3+
,1,0,1,1,0,0,"/","hello solr"
4+
,2,0,1,1,1,1,"/","hallo solr"
5+
"tx_fakeextension_domain_model_bar",
6+
,"uid","pid","title","sys_language_uid","l10n_parent","hidden"
7+
,7,1,"original",0,0,0
8+
,8,1,"original2",0,0,0
9+
,9,1,"original3",0,0,0
10+
,77,1,"translated",1,7,0
11+
,88,1,"translated2",1,8,1
12+
"sys_template",
13+
,"uid","pid","root","clear","sorting","config"
14+
,1,1,1,3,100,"
15+
page = PAGE
16+
page.typeNum = 0
17+
18+
# very simple rendering
19+
page.10 = CONTENT
20+
page.10 {
21+
table = tt_content
22+
select.orderBy = sorting
23+
select.where = colPos=0
24+
renderObj = COA
25+
renderObj {
26+
10 = TEXT
27+
10.field = bodytext
28+
}
29+
}
30+
31+
plugin.tx_solr {
32+
enabled = 1
33+
index {
34+
fieldProcessingInstructions {
35+
changed = timestampToIsoDate
36+
created = timestampToIsoDate
37+
endtime = timestampToUtcIsoDate
38+
rootline = pageUidToHierarchy
39+
pageHierarchy_stringM = pathToHierarchy
40+
}
41+
42+
queue {
43+
foo = 1
44+
foo {
45+
type = tx_fakeextension_domain_model_bar
46+
fields {
47+
title = title
48+
url = TEXT
49+
url {
50+
typolink.parameter = 1
51+
typolink.additionalParams = &tx_foo[uid]={field:uid}
52+
typolink.additionalParams.insertData = 1
53+
typolink.returnLast = url
54+
typolink.forceAbsoluteUrl = 1
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"pages",
2+
,"uid","pid","is_siteroot","doktype","sys_language_uid","l10n_parent","slug","title"
3+
,1,0,1,1,0,0,"/","hello solr"
4+
,2,0,1,1,2,1,"/","hej solr"
5+
"tx_fakeextension_domain_model_bar",
6+
,"uid","pid","title","sys_language_uid","l10n_parent","hidden"
7+
,7,1,"original",0,0,0
8+
,8,1,"original2",0,0,0
9+
,9,1,"original3",0,0,0
10+
,77,1,"translated",2,7,0
11+
,88,1,"translated2",2,8,1
12+
"sys_template",
13+
,"uid","pid","root","clear","sorting","config"
14+
,1,1,1,3,100,"
15+
page = PAGE
16+
page.typeNum = 0
17+
18+
# very simple rendering
19+
page.10 = CONTENT
20+
page.10 {
21+
table = tt_content
22+
select.orderBy = sorting
23+
select.where = colPos=0
24+
renderObj = COA
25+
renderObj {
26+
10 = TEXT
27+
10.field = bodytext
28+
}
29+
}
30+
31+
plugin.tx_solr {
32+
enabled = 1
33+
index {
34+
fieldProcessingInstructions {
35+
changed = timestampToIsoDate
36+
created = timestampToIsoDate
37+
endtime = timestampToUtcIsoDate
38+
rootline = pageUidToHierarchy
39+
pageHierarchy_stringM = pathToHierarchy
40+
}
41+
42+
queue {
43+
foo = 1
44+
foo {
45+
type = tx_fakeextension_domain_model_bar
46+
fields {
47+
title = title
48+
url = TEXT
49+
url {
50+
typolink.parameter = 1
51+
typolink.additionalParams = &tx_foo[uid]={field:uid}
52+
typolink.additionalParams.insertData = 1
53+
typolink.returnLast = url
54+
typolink.forceAbsoluteUrl = 1
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}"

Tests/Integration/IndexQueue/IndexerTest.php

Lines changed: 133 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace ApacheSolrForTypo3\Solr\Tests\Integration\IndexQueue;
1717

18+
use ApacheSolrForTypo3\Solr\Exception\InvalidArgumentException;
1819
use ApacheSolrForTypo3\Solr\IndexQueue\Indexer;
1920
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
2021
use ApacheSolrForTypo3\Solr\IndexQueue\Queue;
@@ -107,48 +108,153 @@ public static function getTranslatedRecordDataProvider(): Traversable
107108
{
108109
yield 'with_l_parameter' => [
109110
'fixture' => 'can_index_custom_translated_record_with_l_param.csv',
111+
'queueItems' => [
112+
['tx_fakeextension_domain_model_bar' => 7],
113+
['tx_fakeextension_domain_model_bar' => 8],
114+
],
115+
'assertions' => [
116+
'core_en' => [
117+
'"numFound":2',
118+
'"title":"original"',
119+
'"title":"original2"',
120+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=7',
121+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=8',
122+
],
123+
'core_de' => [
124+
'"numFound":2',
125+
'"title":"translation"',
126+
'"title":"translation2"',
127+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=7',
128+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=8',
129+
],
130+
],
110131
];
111132
yield 'without_l_parameter' => [
112133
'fixture' => 'can_index_custom_translated_record_without_l_param.csv',
134+
'queueItems' => [
135+
['tx_fakeextension_domain_model_bar' => 7],
136+
['tx_fakeextension_domain_model_bar' => 8],
137+
],
138+
'assertions' => [
139+
'core_en' => [
140+
'"numFound":2',
141+
'"title":"original"',
142+
'"title":"original2"',
143+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=7',
144+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=8',
145+
],
146+
'core_de' => [
147+
'"numFound":2',
148+
'"title":"translation"',
149+
'"title":"translation2"',
150+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=7',
151+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=8',
152+
],
153+
],
113154
];
114155
yield 'without_l_parameter_and_content_fallback' => [
115156
'fixture' => 'can_index_custom_translated_record_without_l_param_and_content_fallback.csv',
157+
'queueItems' => [
158+
['tx_fakeextension_domain_model_bar' => 7],
159+
['tx_fakeextension_domain_model_bar' => 8],
160+
],
161+
'assertions' => [
162+
'core_en' => [
163+
'"numFound":2',
164+
'"title":"original"',
165+
'"title":"original2"',
166+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=7',
167+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=8',
168+
],
169+
'core_de' => [
170+
'"numFound":2',
171+
'"title":"original"',
172+
'"title":"original2"',
173+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=7',
174+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=8',
175+
],
176+
],
177+
];
178+
yield 'visible_and_hidden_translation_in_content_fallback' => [
179+
'fixture' => 'can_index_visible_and_hidden_translated_record_in_content_fallback_mode.csv',
180+
'queueItems' => [
181+
['tx_fakeextension_domain_model_bar' => 7],
182+
['tx_fakeextension_domain_model_bar' => 8],
183+
['tx_fakeextension_domain_model_bar' => 9],
184+
],
185+
'assertions' => [
186+
'core_en' => [
187+
'"numFound":3',
188+
'"title":"original"',
189+
'"title":"original2"',
190+
'"title":"original3"',
191+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=7',
192+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=8',
193+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=9',
194+
],
195+
'core_de' => [
196+
'"numFound":3',
197+
'"title":"translated"',
198+
'"title":"original2"', // in content-fallback mode, the hidden translation must be visible in FE in original language.
199+
'"title":"original3"', // in content-fallback mode, the record without translation must be visible in FE in original language.
200+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=7',
201+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=8',
202+
'"url":"http://testone.site/de/?tx_foo%5Buid%5D=9',
203+
],
204+
],
205+
];
206+
yield 'visible_and_hidden_translation_in_strict' => [
207+
'fixture' => 'can_index_visible_and_hidden_translated_record_in_strict_mode.csv',
208+
'queueItems' => [
209+
['tx_fakeextension_domain_model_bar' => 7],
210+
['tx_fakeextension_domain_model_bar' => 8],
211+
['tx_fakeextension_domain_model_bar' => 9],
212+
],
213+
'assertions' => [
214+
'core_en' => [
215+
'"numFound":3',
216+
'"title":"original"',
217+
'"title":"original2"',
218+
'"title":"original3"',
219+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=7',
220+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=8',
221+
'"url":"http://testone.site/en/?tx_foo%5Buid%5D=9',
222+
],
223+
'core_da' => [
224+
'"numFound":1',
225+
'"title":"translated"',
226+
'"url":"http://testone.site/da/?tx_foo%5Buid%5D=7',
227+
],
228+
],
116229
];
117230
}
118231

232+
/**
233+
* @throws InvalidArgumentException
234+
*/
119235
#[DataProvider('getTranslatedRecordDataProvider')]
120236
#[Test]
121-
public function testCanIndexTranslatedCustomRecord(string $fixture): void
122-
{
237+
public function testCanIndexTranslatedCustomRecord(
238+
string $fixture,
239+
array $queueItems,
240+
array $assertions,
241+
): void {
123242
$this->importCSVDataSet(__DIR__ . '/Fixtures/' . $fixture);
124243

125-
$result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88);
126-
self::assertTrue($result, 'Indexing was not indicated to be successful');
127-
128-
$result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 777);
129-
self::assertTrue($result, 'Indexing was not indicated to be successful');
130-
131-
// do we have the record in the index with the value from the mm relation?
132-
$this->waitToBeVisibleInSolr();
133-
$solrContent = file_get_contents($this->getSolrConnectionUriAuthority() . '/solr/core_en/select?q=*:*');
134-
self::assertStringContainsString('"numFound":2', $solrContent, 'Could not index document into solr');
135-
self::assertStringContainsString('"title":"original"', $solrContent, 'Could not index document into solr');
136-
self::assertStringContainsString('"title":"original2"', $solrContent, 'Could not index document into solr');
137-
self::assertStringContainsString('"url":"http://testone.site/en/?tx_foo%5Buid%5D=88', $solrContent, 'Can not build typolink as expected');
138-
self::assertStringContainsString('"url":"http://testone.site/en/?tx_foo%5Buid%5D=777', $solrContent, 'Can not build typolink as expected');
244+
foreach ($queueItems as $queueItemDef) {
245+
$tableName = key($queueItemDef);
246+
$recordUid = current($queueItemDef);
247+
$result = $this->addToQueueAndIndexRecord($tableName, $recordUid);
248+
self::assertTrue($result, "Indexing of $tableName:$recordUid was not indicated to be successful");
249+
}
139250

140-
$this->waitToBeVisibleInSolr('core_de');
141-
$solrContent = file_get_contents($this->getSolrConnectionUriAuthority() . '/solr/core_de/select?q=*:*');
142-
self::assertStringContainsString('"numFound":2', $solrContent, 'Could not find translated record in solr document into solr');
143-
if ($fixture === 'can_index_custom_translated_record_without_l_param_and_content_fallback.csv') {
144-
self::assertStringContainsString('"title":"original"', $solrContent, 'Could not index translated document into solr');
145-
self::assertStringContainsString('"title":"original2"', $solrContent, 'Could not index translated document into solr');
146-
} else {
147-
self::assertStringContainsString('"title":"translation"', $solrContent, 'Could not index translated document into solr');
148-
self::assertStringContainsString('"title":"translation2"', $solrContent, 'Could not index translated document into solr');
251+
foreach ($assertions as $coreName => $containsAssertions) {
252+
$this->waitToBeVisibleInSolr($coreName);
253+
$solrContent = file_get_contents($this->getSolrConnectionUriAuthority() . "/solr/$coreName/select?q=*:*");
254+
foreach ($containsAssertions as $assertion) {
255+
self::assertStringContainsString($assertion, $solrContent);
256+
}
149257
}
150-
self::assertStringContainsString('"url":"http://testone.site/de/?tx_foo%5Buid%5D=88', $solrContent, 'Can not build typolink as expected');
151-
self::assertStringContainsString('"url":"http://testone.site/de/?tx_foo%5Buid%5D=777', $solrContent, 'Can not build typolink as expected');
152258
}
153259

154260
/**

0 commit comments

Comments
 (0)