Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (70 sloc) 2.563 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
<?php
class CMSSiteTreeFilterTest extends SapphireTest {

static $fixture_file = '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));
}
}
Something went wrong with that request. Please try again.