From 299ec3af5eedcb92ddb46528017256cd58e47ed6 Mon Sep 17 00:00:00 2001
From: Daniel Siepmann
Date: Thu, 13 Jul 2017 14:54:37 +0200
Subject: [PATCH] TASK: Add tests covering new pages indexing
Including content and search abstract.
---
Configuration/TypoScript/setup.txt | 9 +++
Tests/Functional/Fixtures/BasicSetup.ts | 16 +++++
Tests/Functional/Fixtures/BasicSetup.xml | 1 +
.../Fixtures/Indexing/IndexTcaTable.xml | 39 +++++++++++
.../Functional/Indexing/PagesIndexerTest.php | 64 +++++++++++++++++++
Tests/Functional/Indexing/TcaIndexerTest.php | 16 ++---
6 files changed, 137 insertions(+), 8 deletions(-)
create mode 100644 Tests/Functional/Indexing/PagesIndexerTest.php
diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt
index e81368e..d77c42e 100644
--- a/Configuration/TypoScript/setup.txt
+++ b/Configuration/TypoScript/setup.txt
@@ -9,6 +9,15 @@ plugin {
}
indexing {
+ # Not for direct indexing therefore no indexer.
+ # Used to configure tt_content fetching while indexing pages
+ tt_content {
+ additionalWhereClause (
+ tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login')
+ AND tt_content.bodytext != ''
+ )
+ }
+
pages {
indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer
additionalWhereClause = {$plugin.tx_searchcore.settings.indexing.pages.additionalWhereClause}
diff --git a/Tests/Functional/Fixtures/BasicSetup.ts b/Tests/Functional/Fixtures/BasicSetup.ts
index e24aee8..1e2b3a9 100644
--- a/Tests/Functional/Fixtures/BasicSetup.ts
+++ b/Tests/Functional/Fixtures/BasicSetup.ts
@@ -12,6 +12,22 @@ plugin {
tt_content {
indexer = Codappix\SearchCore\Domain\Index\TcaIndexer
+ additionalWhereClause (
+ tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login')
+ AND tt_content.bodytext != ''
+ )
+
+ mapping {
+ CType {
+ type = keyword
+ }
+ }
+ }
+
+ pages {
+ indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer
+ abstractFields = abstract, description, bodytext
+
mapping {
CType {
type = keyword
diff --git a/Tests/Functional/Fixtures/BasicSetup.xml b/Tests/Functional/Fixtures/BasicSetup.xml
index a85b72a..1a46f3b 100644
--- a/Tests/Functional/Fixtures/BasicSetup.xml
+++ b/Tests/Functional/Fixtures/BasicSetup.xml
@@ -4,5 +4,6 @@
1
0
Root page containing necessary TypoScript
+ Used as abstract as no abstract is defined.
diff --git a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml
index 75a1f35..ec251ce 100644
--- a/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml
+++ b/Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml
@@ -60,4 +60,43 @@
0
+
+ 9
+ 1
+ 1480686370
+ 1480686370
+ 0
+ 72
+ list
+
+ this is the content of header content element that should not get indexed
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+
+
+
+ 10
+ 1
+ 1480686370
+ 1480686370
+ 0
+ 72
+ html
+ Indexed without html tags
+ Some text in paragraph
]]>
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+
diff --git a/Tests/Functional/Indexing/PagesIndexerTest.php b/Tests/Functional/Indexing/PagesIndexerTest.php
new file mode 100644
index 0000000..d0440ba
--- /dev/null
+++ b/Tests/Functional/Indexing/PagesIndexerTest.php
@@ -0,0 +1,64 @@
+
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
+use Codappix\SearchCore\Connection\Elasticsearch;
+use Codappix\SearchCore\Domain\Index\IndexerFactory;
+use Codappix\SearchCore\Tests\Functional\AbstractFunctionalTestCase;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+
+class PagesIndexerTest extends AbstractFunctionalTestCase
+{
+ /**
+ * @test
+ */
+ public function pagesContainAllAdditionalInformation()
+ {
+ $this->importDataSet('Tests/Functional/Fixtures/Indexing/IndexTcaTable.xml');
+
+ $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class);
+ $tableName = 'pages';
+
+ $connection = $this->getMockBuilder(Elasticsearch::class)
+ ->setMethods(['addDocuments'])
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $connection->expects($this->once())
+ ->method('addDocuments')
+ ->with(
+ $this->stringContains($tableName),
+ $this->callback(function ($documents) {
+ return count($documents) === 1
+ && isset($documents[0]['content']) && $documents[0]['content'] ===
+ 'this is the content of header content element that should get indexed Some text in paragraph'
+ && isset($documents[0]['search_abstract']) && $documents[0]['search_abstract'] ===
+ 'Used as abstract as no abstract is defined.'
+ ;
+ })
+ );
+
+ $indexer = $objectManager->get(IndexerFactory::class)->getIndexer($tableName);
+ $this->inject($indexer, 'connection', $connection);
+ $indexer->indexAllDocuments();
+ }
+}
diff --git a/Tests/Functional/Indexing/TcaIndexerTest.php b/Tests/Functional/Indexing/TcaIndexerTest.php
index 2b3f817..edf1a74 100644
--- a/Tests/Functional/Indexing/TcaIndexerTest.php
+++ b/Tests/Functional/Indexing/TcaIndexerTest.php
@@ -30,6 +30,14 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
class TcaIndexerTest extends AbstractFunctionalTestCase
{
+ protected function getTypoScriptFilesForFrontendRootPage()
+ {
+ return array_merge(
+ parent::getTypoScriptFilesForFrontendRootPage(),
+ ['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
+ );
+ }
+
/**
* @test
*/
@@ -69,12 +77,4 @@ class TcaIndexerTest extends AbstractFunctionalTestCase
$objectManager->get(TcaIndexer::class, $tableService, $connection)->indexAllDocuments();
}
-
- protected function getTypoScriptFilesForFrontendRootPage()
- {
- return array_merge(
- parent::getTypoScriptFilesForFrontendRootPage(),
- ['EXT:search_core/Tests/Functional/Fixtures/Indexing/TcaIndexer/RespectRootLineBlacklist.ts']
- );
- }
}