1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Tests; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Extensions\ElementalPageExtension; |
6
|
|
|
use DNADesign\Elemental\Models\ElementalArea; |
7
|
|
|
use DNADesign\Elemental\Tests\Src\TestElement; |
8
|
|
|
use DNADesign\Elemental\Tests\Src\TestPage; |
9
|
|
|
use Page; |
|
|
|
|
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
use SilverStripe\Versioned\Versioned; |
12
|
|
|
|
13
|
|
|
class ElementalAreaTest extends SapphireTest |
14
|
|
|
{ |
15
|
|
|
protected static $fixture_file = 'ElementalAreaTest.yml'; |
16
|
|
|
|
17
|
|
|
protected static $required_extensions = [ |
18
|
|
|
Page::class => [ |
19
|
|
|
ElementalPageExtension::class, |
20
|
|
|
], |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
protected static $extra_dataobjects = [ |
24
|
|
|
TestElement::class, |
25
|
|
|
TestPage::class, |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
public function testElementControllers() |
29
|
|
|
{ |
30
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area1'); |
31
|
|
|
$controllers = $area->ElementControllers(); |
32
|
|
|
|
33
|
|
|
$this->assertEquals(2, $controllers->count(), 'Should be a controller per element'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCanViewTestElementIsFalseWhenLoggedInAsCmsEditor() |
37
|
|
|
{ |
38
|
|
|
/** @var ElementalArea $area */ |
39
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area2'); |
40
|
|
|
// Content editors do not have permission to view the TestElement |
41
|
|
|
$this->logInWithPermission('VIEW_DRAFT_CONTENT'); |
42
|
|
|
|
43
|
|
|
$controllers = $area->ElementControllers(); |
44
|
|
|
$this->assertCount(2, $area->Elements(), 'There are two elements in total'); |
45
|
|
|
$this->assertCount( |
46
|
|
|
1, |
47
|
|
|
$controllers, |
48
|
|
|
'Should be one controller only, since TestElement is not viewable by non-admins' |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testCanViewTestElementIsTrueForAdmins() |
53
|
|
|
{ |
54
|
|
|
/** @var ElementalArea $area */ |
55
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area2'); |
56
|
|
|
// Admin users have permission to view the TestElement |
57
|
|
|
$this->logInWithPermission('ADMIN'); |
58
|
|
|
|
59
|
|
|
$controllers = $area->ElementControllers(); |
60
|
|
|
$this->assertCount(2, $area->Elements(), 'There are two elements in total'); |
61
|
|
|
$this->assertCount( |
62
|
|
|
2, |
63
|
|
|
$controllers, |
64
|
|
|
'Should be two controllers when logged in as admin' |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetOwnerPage() |
69
|
|
|
{ |
70
|
|
|
$area1 = $this->objFromFixture(ElementalArea::class, 'area1'); |
71
|
|
|
$area2 = $this->objFromFixture(ElementalArea::class, 'area2'); |
72
|
|
|
|
73
|
|
|
// OwnerClassName not set |
74
|
|
|
$ownerpage1 = $area1->getOwnerPage(); |
75
|
|
|
// OwnerClassName set |
76
|
|
|
$ownerpage2 = $area2->getOwnerPage(); |
77
|
|
|
|
78
|
|
|
$this->assertEquals("DNADesign\Elemental\Tests\Src\TestPage", $ownerpage1); |
79
|
|
|
$this->assertEquals("DNADesign\Elemental\Tests\Src\TestPage", $ownerpage2); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testForTemplate() |
83
|
|
|
{ |
84
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area1'); |
85
|
|
|
|
86
|
|
|
$this->assertContains('Hello Test', $area->forTemplate()); |
87
|
|
|
$this->assertContains('Hello Test 2', $area->forTemplate()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testCanBePublished() |
91
|
|
|
{ |
92
|
|
|
$member = $this->logInWithPermission('SITETREE_EDIT_ALL'); |
93
|
|
|
|
94
|
|
|
/** @var Page $page */ |
95
|
|
|
$page = $this->objFromFixture(TestPage::class, 'page1'); |
96
|
|
|
$this->assertTrue($page->canPublish($member)); |
97
|
|
|
|
98
|
|
|
/** @var ElementalArea|Versioned $area */ |
99
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area1'); |
100
|
|
|
$this->assertTrue($area->canPublish($member)); |
|
|
|
|
101
|
|
|
|
102
|
|
|
/** @var TestElement|Versioned $element */ |
103
|
|
|
$element = $this->objFromFixture(TestElement::class, 'element1'); |
104
|
|
|
$this->assertTrue($element->canPublish($member)); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testDuplicate() |
108
|
|
|
{ |
109
|
|
|
/** @var ElementalArea $area */ |
110
|
|
|
$area = $this->objFromFixture(ElementalArea::class, 'area1'); |
111
|
|
|
$areaIds = $area->Elements()->column('ID'); |
112
|
|
|
$this->assertCount(2, $areaIds); |
113
|
|
|
|
114
|
|
|
$duplicatedArea = $area->duplicate(true); |
115
|
|
|
$duplicatedAreaIds = $duplicatedArea->Elements()->column('ID'); |
116
|
|
|
$this->assertCount(2, $duplicatedAreaIds); |
117
|
|
|
$this->assertNotEquals($areaIds, $duplicatedAreaIds); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths