1 | <?php |
||
2 | |||
3 | namespace DNADesign\Elemental\Tests\Reports; |
||
4 | |||
5 | use DNADesign\Elemental\Reports\ElementsInUseReport; |
||
6 | use DNADesign\Elemental\Tests\Src\TestElement; |
||
7 | use DNADesign\Elemental\Tests\Src\TestPage; |
||
8 | use SilverStripe\Dev\FunctionalTest; |
||
9 | use SilverStripe\ORM\ArrayList; |
||
10 | use SilverStripe\View\ArrayData; |
||
11 | |||
12 | class ElementsInUseReportTest extends FunctionalTest |
||
13 | { |
||
14 | protected static $fixture_file = 'ElementsInUseReportTest.yml'; |
||
15 | |||
16 | protected static $extra_dataobjects = [ |
||
17 | TestElement::class, |
||
18 | TestPage::class, |
||
19 | ]; |
||
20 | |||
21 | public function testReportShowsElementsInUse() |
||
22 | { |
||
23 | $this->logInWithPermission('ADMIN'); |
||
24 | |||
25 | $result = (string) $this->get('admin/reports/show/DNADesign-Elemental-Reports-ElementsInUseReport')->getBody(); |
||
26 | |||
27 | $this->assertContains('Content blocks in use', $result, 'Title is displayed'); |
||
28 | |||
29 | $this->assertContains( |
||
30 | 'data-class="DNADesign-Elemental-Models-ElementContent"', |
||
31 | $result, |
||
32 | 'Report contains content elements (bundled with elemental)' |
||
33 | ); |
||
34 | |||
35 | $this->assertContains('HTML text block', $result, 'Content element "nice" type is shown'); |
||
36 | |||
37 | $this->assertContains('My special content block', $result, 'Fixtured content element is shown'); |
||
38 | $this->assertContains('Stubby Stub', $result, 'Fixtured stub element is shown'); |
||
39 | } |
||
40 | |||
41 | public function testSourceRecords() |
||
42 | { |
||
43 | $records = (new ElementsInUseReport)->sourceRecords(); |
||
44 | |||
45 | $this->assertInstanceOf(ArrayList::class, $records); |
||
46 | $this->assertNotContains(BaseElement::class, $records->toArray(), 'BaseElement is excluded'); |
||
0 ignored issues
–
show
|
|||
47 | |||
48 | $this->assertContainsOnlyInstancesOf(ArrayData::class, $records); |
||
49 | |||
50 | foreach ($records as $record) { |
||
51 | $this->assertNotNull($record->Icon, 'Fields have an icon'); |
||
52 | $this->assertNotNull($record->Type, 'Fields have a type'); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | public function testElementsAssociatedToPagesHaveEditLink() |
||
57 | { |
||
58 | $records = (new ElementsInUseReport)->sourceRecords()->filter(['Title' => 'Welcome to Castros']); |
||
59 | |||
60 | $castros = $records->first(); |
||
61 | $this->assertNotNull($castros, 'Fixtured Castros page exists'); |
||
62 | $this->assertTrue($castros->hasField('EditLink')); |
||
63 | $this->assertContains( |
||
64 | (string) $this->idFromFixture(TestPage::class, 'castros_home'), |
||
65 | $castros->EditLink, |
||
66 | 'Correct owner page ID is in edit link' |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | public function testSourceRecordsFilteredByClassName() |
||
71 | { |
||
72 | $records = (new ElementsInUseReport)->sourceRecords([ |
||
73 | 'ClassName' => 'DNADesign-Elemental-Models-ElementContent', |
||
74 | ]); |
||
75 | |||
76 | $this->assertInstanceOf(ArrayList::class, $records); |
||
77 | $this->assertNotEmpty($records->toArray(), 'Results are returned when filtered'); |
||
78 | $this->assertEquals( |
||
79 | [ |
||
80 | 'DNADesign-Elemental-Models-ElementContent' |
||
81 | ], |
||
82 | array_unique($records->column('ClassName')), |
||
83 | 'Only contains filtered element type' |
||
84 | ); |
||
85 | } |
||
86 | } |
||
87 |
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