[TASK] Add functional test for deleteDocuments functionality

This commit is contained in:
Benjamin Serfhos 2018-10-26 09:46:01 +02:00
parent b70dd604fe
commit 23f3d0df92
3 changed files with 186 additions and 2 deletions

View file

@ -209,8 +209,11 @@ class Elasticsearch implements Singleton, ConnectionInterface
);
return;
}
$index->deleteByQuery($query);
$response = $index->deleteByQuery($query);
if ($response->getData()['deleted'] > 0) {
// Refresh index when delete query is invoked
$index->refresh();
}
}
/**

View file

@ -26,6 +26,17 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
class IndexDeletionTest extends AbstractFunctionalTestCase
{
/**
* @return array
*/
protected function getDataSets()
{
return array_merge(
parent::getDataSets(),
['EXT:search_core/Tests/Functional/Fixtures/Indexing/IndexDeletion.xml']
);
}
/**
* @test
*/
@ -47,4 +58,45 @@ class IndexDeletionTest extends AbstractFunctionalTestCase
'Index could not be deleted through command controller.'
);
}
/**
* @test
*/
public function documentsAreDeleted()
{
$index = $this->client->getIndex('typo3content');
$index->create();
$this->assertTrue(
$index->exists(),
'Could not create index for test.'
);
$contentIndexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
->get(IndexerFactory::class)
->getIndexer('tt_content');
$pageIndexer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
->get(IndexerFactory::class)
->getIndexer('pages');
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 0, 'Index should be empty.');
$contentIndexer->indexAllDocuments();
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 3, 'Not exactly 3 documents are in index.');
$pageIndexer->indexAllDocuments();
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 5, 'Not exactly 5 documents are in index.');
$contentIndexer->deleteDocuments();
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents are in index.');
$pageIndexer->deleteDocuments();
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 0, 'Index should be empty.');
$index->delete();
}
}

View file

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<tt_content>
<uid>6</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>header</CType>
<header>indexed content element</header>
<bodytext>this is the content of header content element that should get indexed</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>
<tt_content>
<uid>7</uid>
<pid>1</pid>
<tstamp>1480686371</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>header</CType>
<header>endtime hidden record</header>
<bodytext></bodytext>
<media>0</media>
<layout>0</layout>
<deleted>0</deleted>
<cols>0</cols>
<starttime>0</starttime>
<endtime>1481305963</endtime>
<colPos>0</colPos>
<filelink_sorting>0</filelink_sorting>
</tt_content>
<tt_content>
<uid>8</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>1</hidden>
<sorting>72</sorting>
<CType>header</CType>
<header>Hidden record</header>
<bodytext></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>
<tt_content>
<uid>9</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>div</CType>
<header>not indexed due to ctype</header>
<bodytext>this is the content of div content element that should not get indexed</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>
<tt_content>
<uid>10</uid>
<pid>1</pid>
<tstamp>1480686370</tstamp>
<crdate>1480686370</crdate>
<hidden>0</hidden>
<sorting>72</sorting>
<CType>html</CType>
<header>Indexed without html tags</header>
<bodytext><![CDATA[<p>Some text in paragraph</p>]]></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>
<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>