2011-03-22 10:00:53 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Controllers;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Assets\File;
|
2017-06-21 06:29:40 +02:00
|
|
|
use SilverStripe\CMS\Controllers\ContentController;
|
|
|
|
use SilverStripe\CMS\Search\ContentControllerSearchExtension;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-06-21 06:29:40 +02:00
|
|
|
use SilverStripe\ORM\Search\FulltextSearchable;
|
|
|
|
use SilverStripe\Versioned\Versioned;
|
2017-08-09 03:25:12 +02:00
|
|
|
use Page;
|
|
|
|
|
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 => [
|
2017-06-21 06:29:40 +02:00
|
|
|
ContentControllerSearchExtension::class,
|
|
|
|
]
|
2017-03-30 00:07:04 +02:00
|
|
|
);
|
|
|
|
|
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);
|
2017-06-21 06:29:40 +02:00
|
|
|
/** @var ContentController|ContentControllerSearchExtension $controller */
|
2017-01-25 21:59:25 +01:00
|
|
|
$controller = new ContentController($page);
|
|
|
|
$form = $controller->SearchForm();
|
2017-06-21 06:29:40 +02:00
|
|
|
$this->assertEquals([ File::class ], $form->getClassesToSearch());
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
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-06-21 06:29:40 +02:00
|
|
|
FulltextSearchable::enable(File::class);
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-06-21 06:29:40 +02:00
|
|
|
File::remove_extension(FulltextSearchable::class);
|
2017-03-30 00:07:04 +02:00
|
|
|
parent::tearDownAfterClass();
|
2017-01-25 21:59:25 +01:00
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|