silverstripe-cms/tests/php/Search/DatabaseSearchEngineTest.php
Ingo Schommer e51bd421a6 FIX InnoDB FULLTEXT compat in tests
> InnoDB FULLTEXT indexes have special transaction handling characteristics due its caching and batch processing behavior. Specifically, updates and insertions on a FULLTEXT index are processed at transaction commit time, which means that a FULLTEXT search can only see committed data. The following example demonstrates this behavior. The FULLTEXT search only returns a result after the inserted lines are committed.

https://dev.mysql.com/doc/refman/5.6/en/innodb-fulltext-index.html#innodb-fulltext-index-transaction
2020-04-09 11:05:19 +12:00

55 lines
1.5 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;
/**
* @var bool InnoDB doesn't update indexes until transactions are committed
*/
protected $usesTransactions = false;
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
);
}
}