2009-11-22 09:23:12 +01:00
|
|
|
<?php
|
|
|
|
class CMSSiteTreeFilterTest extends SapphireTest {
|
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
protected static $fixture_file = 'CMSSiteTreeFilterTest.yml';
|
2016-03-08 21:50:55 +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');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$f = new CMSSiteTreeFilter_Search();
|
|
|
|
$results = $f->pagesIncluded();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$this->assertTrue($f->isPageIncluded($page1));
|
|
|
|
$this->assertTrue($f->isPageIncluded($page2));
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
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');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$f = new CMSSiteTreeFilter_Search(array('Title' => 'Page 1'));
|
|
|
|
$results = $f->pagesIncluded();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
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');
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$f = new CMSSiteTreeFilter_Search(array('Title' => 'Page 3b'));
|
|
|
|
$results = $f->pagesIncluded();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testChangedPagesFilter() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$unchangedPage = $this->objFromFixture('Page', 'page1');
|
2016-04-01 05:17:37 +02:00
|
|
|
$unchangedPage->publishRecursive();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$changedPage = $this->objFromFixture('Page', 'page2');
|
2012-09-21 11:31:00 +02:00
|
|
|
$changedPage->Title = 'Original';
|
2016-04-01 05:17:37 +02:00
|
|
|
$changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2012-09-21 11:31:00 +02:00
|
|
|
$changedPage->Title = 'Changed';
|
2009-11-22 09:23:12 +01:00
|
|
|
$changedPage->write();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Check that only changed pages are returned
|
|
|
|
$f = new CMSSiteTreeFilter_ChangedPages(array('Term' => 'Changed'));
|
2009-11-22 09:23:12 +01:00
|
|
|
$results = $f->pagesIncluded();
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2009-11-22 09:23:12 +01:00
|
|
|
$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]
|
|
|
|
);
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Check that only changed pages are returned
|
|
|
|
$f = new CMSSiteTreeFilter_ChangedPages(array('Term' => 'No Matches'));
|
|
|
|
$results = $f->pagesIncluded();
|
|
|
|
$this->assertEquals(0, count($results));
|
2014-08-07 05:49:09 +02:00
|
|
|
|
|
|
|
// If we roll back to an earlier version than what's on the published site, we should still show the changed
|
|
|
|
$changedPage->Title = 'Changed 2';
|
2016-04-01 05:17:37 +02:00
|
|
|
$changedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2014-08-07 05:49:09 +02:00
|
|
|
$changedPage->doRollbackTo(1);
|
|
|
|
|
|
|
|
$f = new CMSSiteTreeFilter_ChangedPages(array('Term' => 'Changed'));
|
|
|
|
$results = $f->pagesIncluded();
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($results));
|
|
|
|
$this->assertEquals(array('ID' => $changedPage->ID, 'ParentID' => 0), $results[0]);
|
2009-11-22 09:23:12 +01:00
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function testDeletedPagesFilter() {
|
2009-11-22 09:23:12 +01:00
|
|
|
$deletedPage = $this->objFromFixture('Page', 'page2');
|
2016-04-01 05:17:37 +02:00
|
|
|
$deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2009-11-22 09:23:12 +01:00
|
|
|
$deletedPageID = $deletedPage->ID;
|
|
|
|
$deletedPage->delete();
|
|
|
|
$deletedPage = Versioned::get_one_by_stage(
|
2016-01-06 00:42:07 +01:00
|
|
|
'SiteTree',
|
|
|
|
'Live',
|
2013-06-21 00:45:33 +02:00
|
|
|
array('"SiteTree_Live"."ID"' => $deletedPageID)
|
2009-11-22 09:23:12 +01:00
|
|
|
);
|
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
$f = new CMSSiteTreeFilter_DeletedPages(array('Term' => 'Page'));
|
2009-11-22 09:23:12 +01:00
|
|
|
$this->assertTrue($f->isPageIncluded($deletedPage));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Check that only changed pages are returned
|
|
|
|
$f = new CMSSiteTreeFilter_DeletedPages(array('Term' => 'No Matches'));
|
|
|
|
$this->assertFalse($f->isPageIncluded($deletedPage));
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
public function testStatusDraftPagesFilter() {
|
|
|
|
$draftPage = $this->objFromFixture('Page', 'page4');
|
|
|
|
$draftPage = Versioned::get_one_by_stage(
|
2016-01-06 00:42:07 +01:00
|
|
|
'SiteTree',
|
|
|
|
'Stage',
|
2014-03-27 20:29:30 +01:00
|
|
|
sprintf('"SiteTree"."ID" = %d', $draftPage->ID)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check draft page is shown
|
|
|
|
$f = new CMSSiteTreeFilter_StatusDraftPages(array('Term' => 'Page'));
|
|
|
|
$this->assertTrue($f->isPageIncluded($draftPage));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Check filter respects parameters
|
|
|
|
$f = new CMSSiteTreeFilter_StatusDraftPages(array('Term' => 'No Match'));
|
|
|
|
$this->assertEmpty($f->isPageIncluded($draftPage));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Ensures empty array returned if no data to show
|
|
|
|
$f = new CMSSiteTreeFilter_StatusDraftPages();
|
|
|
|
$draftPage->delete();
|
2016-03-08 21:50:55 +01:00
|
|
|
$this->assertEmpty($f->isPageIncluded($draftPage));
|
2014-07-24 04:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDateFromToLastSameDate() {
|
|
|
|
$draftPage = $this->objFromFixture('Page', 'page4');
|
|
|
|
// Grab the date
|
|
|
|
$date = substr($draftPage->LastEdited, 0, 10);
|
|
|
|
// Filter with that date
|
|
|
|
$filter = New CMSSiteTreeFilter_Search(array(
|
|
|
|
'LastEditedFrom' => $date,
|
|
|
|
'LastEditedTo' => $date
|
|
|
|
));
|
|
|
|
$this->assertTrue($filter->isPageIncluded($draftPage), 'Using the same date for from and to should show find that page');
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
public function testStatusRemovedFromDraftFilter() {
|
|
|
|
$removedDraftPage = $this->objFromFixture('Page', 'page6');
|
2016-04-01 05:17:37 +02:00
|
|
|
$removedDraftPage->publishRecursive();
|
2014-03-27 20:29:30 +01:00
|
|
|
$removedDraftPage->deleteFromStage('Stage');
|
|
|
|
$removedDraftPage = Versioned::get_one_by_stage(
|
2016-01-06 00:42:07 +01:00
|
|
|
'SiteTree',
|
|
|
|
'Live',
|
2014-03-27 20:29:30 +01:00
|
|
|
sprintf('"SiteTree"."ID" = %d', $removedDraftPage->ID)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check live-only page is included
|
|
|
|
$f = new CMSSiteTreeFilter_StatusRemovedFromDraftPages(array('LastEditedFrom' => '2000-01-01 00:00'));
|
|
|
|
$this->assertTrue($f->isPageIncluded($removedDraftPage));
|
|
|
|
|
|
|
|
// Check filter is respected
|
|
|
|
$f = new CMSSiteTreeFilter_StatusRemovedFromDraftPages(array('LastEditedTo' => '1999-01-01 00:00'));
|
|
|
|
$this->assertEmpty($f->isPageIncluded($removedDraftPage));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Ensures empty array returned if no data to show
|
|
|
|
$f = new CMSSiteTreeFilter_StatusRemovedFromDraftPages();
|
|
|
|
$removedDraftPage->delete();
|
|
|
|
$this->assertEmpty($f->isPageIncluded($removedDraftPage));
|
|
|
|
}
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
public function testStatusDeletedFilter() {
|
|
|
|
$deletedPage = $this->objFromFixture('Page', 'page7');
|
2016-04-01 05:17:37 +02:00
|
|
|
$deletedPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
2014-03-27 20:29:30 +01:00
|
|
|
$deletedPageID = $deletedPage->ID;
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Can't use straight $blah->delete() as that blows it away completely and test fails
|
2016-06-02 05:56:45 +02:00
|
|
|
$deletedPage->deleteFromStage(Versioned::LIVE);
|
|
|
|
$deletedPage->deleteFromStage(Versioned::DRAFT);
|
2014-03-27 20:29:30 +01:00
|
|
|
$checkParentExists = Versioned::get_latest_version('SiteTree', $deletedPageID);
|
|
|
|
|
|
|
|
// Check deleted page is included
|
|
|
|
$f = new CMSSiteTreeFilter_StatusDeletedPages(array('Title' => 'Page'));
|
|
|
|
$this->assertTrue($f->isPageIncluded($checkParentExists));
|
2016-03-08 21:50:55 +01:00
|
|
|
|
2014-03-27 20:29:30 +01:00
|
|
|
// Check filter is respected
|
|
|
|
$f = new CMSSiteTreeFilter_StatusDeletedPages(array('Title' => 'Bobby'));
|
|
|
|
$this->assertFalse($f->isPageIncluded($checkParentExists));
|
2009-11-22 09:23:12 +01:00
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|