mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #2320 from sminnee/fix-1452
MINOR: Add tests for some search-form fixes
This commit is contained in:
commit
26e196de31
65
tests/php/Search/DatabaseSearchEngineTest.php
Normal file
65
tests/php/Search/DatabaseSearchEngineTest.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Tests\Search;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\ORM\Search\FulltextSearchable;
|
||||||
|
|
||||||
|
class DatabaseSearchEngineTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
|
// Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE
|
||||||
|
// MySQL will need a different table type
|
||||||
|
if (static::$tempDB) {
|
||||||
|
static::$tempDB->kill();
|
||||||
|
Config::modify();
|
||||||
|
}
|
||||||
|
FulltextSearchable::enable();
|
||||||
|
static::$tempDB->build();
|
||||||
|
static::resetDBSchema(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that https://github.com/silverstripe/silverstripe-cms/issues/3212 is fixed
|
||||||
|
*/
|
||||||
|
public function testSearchEngineEscapeAs()
|
||||||
|
{
|
||||||
|
$page = new SiteTree();
|
||||||
|
$page->Title = "This page provides food as bar";
|
||||||
|
$page->write();
|
||||||
|
$page->doPublish();
|
||||||
|
|
||||||
|
$results = DB::get_conn()->searchEngine([ SiteTree::class, File::class ], "foo* as* bar*", 0, 100, "\"Relevance\" DESC", "", true);
|
||||||
|
|
||||||
|
$this->assertCount(1, $results);
|
||||||
|
$this->assertEquals(
|
||||||
|
"This page provides food as bar",
|
||||||
|
$results->First()->Title
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that https://github.com/silverstripe/silverstripe-cms/issues/1452 is fixed
|
||||||
|
*/
|
||||||
|
public function testSearchEngineEscapeGreaterThan()
|
||||||
|
{
|
||||||
|
$page = new SiteTree();
|
||||||
|
$page->Title = "Unrelated page";
|
||||||
|
$page->write();
|
||||||
|
$page->doPublish();
|
||||||
|
|
||||||
|
$results = DB::get_conn()->searchEngine([ SiteTree::class, File::class ], "foo>*", 0, 100, "\"Relevance\" DESC", "", true);
|
||||||
|
|
||||||
|
// We're not trying to match this query, just confirm that it successfully executes
|
||||||
|
$this->assertCount(0, $results);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user