2010-10-19 06:53:36 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\ORM\Tests\Search;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Assets\File;
|
|
|
|
use SilverStripe\ORM\Connect\MySQLSchemaManager;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-05-18 18:59:57 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\ORM\Search\FulltextSearchable;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class FulltextSearchableTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
FulltextSearchable::enable(File::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FulltextSearchable::enable() leaves behind remains that don't get cleaned up
|
|
|
|
* properly at the end of the test. This becomes apparent when a later test tries to
|
|
|
|
* ALTER TABLE File and add fulltext indexes with the InnoDB table type.
|
|
|
|
*/
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function tearDown(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
File::remove_extension(FulltextSearchable::class);
|
2017-07-17 07:59:40 +02:00
|
|
|
Config::modify()->merge(
|
2016-12-16 05:34:21 +01:00
|
|
|
File::class,
|
|
|
|
'create_table_options',
|
2020-04-20 19:58:09 +02:00
|
|
|
[
|
|
|
|
MySQLSchemaManager::ID => 'ENGINE=InnoDB']
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnable()
|
|
|
|
{
|
|
|
|
$this->assertTrue(File::has_extension(FulltextSearchable::class));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnableWithCustomClasses()
|
|
|
|
{
|
2020-04-20 19:58:09 +02:00
|
|
|
FulltextSearchable::enable([File::class]);
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertTrue(File::has_extension(FulltextSearchable::class));
|
|
|
|
|
|
|
|
File::remove_extension(FulltextSearchable::class);
|
|
|
|
$this->assertFalse(File::has_extension(FulltextSearchable::class));
|
|
|
|
}
|
2017-05-18 18:59:57 +02:00
|
|
|
|
|
|
|
public function testIndexesAdded()
|
|
|
|
{
|
|
|
|
$indexes = DataObject::getSchema()->databaseIndexes(File::class);
|
|
|
|
$this->assertArrayHasKey('SearchFields', $indexes);
|
|
|
|
$this->assertCount(2, $indexes['SearchFields']['columns']);
|
|
|
|
$this->assertContains('Name', $indexes['SearchFields']['columns']);
|
|
|
|
$this->assertContains('Title', $indexes['SearchFields']['columns']);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|