From 5e3068ba13e40c19a44f102be2a3dd39fd916559 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 9 Nov 2018 18:10:29 +1300 Subject: [PATCH] MINOR: Add tests for some search-form fixes These 2 tests validate that the following bugs have been fixed. https://github.com/silverstripe/silverstripe-framework/issues/3212 https://github.com/silverstripe/silverstripe-cms/issues/1452 --- tests/php/Search/DatabaseSearchEngineTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/php/Search/DatabaseSearchEngineTest.php diff --git a/tests/php/Search/DatabaseSearchEngineTest.php b/tests/php/Search/DatabaseSearchEngineTest.php new file mode 100644 index 00000000..8d424af0 --- /dev/null +++ b/tests/php/Search/DatabaseSearchEngineTest.php @@ -0,0 +1,65 @@ +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); + } +}