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

46 lines
1.2 KiB
PHP
Raw Normal View History

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