1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CMS\Tests\Tasks; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Tasks\RemoveOrphanedPagesTask; |
6
|
|
|
use SilverStripe\Dev\FunctionalTest; |
7
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* <h2>Fixture tree</h2> |
11
|
|
|
* <code> |
12
|
|
|
* parent1_published |
13
|
|
|
* child1_1_published |
14
|
|
|
* grandchild1_1_1 |
15
|
|
|
* grandchild1_1_2_published |
16
|
|
|
* grandchild1_1_3_orphaned |
17
|
|
|
* grandchild1_1_4_orphaned_published |
18
|
|
|
* child1_2_published |
19
|
|
|
* child1_3_orphaned |
20
|
|
|
* child1_4_orphaned_published |
21
|
|
|
* parent2 |
22
|
|
|
* child2_1_published_orphaned // is orphaned because parent is not published |
23
|
|
|
* </code> |
24
|
|
|
* |
25
|
|
|
* <h2>Cleaned up tree</h2> |
26
|
|
|
* <code> |
27
|
|
|
* parent1_published |
28
|
|
|
* child1_1_published |
29
|
|
|
* grandchild1_1_1 |
30
|
|
|
* grandchild1_1_2_published |
31
|
|
|
* child2_1_published_orphaned |
32
|
|
|
* parent2 |
33
|
|
|
* </code> |
34
|
|
|
* |
35
|
|
|
* @author Ingo Schommer (<firstname>@silverstripe.com), SilverStripe Ltd. |
36
|
|
|
*/ |
37
|
|
|
class RemoveOrphanedPagesTaskTest extends FunctionalTest |
38
|
|
|
{ |
39
|
|
|
protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml'; |
40
|
|
|
|
41
|
|
|
protected function setUp() : void |
42
|
|
|
{ |
43
|
|
|
parent::setUp(); |
44
|
|
|
|
45
|
|
|
$parent1_published = $this->objFromFixture(SiteTree::class, 'parent1_published'); |
46
|
|
|
$parent1_published->publishSingle(); |
47
|
|
|
|
48
|
|
|
$child1_1_published = $this->objFromFixture(SiteTree::class, 'child1_1_published'); |
49
|
|
|
$child1_1_published->publishSingle(); |
50
|
|
|
|
51
|
|
|
$child1_2_published = $this->objFromFixture(SiteTree::class, 'child1_2_published'); |
52
|
|
|
$child1_2_published->publishSingle(); |
53
|
|
|
|
54
|
|
|
$child1_3_orphaned = $this->objFromFixture(SiteTree::class, 'child1_3_orphaned'); |
55
|
|
|
$child1_3_orphaned->ParentID = 9999; |
56
|
|
|
$child1_3_orphaned->write(); |
57
|
|
|
|
58
|
|
|
$child1_4_orphaned_published = $this->objFromFixture(SiteTree::class, 'child1_4_orphaned_published'); |
59
|
|
|
$child1_4_orphaned_published->ParentID = 9999; |
60
|
|
|
$child1_4_orphaned_published->write(); |
61
|
|
|
$child1_4_orphaned_published->publishSingle(); |
62
|
|
|
|
63
|
|
|
$grandchild1_1_2_published = $this->objFromFixture(SiteTree::class, 'grandchild1_1_2_published'); |
64
|
|
|
$grandchild1_1_2_published->publishSingle(); |
65
|
|
|
|
66
|
|
|
$grandchild1_1_3_orphaned = $this->objFromFixture(SiteTree::class, 'grandchild1_1_3_orphaned'); |
67
|
|
|
$grandchild1_1_3_orphaned->ParentID = 9999; |
68
|
|
|
$grandchild1_1_3_orphaned->write(); |
69
|
|
|
|
70
|
|
|
$grandchild1_1_4_orphaned_published = $this->objFromFixture( |
71
|
|
|
SiteTree::class, |
72
|
|
|
'grandchild1_1_4_orphaned_published' |
73
|
|
|
); |
74
|
|
|
$grandchild1_1_4_orphaned_published->ParentID = 9999; |
75
|
|
|
$grandchild1_1_4_orphaned_published->write(); |
76
|
|
|
$grandchild1_1_4_orphaned_published->publishSingle(); |
77
|
|
|
|
78
|
|
|
$child2_1_published_orphaned = $this->objFromFixture(SiteTree::class, 'child2_1_published_orphaned'); |
79
|
|
|
$child2_1_published_orphaned->publishSingle(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetOrphansByStage() |
83
|
|
|
{ |
84
|
|
|
// all orphans |
85
|
|
|
$child1_3_orphaned = $this->objFromFixture(SiteTree::class, 'child1_3_orphaned'); |
86
|
|
|
$child1_4_orphaned_published = $this->objFromFixture(SiteTree::class, 'child1_4_orphaned_published'); |
87
|
|
|
$grandchild1_1_3_orphaned = $this->objFromFixture(SiteTree::class, 'grandchild1_1_3_orphaned'); |
88
|
|
|
$grandchild1_1_4_orphaned_published = $this->objFromFixture( |
89
|
|
|
SiteTree::class, |
90
|
|
|
'grandchild1_1_4_orphaned_published' |
91
|
|
|
); |
92
|
|
|
$child2_1_published_orphaned = $this->objFromFixture(SiteTree::class, 'child2_1_published_orphaned'); |
93
|
|
|
|
94
|
|
|
$task = singleton(RemoveOrphanedPagesTask::class); |
95
|
|
|
$orphans = $task->getOrphanedPages(); |
96
|
|
|
$orphanIDs = $orphans->column('ID'); |
97
|
|
|
sort($orphanIDs); |
98
|
|
|
$compareIDs = [ |
99
|
|
|
$child1_3_orphaned->ID, |
100
|
|
|
$child1_4_orphaned_published->ID, |
101
|
|
|
$grandchild1_1_3_orphaned->ID, |
102
|
|
|
$grandchild1_1_4_orphaned_published->ID, |
103
|
|
|
$child2_1_published_orphaned->ID, |
104
|
|
|
]; |
105
|
|
|
sort($compareIDs); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($orphanIDs, $compareIDs); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|