diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index 54668552..6bd49441 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -103,8 +103,8 @@ class VirtualPage extends Page public function getNonVirtualisedFields() { return array_merge( - VirtualPage::config()->non_virtual_fields, - VirtualPage::config()->initially_copied_fields + self::config()->non_virtual_fields, + self::config()->initially_copied_fields ); } diff --git a/code/Search/SearchForm.php b/code/Search/SearchForm.php index 1fdaf24a..1e0e1b4f 100644 --- a/code/Search/SearchForm.php +++ b/code/Search/SearchForm.php @@ -2,8 +2,10 @@ namespace SilverStripe\CMS\Search; +use BadMethodCallException; +use SilverStripe\Assets\File; use SilverStripe\CMS\Model\SiteTree; -use SilverStripe\Control\Controller; +use SilverStripe\Control\RequestHandler; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; @@ -26,19 +28,22 @@ use Translatable; */ class SearchForm extends Form { - /** - * @var int $pageLength How many results are shown per page. + * How many results are shown per page. * Relies on pagination being implemented in the search results template. + * + * @var int */ protected $pageLength = 10; /** * Classes to search + * + * @var array */ protected $classesToSearch = array( - "SilverStripe\\CMS\\Model\\SiteTree", - "SilverStripe\\Assets\\File" + SiteTree::class, + File::class ); private static $casting = array( @@ -46,15 +51,19 @@ class SearchForm extends Form ); /** - * - * @param Controller $controller + * @skipUpgrade + * @param RequestHandler $controller * @param string $name The name of the form (used in URL addressing) * @param FieldList $fields Optional, defaults to a single field named "Search". Search logic needs to be customized * if fields are added to the form. * @param FieldList $actions Optional, defaults to a single field named "Go". */ - public function __construct($controller, $name, $fields = null, $actions = null) - { + public function __construct( + RequestHandler $controller = null, + $name = 'SearchForm', + FieldList $fields = null, + FieldList $actions = null + ) { if (!$fields) { $fields = new FieldList( new TextField('Search', _t('SearchForm.SEARCH', 'Search')) @@ -69,7 +78,7 @@ class SearchForm extends Form if (!$actions) { $actions = new FieldList( - new FormAction("getResults", _t('SearchForm.GO', 'Go')) + new FormAction("results", _t('SearchForm.GO', 'Go')) ); } @@ -88,13 +97,12 @@ class SearchForm extends Form */ public function classesToSearch($classes) { - $supportedClasses = array('SilverStripe\\CMS\\Model\\SiteTree', 'SilverStripe\\Assets\\File'); + $supportedClasses = array(SiteTree::class, File::class); $illegalClasses = array_diff($classes, $supportedClasses); if ($illegalClasses) { - user_error( + throw new BadMethodCallException( "SearchForm::classesToSearch() passed illegal classes '" . implode("', '", $illegalClasses) - . "'. At this stage, only File and SiteTree are allowed", - E_USER_WARNING + . "'. At this stage, only File and SiteTree are allowed" ); } $legalClasses = array_intersect($classes, $supportedClasses); @@ -112,34 +120,33 @@ class SearchForm extends Form } /** - * Return dataObjectSet of the results using $_REQUEST to get info from form. + * Return dataObjectSet of the results using current request to get info from form. * Wraps around {@link searchEngine()}. * - * @param int $pageLength DEPRECATED 2.3 Use SearchForm->pageLength - * @param array $data Request data as an associative array. Should contain at least a key 'Search' with all searched keywords. * @return SS_List */ - public function getResults($pageLength = null, $data = null) + public function getResults() { - // legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials - if (!isset($data) || !is_array($data)) { - $data = $_REQUEST; - } + // Get request data from request handler + $request = $this->getRequestHandler()->getRequest(); // set language (if present) + $locale = null; + $origLocale = null; if (class_exists('Translatable')) { - if (SiteTree::singleton()->hasExtension('Translatable') && isset($data['searchlocale'])) { - if ($data['searchlocale'] == "ALL") { + $locale = $request->requestVar('searchlocale'); + if (SiteTree::singleton()->hasExtension('Translatable') && $locale) { + if ($locale === "ALL") { Translatable::disable_locale_filter(); } else { $origLocale = Translatable::get_current_locale(); - Translatable::set_current_locale($data['searchlocale']); + Translatable::set_current_locale($locale); } } } - $keywords = $data['Search']; + $keywords = $request->requestVar('Search'); $andProcessor = create_function('$matches', ' return " +" . $matches[2] . " +" . $matches[4] . " "; @@ -155,16 +162,15 @@ class SearchForm extends Form $keywords = $this->addStarsToKeywords($keywords); - if (!$pageLength) { - $pageLength = $this->pageLength; - } - $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; + $pageLength = $this->getPageLength(); + $start = $request->requestVar('start') ?: 0; - if (strpos($keywords, '"') !== false || strpos($keywords, '+') !== false || strpos($keywords, '-') !== false || strpos($keywords, '*') !== false) { - $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", true); - } else { - $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength); - } + $booleanSearch = + strpos($keywords, '"') !== false || + strpos($keywords, '+') !== false || + strpos($keywords, '-') !== false || + strpos($keywords, '*') !== false; + $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", $booleanSearch); // filter by permission if ($results) { @@ -177,8 +183,8 @@ class SearchForm extends Form // reset locale if (class_exists('Translatable')) { - if (SiteTree::singleton()->hasExtension('Translatable') && isset($data['searchlocale'])) { - if ($data['searchlocale'] == "ALL") { + if (SiteTree::singleton()->hasExtension('Translatable') && $locale) { + if ($locale == "ALL") { Translatable::enable_locale_filter(); } else { Translatable::set_current_locale($origLocale); @@ -216,22 +222,11 @@ class SearchForm extends Form /** * Get the search query for display in a "You searched for ..." sentence. * - * @param array $data * @return string */ - public function getSearchQuery($data = null) + public function getSearchQuery() { - // legacy usage: $data was defaulting to $_REQUEST, parameter not passed in doc.silverstripe.org tutorials - if (!isset($data)) { - $data = $_REQUEST; - } - - // The form could be rendered without the search being done, so check for that. - if (isset($data['Search'])) { - return $data['Search']; - } - - return null; + return $this->getRequestHandler()->getRequest()->requestVar('Search'); } /** diff --git a/tests/model/RedirectorPageTest.php b/tests/model/RedirectorPageTest.php index 96959637..d440c150 100644 --- a/tests/model/RedirectorPageTest.php +++ b/tests/model/RedirectorPageTest.php @@ -22,15 +22,15 @@ class RedirectorPageTest extends FunctionalTest public function testGoodRedirectors() { /* For good redirectors, the final destination URL will be returned */ - $this->assertEquals("http://www.google.com", $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'goodexternal')->Link()); - $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'goodinternal')->redirectionLink()); - $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'goodinternal')->Link()); + $this->assertEquals("http://www.google.com", $this->objFromFixture(RedirectorPage::class, 'goodexternal')->Link()); + $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->redirectionLink()); + $this->assertEquals(Director::baseURL() . "redirection-dest/", $this->objFromFixture(RedirectorPage::class, 'goodinternal')->Link()); } public function testEmptyRedirectors() { /* If a redirector page is misconfigured, then its link method will just return the usual URLSegment-generated value */ - $page1 = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'badexternal'); + $page1 = $this->objFromFixture(RedirectorPage::class, 'badexternal'); $this->assertEquals(Director::baseURL() . 'bad-external/', $page1->Link()); /* An error message will be shown if you visit it */ @@ -38,7 +38,7 @@ class RedirectorPageTest extends FunctionalTest $this->assertContains('message-setupWithoutRedirect', $content); /* This also applies for internal links */ - $page2 = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'badinternal'); + $page2 = $this->objFromFixture(RedirectorPage::class, 'badinternal'); $this->assertEquals(Director::baseURL() . 'bad-internal/', $page2->Link()); $content = $this->get(Director::makeRelative($page2->Link()))->getBody(); $this->assertContains('message-setupWithoutRedirect', $content); @@ -47,14 +47,14 @@ class RedirectorPageTest extends FunctionalTest public function testReflexiveAndTransitiveInternalRedirectors() { /* Reflexive redirectors are those that point to themselves. They should behave the same as an empty redirector */ - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'reflexive'); + $page = $this->objFromFixture(RedirectorPage::class, 'reflexive'); $this->assertEquals(Director::baseURL() . 'reflexive/', $page->Link()); $content = $this->get(Director::makeRelative($page->Link()))->getBody(); $this->assertContains('message-setupWithoutRedirect', $content); /* Transitive redirectors are those that point to another redirector page. They should send people to the URLSegment * of the destination page - the middle-stop, so to speak. That should redirect to the final destination */ - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'transitive'); + $page = $this->objFromFixture(RedirectorPage::class, 'transitive'); $this->assertEquals(Director::baseURL() . 'good-internal/', $page->Link()); $this->autoFollowRedirection = false; @@ -64,7 +64,7 @@ class RedirectorPageTest extends FunctionalTest public function testExternalURLGetsPrefixIfNotSet() { - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'externalnoprefix'); + $page = $this->objFromFixture(RedirectorPage::class, 'externalnoprefix'); $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http'); $page->write(); $this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!'); @@ -90,12 +90,12 @@ class RedirectorPageTest extends FunctionalTest */ public function testRedirectRespectsFinishedResponse() { - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\RedirectorPage', 'goodinternal'); + $page = $this->objFromFixture(RedirectorPage::class, 'goodinternal'); RedirectorPageController::add_extension('RedirectorPageTest_RedirectExtension'); $response = $this->get($page->regularLink()); $this->assertEquals(302, $response->getStatusCode()); - $this->assertEquals('/foo', $response->getHeader('Location')); + $this->assertEquals('http://www.mysite.com/foo', $response->getHeader('Location')); RedirectorPageController::remove_extension('RedirectorPageTest_RedirectExtension'); } diff --git a/tests/search/SearchFormTest.php b/tests/search/SearchFormTest.php index 667860dc..466ec874 100644 --- a/tests/search/SearchFormTest.php +++ b/tests/search/SearchFormTest.php @@ -1,5 +1,10 @@ array('SiteTreeSubsites', 'Translatable') + SiteTree::class => array('SiteTreeSubsites', 'Translatable') ); + /** + * @var ContentController + */ protected $mockController; public function waitUntilIndexingFinished() @@ -42,6 +51,7 @@ class ZZZSearchFormTest extends FunctionalTest // HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE // MySQL will need a different table type self::kill_temp_db(); + Config::modify(); FulltextSearchable::enable(); self::create_temp_db(); $this->resetDBSchema(true); @@ -52,8 +62,9 @@ class ZZZSearchFormTest extends FunctionalTest { parent::setUp(); - $holderPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'searchformholder'); - $this->mockController = new ContentController($holderPage); + /** @var Page $holderPage */ + $holderPage = $this->objFromFixture(SiteTree::class, 'searchformholder'); + $this->mockController = ModelAsController::controller_for($holderPage); $this->waitUntilIndexingFinished(); } @@ -64,7 +75,7 @@ class ZZZSearchFormTest extends FunctionalTest protected function checkFulltextSupport() { $conn = DB::get_conn(); - if (class_exists('SilverStripe\\MSSQL\\MSSQLDatabase') && $conn instanceof MSSQLDatabase) { + if (class_exists(MSSQLDatabase::class) && $conn instanceof MSSQLDatabase) { $supports = $conn->fullTextEnabled(); } else { $supports = true; @@ -75,35 +86,44 @@ class ZZZSearchFormTest extends FunctionalTest return $supports; } + /** + * @skipUpgrade + */ public function testSearchFormTemplateCanBeChanged() { if (!$this->checkFulltextSupport()) { return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $sf = new SearchForm($this->mockController); $sf->setTemplate('BlankPage'); $this->assertContains( - '', + '', $sf->forTemplate() ); } + /** + * @skipUpgrade + */ public function testPublishedPagesMatchedByTitle() { if (!$this->checkFulltextSupport()) { return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'publicPublishedPage']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $publishedPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'publicPublishedPage'); + $publishedPage = $this->objFromFixture(SiteTree::class, 'publicPublishedPage'); $publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $this->waitUntilIndexingFinished(); - $results = $sf->getResults(null, array('Search'=>'publicPublishedPage')); + + $results = $sf->getResults(); $this->assertContains( $publishedPage->ID, $results->column('ID'), @@ -111,21 +131,26 @@ class ZZZSearchFormTest extends FunctionalTest ); } + /** + * @skipUpgrade + */ public function testDoubleQuotesPublishedPagesMatchedByTitle() { if (!$this->checkFulltextSupport()) { return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'"finding butterflies"']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $publishedPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'publicPublishedPage'); + $publishedPage = $this->objFromFixture(SiteTree::class, 'publicPublishedPage'); $publishedPage->Title = "finding butterflies"; $publishedPage->write(); $publishedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $this->waitUntilIndexingFinished(); - $results = $sf->getResults(null, array('Search'=>'"finding butterflies"')); + $results = $sf->getResults(); $this->assertContains( $publishedPage->ID, $results->column('ID'), @@ -133,16 +158,21 @@ class ZZZSearchFormTest extends FunctionalTest ); } + /** + * @skipUpgrade + */ public function testUnpublishedPagesNotIncluded() { if (!$this->checkFulltextSupport()) { return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'publicUnpublishedPage']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $results = $sf->getResults(null, array('Search'=>'publicUnpublishedPage')); - $unpublishedPage = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'publicUnpublishedPage'); + $results = $sf->getResults(); + $unpublishedPage = $this->objFromFixture(SiteTree::class, 'publicUnpublishedPage'); $this->assertNotContains( $unpublishedPage->ID, $results->column('ID'), @@ -156,20 +186,22 @@ class ZZZSearchFormTest extends FunctionalTest return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'restrictedViewLoggedInUsers']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'restrictedViewLoggedInUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers'); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $results = $sf->getResults(null, array('Search'=>'restrictedViewLoggedInUsers')); + $results = $sf->getResults(); $this->assertNotContains( $page->ID, $results->column('ID'), 'Page with "Restrict to logged in users" doesnt show without valid login' ); - $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'randomuser'); + $member = $this->objFromFixture(Member::class, 'randomuser'); $member->logIn(); - $results = $sf->getResults(null, array('Search'=>'restrictedViewLoggedInUsers')); + $results = $sf->getResults(); $this->assertContains( $page->ID, $results->column('ID'), @@ -184,20 +216,22 @@ class ZZZSearchFormTest extends FunctionalTest return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'restrictedViewOnlyWebsiteUsers']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'restrictedViewOnlyWebsiteUsers'); + $page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers'); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers')); + $results = $sf->getResults(); $this->assertNotContains( $page->ID, $results->column('ID'), 'Page with "Restrict to these users" doesnt show without valid login' ); - $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'randomuser'); + $member = $this->objFromFixture(Member::class, 'randomuser'); $member->logIn(); - $results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers')); + $results = $sf->getResults(); $this->assertNotContains( $page->ID, $results->column('ID'), @@ -205,9 +239,9 @@ class ZZZSearchFormTest extends FunctionalTest ); $member->logOut(); - $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'websiteuser'); + $member = $this->objFromFixture(Member::class, 'websiteuser'); $member->logIn(); - $results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers')); + $results = $sf->getResults(); $this->assertContains( $page->ID, $results->column('ID'), @@ -218,23 +252,25 @@ class ZZZSearchFormTest extends FunctionalTest public function testInheritedRestrictedPagesNotIncluded() { - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'inheritRestrictedView']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $parent = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'restrictedViewLoggedInUsers'); + $parent = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers'); $parent->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'inheritRestrictedView'); + $page = $this->objFromFixture(SiteTree::class, 'inheritRestrictedView'); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $results = $sf->getResults(null, array('Search'=>'inheritRestrictedView')); + $results = $sf->getResults(); $this->assertNotContains( $page->ID, $results->column('ID'), 'Page inheriting "Restrict to loggedin users" doesnt show without valid login' ); - $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'websiteuser'); + $member = $this->objFromFixture(Member::class, 'websiteuser'); $member->logIn(); - $results = $sf->getResults(null, array('Search'=>'inheritRestrictedView')); + $results = $sf->getResults(); $this->assertContains( $page->ID, $results->column('ID'), @@ -249,14 +285,16 @@ class ZZZSearchFormTest extends FunctionalTest return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'dontShowInSearchPage']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'dontShowInSearchPage'); - $results = $sf->getResults(null, array('Search'=>'dontShowInSearchPage')); + $page = $this->objFromFixture(SiteTree::class, 'dontShowInSearchPage'); + $results = $sf->getResults(); $this->assertNotContains( $page->ID, $results->column('ID'), - 'Page with "Show in Search" disabled doesnt show' + 'Page with "Show in Search" disabled does not show' ); } @@ -266,21 +304,27 @@ class ZZZSearchFormTest extends FunctionalTest return; } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'dontShowInSearchFile']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $dontShowInSearchFile = $this->objFromFixture('SilverStripe\\Assets\\File', 'dontShowInSearchFile'); + $dontShowInSearchFile = $this->objFromFixture(File::class, 'dontShowInSearchFile'); $dontShowInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $showInSearchFile = $this->objFromFixture('SilverStripe\\Assets\\File', 'showInSearchFile'); + $showInSearchFile = $this->objFromFixture(File::class, 'showInSearchFile'); $showInSearchFile->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $results = $sf->getResults(null, array('Search'=>'dontShowInSearchFile')); + $results = $sf->getResults(); $this->assertNotContains( $dontShowInSearchFile->ID, $results->column('ID'), 'File with "Show in Search" disabled doesnt show' ); - $results = $sf->getResults(null, array('Search'=>'showInSearchFile')); + // Check ShowInSearch=1 can be found + $request = new HTTPRequest('GET', 'search', ['Search'=>'showInSearchFile']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); + $results = $sf->getResults(); $this->assertContains( $showInSearchFile->ID, $results->column('ID'), @@ -294,23 +338,29 @@ class ZZZSearchFormTest extends FunctionalTest return; } - if (class_exists('SilverStripe\\PostgreSQL\\PostgreSQLDatabase') && DB::get_conn() instanceof PostgreSQLDatabase) { + if (class_exists(PostgreSQLDatabase::class) && DB::get_conn() instanceof PostgreSQLDatabase) { $this->markTestSkipped("PostgreSQLDatabase doesn't support entity-encoded searches"); } - $sf = new SearchForm($this->mockController, 'SilverStripe\\CMS\\Search\\SearchForm'); + $request = new HTTPRequest('GET', 'search', ['Search'=>'Brötchen']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); - $pageWithSpecialChars = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'pageWithSpecialChars'); + $pageWithSpecialChars = $this->objFromFixture(SiteTree::class, 'pageWithSpecialChars'); $pageWithSpecialChars->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); - $results = $sf->getResults(null, array('Search'=>'Brötchen')); + $results = $sf->getResults(); $this->assertContains( $pageWithSpecialChars->ID, $results->column('ID'), 'Published pages with umlauts in title are found' ); - $results = $sf->getResults(null, array('Search'=>'Bäcker')); + // Check another word + $request = new HTTPRequest('GET', 'search', ['Search'=>'Bäcker']); + $this->mockController->setRequest($request); + $sf = new SearchForm($this->mockController); + $results = $sf->getResults(); $this->assertContains( $pageWithSpecialChars->ID, $results->column('ID'),