silverstripe-cms/tests/CMSSiteTreeFilterTest.php
Ingo Schommer a5070b858a API CHANGE Removed CMSSiteTreeFilter->showInList(), using custom logic in CMSMain->SearchTreeForm() instead
API CHANGE Returning arrays instead of Query resource from CMSSiteTreeFilter->pagesIncluded()
MINOR Removed unused LeftAndMain->getMarkingFilter() and CMSMainMarkingFilter, now handled by CMSSiteTreeFilter and CMSMain->SearchTreeForm()
ENHANCEMENT Moved 'page tree filter' dropdown logic into an additional option for CMSMain->SearchTreeForm() (originally implemented in r83674)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92938 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-22 08:23:12 +00:00

87 lines
2.5 KiB
PHP

<?php
class CMSSiteTreeFilterTest extends SapphireTest {
static $fixture_file = 'cms/tests/CMSSiteTreeFilterTest.yml';
function testSearchFilterEmpty() {
$page1 = $this->objFromFixture('Page', 'page1');
$page2 = $this->objFromFixture('Page', 'page2');
$f = new CMSSiteTreeFilter_Search();
$results = $f->pagesIncluded();
$this->assertTrue($f->isPageIncluded($page1));
$this->assertTrue($f->isPageIncluded($page2));
}
function testSearchFilterByTitle() {
$page1 = $this->objFromFixture('Page', 'page1');
$page2 = $this->objFromFixture('Page', 'page2');
$f = new CMSSiteTreeFilter_Search(array('Title' => 'Page 1'));
$results = $f->pagesIncluded();
$this->assertTrue($f->isPageIncluded($page1));
$this->assertFalse($f->isPageIncluded($page2));
$this->assertEquals(1, count($results));
$this->assertEquals(
array('ID' => $page1->ID, 'ParentID' => 0),
$results[0]
);
}
function testIncludesParentsForNestedMatches() {
$parent = $this->objFromFixture('Page', 'page3');
$child = $this->objFromFixture('Page', 'page3b');
$f = new CMSSiteTreeFilter_Search(array('Title' => 'Page 3b'));
$results = $f->pagesIncluded();
$this->assertTrue($f->isPageIncluded($parent));
$this->assertTrue($f->isPageIncluded($child));
$this->assertEquals(1, count($results));
$this->assertEquals(
array('ID' => $child->ID, 'ParentID' => $parent->ID),
$results[0]
);
}
function testChangedPagesFilter() {
$unchangedPage = $this->objFromFixture('Page', 'page1');
$unchangedPage->doPublish();
$changedPage = $this->objFromFixture('Page', 'page2');
$changedPage->MetaTitle = 'Original';
$changedPage->publish('Stage', 'Live');
$changedPage->MetaTitle = 'Changed';
$changedPage->write();
$f = new CMSSiteTreeFilter_ChangedPages();
$results = $f->pagesIncluded();
$this->assertTrue($f->isPageIncluded($changedPage));
$this->assertFalse($f->isPageIncluded($unchangedPage));
$this->assertEquals(1, count($results));
$this->assertEquals(
array('ID' => $changedPage->ID, 'ParentID' => 0),
$results[0]
);
}
function testDeletedPagesFilter() {
$deletedPage = $this->objFromFixture('Page', 'page2');
$deletedPage->publish('Stage', 'Live');
$deletedPageID = $deletedPage->ID;
$deletedPage->delete();
$deletedPage = Versioned::get_one_by_stage(
'SiteTree',
'Live',
sprintf('"SiteTree_Live"."ID" = %d', $deletedPageID)
);
$f = new CMSSiteTreeFilter_DeletedPages();
$results = $f->pagesIncluded();
$this->assertTrue($f->isPageIncluded($deletedPage));
}
}