mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 12:05:29 +00:00
Namespacing for tests
This commit is contained in:
parent
9aac0ff1aa
commit
ddbab95e3f
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace SilverStripe\FullTextSearch;
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
|
||||
use SilverStripe\View\ViewableData;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
@ -605,95 +606,3 @@ abstract class SearchIndex extends ViewableData
|
||||
*/
|
||||
abstract public function init();
|
||||
}
|
||||
|
||||
/**
|
||||
* A search index that does nothing. Useful for testing
|
||||
*/
|
||||
abstract class SearchIndex_Null extends SearchIndex
|
||||
{
|
||||
public function add($object)
|
||||
{
|
||||
}
|
||||
|
||||
public function delete($base, $id, $state)
|
||||
{
|
||||
}
|
||||
|
||||
public function commit()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A search index that just records actions. Useful for testing
|
||||
*/
|
||||
abstract class SearchIndex_Recording extends SearchIndex
|
||||
{
|
||||
public $added = array();
|
||||
public $deleted = array();
|
||||
public $committed = false;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
23
code/search/SearchIndex_Null.php
Normal file
23
code/search/SearchIndex_Null.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex;
|
||||
|
||||
/**
|
||||
* A search index that does nothing. Useful for testing
|
||||
*/
|
||||
abstract class SearchIndex_Null extends SearchIndex
|
||||
{
|
||||
public function add($object)
|
||||
{
|
||||
}
|
||||
|
||||
public function delete($base, $id, $state)
|
||||
{
|
||||
}
|
||||
|
||||
public function commit()
|
||||
{
|
||||
}
|
||||
}
|
79
code/search/SearchIndex_Recording.php
Normal file
79
code/search/SearchIndex_Recording.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex;
|
||||
|
||||
/**
|
||||
* A search index that just records actions. Useful for testing
|
||||
*/
|
||||
abstract class SearchIndex_Recording extends SearchIndex
|
||||
{
|
||||
public $added = array();
|
||||
public $deleted = array();
|
||||
public $committed = false;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -1,40 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Tests;
|
||||
|
||||
class BatchedProcessorTest_Object extends SiteTree implements TestOnly
|
||||
{
|
||||
private static $db = array(
|
||||
'TestText' => '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}
|
||||
|
15
tests/BatchedProcessorTest/BatchedProcessorTest_Index.php
Normal file
15
tests/BatchedProcessorTest/BatchedProcessorTest_Index.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Tests\BatchedProcessorTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex_Recording;
|
||||
|
||||
class BatchedProcessorTest_Index extends SearchIndex_Recording implements TestOnly
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->addClass('BatchedProcessorTest_Object');
|
||||
$this->addFilterField('TestText');
|
||||
}
|
||||
}
|
13
tests/BatchedProcessorTest/BatchedProcessorTest_Object.php
Normal file
13
tests/BatchedProcessorTest/BatchedProcessorTest_Object.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Tests\BatchedProcessorTest;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class BatchedProcessorTest_Object extends SiteTree implements TestOnly
|
||||
{
|
||||
private static $db = array(
|
||||
'TestText' => 'Varchar'
|
||||
);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Tests\BatchedProcessorTest;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex_Recording;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class SearchUpdaterTest_Container extends DataObject
|
||||
{
|
||||
private static $db = array(
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex_Recording;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class SearchVariantSiteTreeSubsitesPolyhomeTest_Item extends SiteTree
|
||||
{
|
||||
// TODO: Currently theres a failure if you addClass a non-table class
|
||||
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\FullTextSearch\Search\SearchIndex_Recording;
|
||||
|
||||
class SearchVariantVersionedTest extends SapphireTest
|
||||
{
|
||||
/**
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
/**
|
||||
* Test solr 4.0 compatibility
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
if (class_exists('Phockito')) {
|
||||
Phockito::include_hamcrest(false);
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
class SolrIndexTest extends SapphireTest
|
||||
{
|
||||
public function setUpOnce()
|
||||
|
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
|
||||
if (class_exists('Phockito')) {
|
||||
Phockito::include_hamcrest(false);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
|
||||
/**
|
||||
* Additional tests of solr reindexing processes when run with queuedjobs
|
||||
*/
|
||||
|
@ -4,6 +4,10 @@ use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Handler\HandlerInterface;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
|
||||
if (class_exists('Phockito')) {
|
||||
Phockito::include_hamcrest(false);
|
||||
@ -339,7 +343,7 @@ class SolrReindexTest_ItemExtension extends DataExtension implements TestOnly
|
||||
* @param SQLQuery $query
|
||||
* @param DataQuery $dataQuery
|
||||
*/
|
||||
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
|
||||
public function augmentSQL(SilverStripe\ORM\Queries\SQLSelect $query, SilverStripe\ORM\DataQuery $dataQuery = NULL)
|
||||
{
|
||||
$variant = SolrReindexTest_Variant::get_current();
|
||||
if ($variant !== null && !$query->filtersOnID()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user