From ddbab95e3f9224f40c8eda4b3164ed55ee29df0a Mon Sep 17 00:00:00 2001 From: Brett Tasker Date: Fri, 21 Apr 2017 12:23:27 +1200 Subject: [PATCH] Namespacing for tests --- code/search/FullTextSearch.php | 2 + code/search/SearchIndex.php | 95 +------------------ code/search/SearchIndex_Null.php | 23 +++++ code/search/SearchIndex_Recording.php | 79 +++++++++++++++ code/solr/SolrIndex.php | 2 +- tests/BatchedProcessorTest.php | 37 +------- .../BatchedProcessorTest_Index.php | 15 +++ .../BatchedProcessorTest_Object.php | 13 +++ .../BatchedProcessor_QueuedJobService.php | 22 +++++ tests/SearchUpdaterTest.php | 4 + ...rchVariantSiteTreeSubsitesPolyhomeTest.php | 4 + tests/SearchVariantVersionedTest.php | 5 + tests/Solr4ServiceTest.php | 2 + tests/SolrIndexSubsitesTest.php | 2 + tests/SolrIndexTest.php | 3 + tests/SolrIndexVersionedTest.php | 4 + tests/SolrReindexQueuedTest.php | 2 + tests/SolrReindexTest.php | 6 +- 18 files changed, 191 insertions(+), 129 deletions(-) create mode 100644 code/search/SearchIndex_Null.php create mode 100644 code/search/SearchIndex_Recording.php create mode 100644 tests/BatchedProcessorTest/BatchedProcessorTest_Index.php create mode 100644 tests/BatchedProcessorTest/BatchedProcessorTest_Object.php create mode 100644 tests/BatchedProcessorTest/BatchedProcessor_QueuedJobService.php diff --git a/code/search/FullTextSearch.php b/code/search/FullTextSearch.php index 636bbaa..b419d25 100644 --- a/code/search/FullTextSearch.php +++ b/code/search/FullTextSearch.php @@ -1,5 +1,7 @@ added = array(); - $this->deleted = array(); - $this->committed = false; - } - - public function add($object) - { - $res = array(); - - $res['ID'] = $object->ID; - - foreach ($this->getFieldsIterator() as $name => $field) { - $val = $this->_getFieldValue($object, $field); - $res[$name] = $val; - } - - $this->added[] = $res; - } - - public function getAdded($fields = array()) - { - $res = array(); - - foreach ($this->added as $added) { - $filtered = array(); - foreach ($fields as $field) { - if (isset($added[$field])) { - $filtered[$field] = $added[$field]; - } - } - $res[] = $filtered; - } - - return $res; - } - - public function delete($base, $id, $state) - { - $this->deleted[] = array('base' => $base, 'id' => $id, 'state' => $state); - } - - public function commit() - { - $this->committed = true; - } - - public function getIndexName() - { - return get_class($this); - } - - public function getIsCommitted() - { - return $this->committed; - } - - public function getService() - { - // Causes commits to the service to be redirected back to the same object - return $this; - } -} diff --git a/code/search/SearchIndex_Null.php b/code/search/SearchIndex_Null.php new file mode 100644 index 0000000..961bcb2 --- /dev/null +++ b/code/search/SearchIndex_Null.php @@ -0,0 +1,23 @@ +added = array(); + $this->deleted = array(); + $this->committed = false; + } + + public function add($object) + { + $res = array(); + + $res['ID'] = $object->ID; + + foreach ($this->getFieldsIterator() as $name => $field) { + $val = $this->_getFieldValue($object, $field); + $res[$name] = $val; + } + + $this->added[] = $res; + } + + public function getAdded($fields = array()) + { + $res = array(); + + foreach ($this->added as $added) { + $filtered = array(); + foreach ($fields as $field) { + if (isset($added[$field])) { + $filtered[$field] = $added[$field]; + } + } + $res[] = $filtered; + } + + return $res; + } + + public function delete($base, $id, $state) + { + $this->deleted[] = array('base' => $base, 'id' => $id, 'state' => $state); + } + + public function commit() + { + $this->committed = true; + } + + public function getIndexName() + { + return get_class($this); + } + + public function getIsCommitted() + { + return $this->committed; + } + + public function getService() + { + // Causes commits to the service to be redirected back to the same object + return $this; + } +} diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index bfe7477..8e69c77 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -4,7 +4,7 @@ Solr::include_client_api(); use SilverStripe\Dev\BuildTask; use SilverStripe\Control\Director; -use SilverStripe\FulltextSearch\SearchIndex; +use SilverStripe\FulltextSearch\Search\SearchIndex; abstract class SolrIndex extends SearchIndex { diff --git a/tests/BatchedProcessorTest.php b/tests/BatchedProcessorTest.php index 6978d3e..fcb96b3 100644 --- a/tests/BatchedProcessorTest.php +++ b/tests/BatchedProcessorTest.php @@ -1,40 +1,9 @@ 'Varchar' - ); -} - -class BatchedProcessorTest_Index extends SearchIndex_Recording implements TestOnly -{ - public function init() - { - $this->addClass('BatchedProcessorTest_Object'); - $this->addFilterField('TestText'); - } -} - -class BatchedProcessor_QueuedJobService -{ - protected $jobs = array(); - - public function queueJob(QueuedJob $job, $startAfter = null, $userId = null, $queueName = null) - { - $this->jobs[] = array( - 'job' => $job, - 'startAfter' => $startAfter - ); - return $job; - } - - public function getJobs() - { - return $this->jobs; - } -} +use SilverStripe\Dev\SapphireTest; +use SilverStripe\FullTextSearch\Search\FullTextSearch; /** * Tests {@see SearchUpdateQueuedJobProcessor} diff --git a/tests/BatchedProcessorTest/BatchedProcessorTest_Index.php b/tests/BatchedProcessorTest/BatchedProcessorTest_Index.php new file mode 100644 index 0000000..c62ea6b --- /dev/null +++ b/tests/BatchedProcessorTest/BatchedProcessorTest_Index.php @@ -0,0 +1,15 @@ +addClass('BatchedProcessorTest_Object'); + $this->addFilterField('TestText'); + } +} diff --git a/tests/BatchedProcessorTest/BatchedProcessorTest_Object.php b/tests/BatchedProcessorTest/BatchedProcessorTest_Object.php new file mode 100644 index 0000000..b596a3a --- /dev/null +++ b/tests/BatchedProcessorTest/BatchedProcessorTest_Object.php @@ -0,0 +1,13 @@ + 'Varchar' + ); +} diff --git a/tests/BatchedProcessorTest/BatchedProcessor_QueuedJobService.php b/tests/BatchedProcessorTest/BatchedProcessor_QueuedJobService.php new file mode 100644 index 0000000..1cf5253 --- /dev/null +++ b/tests/BatchedProcessorTest/BatchedProcessor_QueuedJobService.php @@ -0,0 +1,22 @@ +jobs[] = array( + 'job' => $job, + 'startAfter' => $startAfter + ); + return $job; + } + + public function getJobs() + { + return $this->jobs; + } +} diff --git a/tests/SearchUpdaterTest.php b/tests/SearchUpdaterTest.php index d2211c0..9cbb9c8 100644 --- a/tests/SearchUpdaterTest.php +++ b/tests/SearchUpdaterTest.php @@ -1,5 +1,9 @@ filtersOnID()) {