silverstripe-cms/tests/tasks/RemoveOrphanedPagesTaskTest.php

105 lines
3.6 KiB
PHP
Raw Normal View History

<?php
/**
* <h2>Fixture tree</h2>
* <code>
* parent1_published
* child1_1_published
* grandchild1_1_1
* grandchild1_1_2_published
* grandchild1_1_3_orphaned
* grandchild1_1_4_orphaned_published
* child1_2_published
* child1_3_orphaned
* child1_4_orphaned_published
* parent2
* child2_1_published_orphaned // is orphaned because parent is not published
* </code>
*
* <h2>Cleaned up tree</h2>
* <code>
* parent1_published
* child1_1_published
* grandchild1_1_1
* grandchild1_1_2_published
* child2_1_published_orphaned
* parent2
* </code>
*
* @author Ingo Schommer (<firstname>@silverstripe.com), SilverStripe Ltd.
*
* @package cms
* @subpackage tests
*/
class RemoveOrphanedPagesTaskTest extends FunctionalTest {
2016-03-08 21:50:55 +01:00
protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml';
2016-03-08 21:50:55 +01:00
protected static $use_draft_site = false;
2016-03-08 21:50:55 +01:00
public function setUp() {
parent::setUp();
2016-03-08 21:50:55 +01:00
$parent1_published = $this->objFromFixture('Page', 'parent1_published');
2016-04-01 05:17:37 +02:00
$parent1_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$child1_1_published = $this->objFromFixture('Page', 'child1_1_published');
2016-04-01 05:17:37 +02:00
$child1_1_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$child1_2_published = $this->objFromFixture('Page', 'child1_2_published');
2016-04-01 05:17:37 +02:00
$child1_2_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned');
$child1_3_orphaned->ParentID = 9999;
$child1_3_orphaned->write();
2016-03-08 21:50:55 +01:00
$child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published');
$child1_4_orphaned_published->ParentID = 9999;
$child1_4_orphaned_published->write();
2016-04-01 05:17:37 +02:00
$child1_4_orphaned_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$grandchild1_1_2_published = $this->objFromFixture('Page', 'grandchild1_1_2_published');
2016-04-01 05:17:37 +02:00
$grandchild1_1_2_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$grandchild1_1_3_orphaned = $this->objFromFixture('Page', 'grandchild1_1_3_orphaned');
$grandchild1_1_3_orphaned->ParentID = 9999;
$grandchild1_1_3_orphaned->write();
2016-03-08 21:50:55 +01:00
$grandchild1_1_4_orphaned_published = $this->objFromFixture('Page',
'grandchild1_1_4_orphaned_published'
);
$grandchild1_1_4_orphaned_published->ParentID = 9999;
$grandchild1_1_4_orphaned_published->write();
2016-04-01 05:17:37 +02:00
$grandchild1_1_4_orphaned_published->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
2016-03-08 21:50:55 +01:00
$child2_1_published_orphaned = $this->objFromFixture('Page', 'child2_1_published_orphaned');
2016-04-01 05:17:37 +02:00
$child2_1_published_orphaned->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
}
2016-03-08 21:50:55 +01:00
public function testGetOrphansByStage() {
// all orphans
$child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned');
$child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published');
$grandchild1_1_3_orphaned = $this->objFromFixture('Page', 'grandchild1_1_3_orphaned');
$grandchild1_1_4_orphaned_published = $this->objFromFixture('Page',
'grandchild1_1_4_orphaned_published'
);
$child2_1_published_orphaned = $this->objFromFixture('Page', 'child2_1_published_orphaned');
2016-03-08 21:50:55 +01:00
$task = singleton('RemoveOrphanedPagesTask');
$orphans = $task->getOrphanedPages();
$orphanIDs = $orphans->column('ID');
sort($orphanIDs);
$compareIDs = array(
$child1_3_orphaned->ID,
$child1_4_orphaned_published->ID,
$grandchild1_1_3_orphaned->ID,
$grandchild1_1_4_orphaned_published->ID,
$child2_1_published_orphaned->ID
);
sort($compareIDs);
2016-03-08 21:50:55 +01:00
$this->assertEquals($orphanIDs, $compareIDs);
}
2016-03-08 21:50:55 +01:00
}