silverstripe-cms/tests/php/Search/DatabaseSearchEngineTest.php
Ingo Schommer dd839ca2d9 FIX Remove searchEngine() test that's using API wrong
Required to allow InnoDB usage, see https://github.com/silverstripe/silverstripe-framework/pull/9454.

This came up in https://github.com/silverstripe/silverstripe-cms/issues/1452, and wasn't fully addressed.
Either we allow boolean mode and all the constraints this brings around special character usage,
or we filter out those special characters, which makes boolean mode pointless.
You can't just pass arbitrary user input in a power-user function like this.
See https://dev.mysql.com/doc/refman/5.6/en/fulltext-boolean.html

Context: This used to work for some examples like "foo>*" under MyISAM,
presumably because it had a more lenient parser. InnoDB rightfully complains about this now.
2020-04-09 09:59:53 +12:00

51 lines
1.4 KiB
PHP

<?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
);
}
}