silverstripe-cms/tests/search/CMSMainSearchFormTest.php

38 lines
1010 B
PHP
Raw Normal View History

<?php
use SilverStripe\Dev\FunctionalTest;
class CMSMainSearchFormTest extends FunctionalTest {
2016-03-08 21:50:55 +01:00
protected static $fixture_file = '../controller/CMSMainTest.yml';
2016-03-08 21:50:55 +01:00
public function testTitleFilter() {
$this->session()->inst_set('loggedInAs', $this->idFromFixture('SilverStripe\\Security\\Member', 'admin'));
$response = $this->get(
'admin/pages/SearchForm/?' .
http_build_query(array(
'q' => array(
'Title' => 'Page 10',
2016-07-22 01:32:32 +02:00
'FilterClass' => 'SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter_Search',
),
'action_doSearch' => true
))
);
2016-03-08 21:50:55 +01:00
$titles = $this->getPageTitles();
$this->assertEquals(count($titles), 1);
// For some reason the title gets split into two lines
2016-03-08 21:50:55 +01:00
$this->assertContains('Page 1', $titles[0]);
}
2016-03-08 21:50:55 +01:00
protected function getPageTitles() {
$titles = array();
$links = $this->cssParser()->getBySelector('li.class-Page a');
if($links) foreach($links as $link) {
$titles[] = preg_replace('/\n/', ' ', $link->asXML());
}
return $titles;
}
}