2009-11-22 09:23:12 +01:00
|
|
|
<?php
|
|
|
|
class CMSSiteTreeFilterTest extends SapphireTest {
|
|
|
|
|
2011-03-30 09:04:31 +02:00
|
|
|
static $fixture_file = 'CMSSiteTreeFilterTest.yml';
|
2009-11-22 09:23:12 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testSearchFilterEmpty() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$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));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testSearchFilterByTitle() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testIncludesParentsForNestedMatches() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testChangedPagesFilter() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$unchangedPage = $this->objFromFixture('Page', 'page1');
|
|
|
|
$unchangedPage->doPublish();
|
|
|
|
|
|
|
|
$changedPage = $this->objFromFixture('Page', 'page2');
|
2012-09-21 11:31:00 +02:00
|
|
|
$changedPage->Title = 'Original';
|
2009-11-22 09:23:12 +01:00
|
|
|
$changedPage->publish('Stage', 'Live');
|
2012-09-21 11:31:00 +02:00
|
|
|
$changedPage->Title = 'Changed';
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeletedPagesFilter() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$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));
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|