1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CMS\Tests\Search; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
7
|
|
|
use SilverStripe\Assets\File; |
8
|
|
|
use SilverStripe\ORM\DB; |
9
|
|
|
use SilverStripe\Core\Config\Config; |
10
|
|
|
use SilverStripe\ORM\Search\FulltextSearchable; |
11
|
|
|
|
12
|
|
|
class DatabaseSearchEngineTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected $usesDatabase = true; |
15
|
|
|
|
16
|
|
|
public static function setUpBeforeClass() |
17
|
|
|
{ |
18
|
|
|
parent::setUpBeforeClass(); |
19
|
|
|
|
20
|
|
|
// Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE |
21
|
|
|
// MySQL will need a different table type |
22
|
|
|
if (static::$tempDB) { |
23
|
|
|
static::$tempDB->kill(); |
24
|
|
|
Config::modify(); |
25
|
|
|
} |
26
|
|
|
FulltextSearchable::enable(); |
27
|
|
|
static::$tempDB->build(); |
28
|
|
|
static::resetDBSchema(true); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Validate that https://github.com/silverstripe/silverstripe-cms/issues/3212 is fixed |
33
|
|
|
*/ |
34
|
|
|
public function testSearchEngineEscapeAs() |
35
|
|
|
{ |
36
|
|
|
$page = new SiteTree(); |
37
|
|
|
$page->Title = "This page provides food as bar"; |
38
|
|
|
$page->write(); |
39
|
|
|
$page->doPublish(); |
40
|
|
|
|
41
|
|
|
$results = DB::get_conn()->searchEngine([ SiteTree::class, File::class ], "foo* as* bar*", 0, 100, "\"Relevance\" DESC", "", true); |
42
|
|
|
|
43
|
|
|
$this->assertCount(1, $results); |
44
|
|
|
$this->assertEquals( |
45
|
|
|
"This page provides food as bar", |
46
|
|
|
$results->First()->Title |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Validate that https://github.com/silverstripe/silverstripe-cms/issues/1452 is fixed |
52
|
|
|
*/ |
53
|
|
|
public function testSearchEngineEscapeGreaterThan() |
54
|
|
|
{ |
55
|
|
|
$page = new SiteTree(); |
56
|
|
|
$page->Title = "Unrelated page"; |
57
|
|
|
$page->write(); |
58
|
|
|
$page->doPublish(); |
59
|
|
|
|
60
|
|
|
$results = DB::get_conn()->searchEngine([ SiteTree::class, File::class ], "foo>*", 0, 100, "\"Relevance\" DESC", "", true); |
61
|
|
|
|
62
|
|
|
// We're not trying to match this query, just confirm that it successfully executes |
63
|
|
|
$this->assertCount(0, $results); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|