silverstripe-cms/tests/controller/ContentControllerSearchExtensionTest.php

54 lines
1.8 KiB
PHP
Raw Normal View History

<?php
use SilverStripe\Versioned\Versioned;
2016-07-22 01:32:32 +02:00
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\ORM\Search\FulltextSearchable;
use SilverStripe\Core\Config\Config;
use SilverStripe\Assets\File;
use SilverStripe\Dev\SapphireTest;
2017-01-25 21:59:25 +01:00
class ContentControllerSearchExtensionTest extends SapphireTest
{
2017-03-30 00:07:04 +02:00
protected static $required_extensions = array(
ContentController::class => [
\SilverStripe\CMS\Search\ContentControllerSearchExtension::class,
],
);
2017-01-25 21:59:25 +01:00
public function testCustomSearchFormClassesToTest()
{
$page = new Page();
$page->URLSegment = 'whatever';
$page->Content = 'oh really?';
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$controller = new ContentController($page);
$form = $controller->SearchForm();
if (get_class($form) == 'SilverStripe\\CMS\\Search\\SearchForm') {
$this->assertEquals(array('SilverStripe\\Assets\\File'), $form->getClassesToSearch());
}
}
2017-03-30 00:07:04 +02:00
public static function setUpBeforeClass()
2017-01-25 21:59:25 +01:00
{
2017-03-30 00:07:04 +02:00
parent::setUpBeforeClass();
2017-01-25 21:59:25 +01:00
FulltextSearchable::enable('SilverStripe\\Assets\\File');
}
/**
* 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.
*/
2017-03-30 00:07:04 +02:00
public static function tearDownAfterClass()
2017-01-25 21:59:25 +01:00
{
2017-03-30 00:07:04 +02:00
parent::tearDownAfterClass();
2017-01-25 21:59:25 +01:00
Config::inst()->update('SilverStripe\\Assets\\File', 'create_table_options', array('SilverStripe\ORM\Connect\MySQLDatabase' => 'ENGINE=InnoDB'));
File::remove_extension('SilverStripe\\ORM\\Search\\FulltextSearchable');
}
}