silverstripe-cms/tests/php/Search/CMSMainSearchFormTest.php

46 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2017-08-09 04:53:38 +02:00
namespace SilverStripe\CMS\Tests\Search;
2017-08-09 03:25:12 +02:00
use SilverStripe\CMS\Controllers\CMSSiteTreeFilter_Search;
use SilverStripe\Dev\FunctionalTest;
2017-08-09 04:53:38 +02:00
use SilverStripe\Security\Member;
2017-08-09 03:25:12 +02:00
2017-01-25 21:59:25 +01:00
class CMSMainSearchFormTest extends FunctionalTest
{
2017-08-09 04:53:38 +02:00
protected static $fixture_file = '../Controllers/CMSMainTest.yml';
2017-01-25 21:59:25 +01:00
public function testTitleFilter()
{
2017-08-09 04:53:38 +02:00
$this->session()->set('loggedInAs', $this->idFromFixture(Member::class, 'admin'));
2017-01-25 21:59:25 +01:00
$this->get(
'admin/pages/?' .
2017-01-25 21:59:25 +01:00
http_build_query(array(
'q' => array(
'Term' => 'Page 10',
'FilterClass' => CMSSiteTreeFilter_Search::class,
)
2017-01-25 21:59:25 +01:00
))
);
$titles = $this->getPageTitles();
$this->assertEquals(count($titles), 1);
// For some reason the title gets split into two lines
$this->assertContains('Page 1', $titles[0]);
}
protected function getPageTitles()
{
$titles = array();
$links = $this->cssParser()->getBySelector('.col-getTreeTitle span.item');
2017-01-25 21:59:25 +01:00
if ($links) {
foreach ($links as $link) {
$titles[] = preg_replace('/\n/', ' ', $link->asXML());
}
}
return $titles;
}
}