2011-03-22 10:00:53 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2011-03-22 10:47:26 +01:00
|
|
|
* @package cms
|
2011-03-22 10:00:53 +01:00
|
|
|
* @subpackage testing
|
|
|
|
*
|
|
|
|
* @todo Fix unpublished pages check in testPublishedPagesMatchedByTitle()
|
|
|
|
* @todo All tests run on unpublished pages at the moment, due to the searchform not distinguishing between them
|
2011-11-07 23:27:25 +01:00
|
|
|
*
|
|
|
|
* Because this manipulates the test database in severe ways, I've renamed the test to force it to run last...
|
2011-03-22 10:00:53 +01:00
|
|
|
*/
|
2011-11-07 23:27:25 +01:00
|
|
|
class ZZZSearchFormTest extends FunctionalTest {
|
2011-03-22 10:00:53 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'SearchFormTest.yml';
|
2014-01-15 23:36:25 +01:00
|
|
|
|
|
|
|
protected $illegalExtensions = array(
|
|
|
|
'SiteTree' => array('SiteTreeSubsites', 'Translatable')
|
|
|
|
);
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
protected $mockController;
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function waitUntilIndexingFinished() {
|
2013-06-21 00:45:33 +02:00
|
|
|
$schema = DB::get_schema();
|
|
|
|
if (method_exists($schema, 'waitUntilIndexingFinished')) $schema->waitUntilIndexingFinished();
|
2011-03-22 10:00:53 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function setUpOnce() {
|
2011-03-22 10:00:53 +01:00
|
|
|
// HACK Postgres doesn't refresh TSearch indexes when the schema changes after CREATE TABLE
|
2011-11-07 23:27:25 +01:00
|
|
|
// MySQL will need a different table type
|
|
|
|
self::kill_temp_db();
|
2011-10-31 00:20:56 +01:00
|
|
|
FulltextSearchable::enable();
|
2011-11-07 23:27:25 +01:00
|
|
|
self::create_temp_db();
|
|
|
|
$this->resetDBSchema(true);
|
2011-03-22 10:00:53 +01:00
|
|
|
parent::setUpOnce();
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function setUp() {
|
2011-03-22 10:00:53 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$holderPage = $this->objFromFixture('SiteTree', 'searchformholder');
|
|
|
|
$this->mockController = new ContentController($holderPage);
|
|
|
|
|
|
|
|
$this->waitUntilIndexingFinished();
|
|
|
|
}
|
|
|
|
|
2012-12-11 15:18:47 +01:00
|
|
|
/**
|
|
|
|
* @return Boolean
|
|
|
|
*/
|
|
|
|
protected function checkFulltextSupport() {
|
2013-06-21 00:45:33 +02:00
|
|
|
$conn = DB::get_conn();
|
2012-12-11 15:18:47 +01:00
|
|
|
if(class_exists('MSSQLDatabase') && $conn instanceof MSSQLDatabase) {
|
|
|
|
$supports = $conn->fullTextEnabled();
|
|
|
|
} else {
|
|
|
|
$supports = true;
|
|
|
|
}
|
|
|
|
if(!$supports) $this->markTestSkipped('Fulltext not supported by DB driver or setup');
|
|
|
|
return $supports;
|
|
|
|
}
|
2011-03-22 10:00:53 +01:00
|
|
|
|
2014-10-03 06:08:47 +02:00
|
|
|
public function testSearchFormTemplateCanBeChanged() {
|
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$sf->setTemplate('BlankPage');
|
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'<body class="SearchForm Form RequestHandler BlankPage">',
|
|
|
|
$sf->forTemplate()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPublishedPagesMatchedByTitle() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$publishedPage = $this->objFromFixture('SiteTree', 'publicPublishedPage');
|
|
|
|
$publishedPage->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$this->waitUntilIndexingFinished();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'publicPublishedPage'));
|
|
|
|
$this->assertContains(
|
|
|
|
$publishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages are found by searchform'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDoubleQuotesPublishedPagesMatchedByTitle() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$publishedPage = $this->objFromFixture('SiteTree', 'publicPublishedPage');
|
|
|
|
$publishedPage->Title = "finding butterflies";
|
|
|
|
$publishedPage->write();
|
|
|
|
$publishedPage->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$this->waitUntilIndexingFinished();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'"finding butterflies"'));
|
|
|
|
$this->assertContains(
|
|
|
|
$publishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages are found by searchform'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testUnpublishedPagesNotIncluded() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'publicUnpublishedPage'));
|
|
|
|
$unpublishedPage = $this->objFromFixture('SiteTree', 'publicUnpublishedPage');
|
|
|
|
$this->assertNotContains(
|
|
|
|
$unpublishedPage->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Unpublished pages are not found by searchform'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPagesRestrictedToLoggedinUsersNotIncluded() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'restrictedViewLoggedInUsers');
|
2013-07-04 04:54:13 +02:00
|
|
|
$page->publish('Stage', 'Live');
|
2011-03-22 10:00:53 +01:00
|
|
|
$results = $sf->getResults(null, array('Search'=>'restrictedViewLoggedInUsers'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Restrict to logged in users" doesnt show without valid login'
|
|
|
|
);
|
|
|
|
|
|
|
|
$member = $this->objFromFixture('Member', 'randomuser');
|
|
|
|
$member->logIn();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'restrictedViewLoggedInUsers'));
|
|
|
|
$this->assertContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Restrict to logged in users" shows if login is present'
|
|
|
|
);
|
|
|
|
$member->logOut();
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testPagesRestrictedToSpecificGroupNotIncluded() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'restrictedViewOnlyWebsiteUsers');
|
2013-07-04 04:54:13 +02:00
|
|
|
$page->publish('Stage', 'Live');
|
2011-03-22 10:00:53 +01:00
|
|
|
$results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Restrict to these users" doesnt show without valid login'
|
|
|
|
);
|
|
|
|
|
|
|
|
$member = $this->objFromFixture('Member', 'randomuser');
|
|
|
|
$member->logIn();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Restrict to these users" doesnt show if logged in user is not in the right group'
|
|
|
|
);
|
|
|
|
$member->logOut();
|
|
|
|
|
|
|
|
$member = $this->objFromFixture('Member', 'websiteuser');
|
|
|
|
$member->logIn();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'restrictedViewOnlyWebsiteUsers'));
|
|
|
|
$this->assertContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Restrict to these users" shows if user in this group is logged in'
|
|
|
|
);
|
|
|
|
$member->logOut();
|
|
|
|
}
|
|
|
|
|
2013-07-04 04:54:13 +02:00
|
|
|
public function testInheritedRestrictedPagesNotIncluded() {
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
2013-07-04 04:54:13 +02:00
|
|
|
|
|
|
|
$parent = $this->objFromFixture('SiteTree', 'restrictedViewLoggedInUsers');
|
|
|
|
$parent->publish('Stage', 'Live');
|
2011-03-22 10:00:53 +01:00
|
|
|
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'inheritRestrictedView');
|
2013-07-04 04:54:13 +02:00
|
|
|
$page->publish('Stage', 'Live');
|
2011-03-22 10:00:53 +01:00
|
|
|
$results = $sf->getResults(null, array('Search'=>'inheritRestrictedView'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page inheriting "Restrict to loggedin users" doesnt show without valid login'
|
|
|
|
);
|
|
|
|
|
|
|
|
$member = $this->objFromFixture('Member', 'websiteuser');
|
|
|
|
$member->logIn();
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'inheritRestrictedView'));
|
|
|
|
$this->assertContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page inheriting "Restrict to loggedin users" shows if user in this group is logged in'
|
|
|
|
);
|
|
|
|
$member->logOut();
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDisabledShowInSearchFlagNotIncludedForSiteTree() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$page = $this->objFromFixture('SiteTree', 'dontShowInSearchPage');
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'dontShowInSearchPage'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$page->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Page with "Show in Search" disabled doesnt show'
|
|
|
|
);
|
|
|
|
}
|
2011-09-15 15:59:18 +02:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDisabledShowInSearchFlagNotIncludedForFiles() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2011-09-15 15:59:18 +02:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$dontShowInSearchFile = $this->objFromFixture('File', 'dontShowInSearchFile');
|
|
|
|
$showInSearchFile = $this->objFromFixture('File', 'showInSearchFile');
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'dontShowInSearchFile'));
|
|
|
|
$this->assertNotContains(
|
|
|
|
$dontShowInSearchFile->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'File with "Show in Search" disabled doesnt show'
|
|
|
|
);
|
|
|
|
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'showInSearchFile'));
|
|
|
|
$this->assertContains(
|
|
|
|
$showInSearchFile->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'File with "Show in Search" enabled can be found'
|
|
|
|
);
|
|
|
|
}
|
2011-03-22 10:00:53 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testSearchTitleAndContentWithSpecialCharacters() {
|
2012-12-11 15:18:47 +01:00
|
|
|
if(!$this->checkFulltextSupport()) return;
|
|
|
|
|
2013-06-21 00:45:33 +02:00
|
|
|
if(class_exists('PostgreSQLDatabase') && DB::get_conn() instanceof PostgreSQLDatabase) {
|
2013-08-20 16:56:24 +02:00
|
|
|
$this->markTestSkipped("PostgreSQLDatabase doesn't support entity-encoded searches");
|
|
|
|
}
|
|
|
|
|
2011-03-22 10:00:53 +01:00
|
|
|
$sf = new SearchForm($this->mockController, 'SearchForm');
|
|
|
|
|
|
|
|
$pageWithSpecialChars = $this->objFromFixture('SiteTree', 'pageWithSpecialChars');
|
|
|
|
$pageWithSpecialChars->publish('Stage', 'Live');
|
|
|
|
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'Brötchen'));
|
|
|
|
$this->assertContains(
|
|
|
|
$pageWithSpecialChars->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages with umlauts in title are found'
|
|
|
|
);
|
|
|
|
|
|
|
|
$results = $sf->getResults(null, array('Search'=>'Bäcker'));
|
|
|
|
$this->assertContains(
|
|
|
|
$pageWithSpecialChars->ID,
|
|
|
|
$results->column('ID'),
|
|
|
|
'Published pages with htmlencoded umlauts in content are found'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|