2011-03-18 04:37:22 +01:00
|
|
|
<?php
|
2016-06-16 06:57:19 +02:00
|
|
|
|
2017-08-09 04:53:38 +02:00
|
|
|
namespace SilverStripe\CMS\Tests\Tasks;
|
2017-08-09 03:25:12 +02:00
|
|
|
|
2018-03-21 05:44:24 +01:00
|
|
|
use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask;
|
2017-03-21 05:26:46 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-08-23 04:36:06 +02:00
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
|
2011-03-18 04:37:22 +01:00
|
|
|
/**
|
|
|
|
* <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>
|
2016-01-06 00:42:07 +01:00
|
|
|
*
|
2011-03-18 04:37:22 +01:00
|
|
|
* <h2>Cleaned up tree</h2>
|
|
|
|
* <code>
|
|
|
|
* parent1_published
|
|
|
|
* child1_1_published
|
|
|
|
* grandchild1_1_1
|
|
|
|
* grandchild1_1_2_published
|
|
|
|
* child2_1_published_orphaned
|
|
|
|
* parent2
|
|
|
|
* </code>
|
2016-01-06 00:42:07 +01:00
|
|
|
*
|
2011-03-18 04:37:22 +01:00
|
|
|
* @author Ingo Schommer (<firstname>@silverstripe.com), SilverStripe Ltd.
|
|
|
|
*/
|
2017-01-25 21:59:25 +01:00
|
|
|
class RemoveOrphanedPagesTaskTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml';
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$parent1_published = $this->objFromFixture('Page', 'parent1_published');
|
2018-03-21 05:44:24 +01:00
|
|
|
$parent1_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$child1_1_published = $this->objFromFixture('Page', 'child1_1_published');
|
2018-03-21 05:44:24 +01:00
|
|
|
$child1_1_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$child1_2_published = $this->objFromFixture('Page', 'child1_2_published');
|
2018-03-21 05:44:24 +01:00
|
|
|
$child1_2_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$child1_3_orphaned = $this->objFromFixture('Page', 'child1_3_orphaned');
|
|
|
|
$child1_3_orphaned->ParentID = 9999;
|
|
|
|
$child1_3_orphaned->write();
|
|
|
|
|
|
|
|
$child1_4_orphaned_published = $this->objFromFixture('Page', 'child1_4_orphaned_published');
|
|
|
|
$child1_4_orphaned_published->ParentID = 9999;
|
|
|
|
$child1_4_orphaned_published->write();
|
2018-03-21 05:44:24 +01:00
|
|
|
$child1_4_orphaned_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$grandchild1_1_2_published = $this->objFromFixture('Page', 'grandchild1_1_2_published');
|
2018-03-21 05:44:24 +01:00
|
|
|
$grandchild1_1_2_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$grandchild1_1_3_orphaned = $this->objFromFixture('Page', 'grandchild1_1_3_orphaned');
|
|
|
|
$grandchild1_1_3_orphaned->ParentID = 9999;
|
|
|
|
$grandchild1_1_3_orphaned->write();
|
|
|
|
|
|
|
|
$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();
|
2018-03-21 05:44:24 +01:00
|
|
|
$grandchild1_1_4_orphaned_published->publishSingle();
|
2017-01-25 21:59:25 +01:00
|
|
|
|
|
|
|
$child2_1_published_orphaned = $this->objFromFixture('Page', 'child2_1_published_orphaned');
|
2018-03-21 05:44:24 +01:00
|
|
|
$child2_1_published_orphaned->publishSingle();
|
2017-01-25 21:59:25 +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');
|
|
|
|
|
2018-03-21 05:44:24 +01:00
|
|
|
$task = singleton(RemoveOrphanedPagesTask::class);
|
2017-01-25 21:59:25 +01:00
|
|
|
$orphans = $task->getOrphanedPages();
|
|
|
|
$orphanIDs = $orphans->column('ID');
|
|
|
|
sort($orphanIDs);
|
2020-04-19 06:18:01 +02:00
|
|
|
$compareIDs = [
|
2017-01-25 21:59:25 +01:00
|
|
|
$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
|
2020-04-19 06:18:01 +02:00
|
|
|
];
|
2017-01-25 21:59:25 +01:00
|
|
|
sort($compareIDs);
|
|
|
|
|
|
|
|
$this->assertEquals($orphanIDs, $compareIDs);
|
|
|
|
}
|
2011-03-18 04:37:22 +01:00
|
|
|
}
|