silverstripe /
silverstripe-cms
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverStripe\CMS\Tests\Controllers; |
||
| 4 | |||
| 5 | use SilverStripe\Assets\File; |
||
| 6 | use SilverStripe\CMS\Controllers\ContentController; |
||
| 7 | use SilverStripe\CMS\Model\SiteTree; |
||
| 8 | use SilverStripe\CMS\Search\ContentControllerSearchExtension; |
||
| 9 | use SilverStripe\Dev\SapphireTest; |
||
| 10 | use SilverStripe\ORM\Search\FulltextSearchable; |
||
| 11 | use SilverStripe\Versioned\Versioned; |
||
| 12 | |||
| 13 | class ContentControllerSearchExtensionTest extends SapphireTest |
||
| 14 | { |
||
| 15 | protected static $required_extensions = [ |
||
| 16 | ContentController::class => [ |
||
| 17 | ContentControllerSearchExtension::class, |
||
| 18 | ], |
||
| 19 | ]; |
||
| 20 | |||
| 21 | public function testCustomSearchFormClassesToTest() |
||
| 22 | { |
||
| 23 | $page = SiteTree::create(); |
||
| 24 | $page->URLSegment = 'whatever'; |
||
| 25 | $page->Content = 'oh really?'; |
||
| 26 | $page->write(); |
||
| 27 | $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
||
| 28 | /** @var ContentController|ContentControllerSearchExtension $controller */ |
||
| 29 | $controller = new ContentController($page); |
||
| 30 | $form = $controller->SearchForm(); |
||
| 31 | $this->assertEquals([ File::class ], $form->getClassesToSearch()); |
||
| 32 | } |
||
| 33 | |||
| 34 | public static function setUpBeforeClass() : void |
||
| 35 | { |
||
| 36 | parent::setUpBeforeClass(); |
||
| 37 | FulltextSearchable::enable(File::class); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * FulltextSearchable::enable() leaves behind remains that don't get cleaned up |
||
| 42 | * properly at the end of the test. This becomes apparent when a later test tries to |
||
| 43 | * ALTER TABLE File and add fulltext indexes with the InnoDB table type. |
||
| 44 | */ |
||
| 45 | public static function tearDownAfterClass() : void |
||
| 46 | { |
||
| 47 | File::remove_extension(FulltextSearchable::class); |
||
| 48 | parent::tearDownAfterClass(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |