Merge remote-tracking branch 'origin/develop' into feature/134-allow-header-element-to-be-indexed

This commit is contained in:
Daniel Siepmann 2018-03-16 17:28:56 +01:00
commit bb10f4f5d6
4 changed files with 51 additions and 19 deletions

View file

@ -80,8 +80,14 @@ class PagesIndexer extends TcaIndexer
protected function fetchContentForPage(int $uid) : array
{
if ($this->contentTableService instanceof TcaTableService) {
$contentElements = $this->contentTableService->getQuery()
->execute()->fetchAll();
$queryBuilder = $this->contentTableService->getQuery();
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
$this->contentTableService->getTableName() . '.pid',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
)
);
$contentElements = $queryBuilder->execute()->fetchAll();
} else {
$contentElements = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
$this->contentTableService->getFields(),

View file

@ -49,12 +49,11 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertArraySubset(
['_source' => ['header' => 'indexed content element']],
$response->getData()['hits']['hits'][1],
false,
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
$this->assertSame(
'indexed content element',
$response->getData()['hits']['hits'][2]['_source']['header'],
'Record was not indexed.'
);
}
@ -72,7 +71,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document was indexed.');
$this->assertArraySubset(
['_source' => ['header' => 'indexed content element']],
@ -112,8 +111,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
}
/**
@ -135,8 +134,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
$response = $this->client->request('typo3content/_search?q=uid:11');
$this->assertArraySubset(
['_source' => ['header' => 'Also indexable record']],
@ -167,8 +166,8 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertTrue($response->isOK(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 4, 'Not exactly 4 documents were indexed.');
$this->assertTrue($response->isOk(), 'Elastica did not answer with ok code.');
$this->assertSame($response->getData()['hits']['total'], 5, 'Not exactly 5 documents were indexed.');
$response = $this->client->request('typo3content/_search?q=uid:11');
$this->assertArraySubset(
@ -209,7 +208,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
/**
* @test
*/
public function indexingDeltedRecordIfRecordShouldBeIndexedButIsNoLongerAvailableAndWasAlreadyIndexed()
public function indexingDeletedRecordIfRecordShouldBeIndexedButIsNoLongerAvailableAndWasAlreadyIndexed()
{
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
->get(IndexerFactory::class)
@ -218,7 +217,7 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents were indexed.');
if ($this->isLegacyVersion()) {
$this->getDatabaseConnection()
@ -239,6 +238,6 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document is in index.');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 document is in index.');
}
}

View file

@ -99,4 +99,31 @@
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<tt_content>
<uid>100</uid>
<pid>2</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>header</CType>
<header>Indexed on page 2</header>
<bodytext>This element is on a different page</bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>0</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<pages>
<uid>2</uid>
<pid>1</pid>
<title>Second page with content</title>
<description>Used to check whether content is indexed only for parent page.</description>
</pages>
</dataset>

View file

@ -48,7 +48,7 @@ class PagesIndexerTest extends AbstractFunctionalTestCase
->with(
$this->stringContains($tableName),
$this->callback(function ($documents) {
return count($documents) === 1
return count($documents) === 2
&& isset($documents[0]['content']) && $documents[0]['content'] ===
'indexed content element' .
' this is the content of header content element that should get indexed' .