1 | <?php |
||||
2 | |||||
3 | namespace SilverStripe\SiteWideContentReport\Tests; |
||||
4 | |||||
5 | use Page; |
||||
0 ignored issues
–
show
|
|||||
6 | use SilverStripe\CMS\Model\SiteTree; |
||||
7 | use SilverStripe\ContentReview\Extensions\SiteTreeContentReview; |
||||
0 ignored issues
–
show
The type
SilverStripe\ContentRevi...s\SiteTreeContentReview was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
8 | use SilverStripe\Core\Config\Config; |
||||
9 | use SilverStripe\Dev\SapphireTest; |
||||
10 | use SilverStripe\Forms\DropdownField; |
||||
11 | use SilverStripe\Forms\FieldList; |
||||
12 | use SilverStripe\Forms\GridField\GridFieldDataColumns; |
||||
13 | use SilverStripe\Forms\GridField\GridFieldExportButton; |
||||
14 | use SilverStripe\ORM\DataList; |
||||
15 | use SilverStripe\SiteWideContentReport\Model\SitewideContentTaxonomy; |
||||
16 | use SilverStripe\SiteWideContentReport\SitewideContentReport; |
||||
17 | use SilverStripe\Subsites\Model\Subsite; |
||||
0 ignored issues
–
show
The type
SilverStripe\Subsites\Model\Subsite was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
18 | |||||
19 | class SitewideContentReportTest extends SapphireTest |
||||
20 | { |
||||
21 | /** |
||||
22 | * @var string |
||||
23 | */ |
||||
24 | protected static $fixture_file = 'SitewideContentReportTest.yml'; |
||||
25 | |||||
26 | public function setUp() |
||||
27 | { |
||||
28 | // Stop default page creation from occuring - just use fixtures |
||||
29 | Config::modify()->set(SiteTree::class, 'create_default_pages', false); |
||||
30 | |||||
31 | // This module is made to work with subsites, but will still operate without it (although presumably being of |
||||
32 | // far less value). The fixture includes subsite definitions, which is a problem if the module isn't installed. |
||||
33 | // So we'll use the same fixture without the subsites definitions if this is the case. |
||||
34 | if (!class_exists(Subsite::class)) { |
||||
35 | static::$fixture_file = 'SitewideContentReportNoSubsitesTest.yml'; |
||||
36 | } |
||||
37 | |||||
38 | parent::setUp(); |
||||
39 | |||||
40 | foreach (range(1, 5) as $i) { |
||||
41 | /** @var SiteTree $page */ |
||||
42 | $page = $this->objFromFixture(Page::class, "page{$i}"); |
||||
43 | |||||
44 | if ($i <= 3) { |
||||
45 | $page->publishRecursive(); |
||||
46 | } |
||||
47 | } |
||||
48 | } |
||||
49 | |||||
50 | public function testSourceRecords() |
||||
51 | { |
||||
52 | $report = SitewideContentReport::create(); |
||||
53 | $records = $report->sourceRecords([]); |
||||
54 | |||||
55 | $this->assertCount(2, $records, 'Returns an array with 2 items, one for pages and one for files'); |
||||
56 | $this->assertArrayHasKey('Pages', $records); |
||||
0 ignored issues
–
show
It seems like
$records can also be of type Countable and Traversable ; however, parameter $array of PHPUnit_Framework_Assert::assertArrayHasKey() does only seem to accept ArrayAccess|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
57 | $this->assertArrayHasKey('Files', $records); |
||||
58 | |||||
59 | /** @var DataList $pages */ |
||||
60 | $pages = $records['Pages']; |
||||
61 | |||||
62 | /** @var DataList $files */ |
||||
63 | $files = $records['Files']; |
||||
64 | |||||
65 | $this->assertCount(5, $pages, 'Total number of pages'); |
||||
66 | $this->assertCount(1, $files, 'Total number of files'); |
||||
67 | } |
||||
68 | |||||
69 | public function testParameterFields() |
||||
70 | { |
||||
71 | $report = SitewideContentReport::create(); |
||||
72 | /** @var FieldList $fields */ |
||||
73 | $fields = $report->parameterFields(); |
||||
74 | |||||
75 | if (class_exists(Subsite::class)) { |
||||
76 | /** @var DropdownField $field */ |
||||
77 | $field = $fields->fieldByName('AllSubsites'); |
||||
78 | $keys = array_filter(array_keys($field->getSource())); |
||||
0 ignored issues
–
show
It seems like
$field->getSource() can also be of type ArrayAccess ; however, parameter $input of array_keys() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
79 | |||||
80 | $this->assertCount(4, $keys, '2 subsites plus 2 added options to filter by subsite'); |
||||
81 | } else { |
||||
82 | $this->assertNull($fields); |
||||
83 | } |
||||
84 | } |
||||
85 | |||||
86 | public function testReportFields() |
||||
87 | { |
||||
88 | $report = SitewideContentReport::create(); |
||||
89 | |||||
90 | // Test pages view |
||||
91 | $gridField = $report->getReportField('Pages'); |
||||
92 | |||||
93 | /* @var $columns GridFieldDataColumns */ |
||||
94 | $columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class); |
||||
95 | $displayed = $columns->getDisplayFields($gridField); |
||||
96 | |||||
97 | $this->assertArrayHasKey('Title', $displayed); |
||||
98 | $this->assertArrayHasKey('Created', $displayed); |
||||
99 | $this->assertArrayHasKey('LastEdited', $displayed); |
||||
100 | $this->assertArrayHasKey('i18n_singular_name', $displayed); |
||||
101 | $this->assertArrayHasKey('StageState', $displayed); |
||||
102 | |||||
103 | // Use correct link |
||||
104 | $this->assertArrayHasKey('RelativeLink', $displayed); |
||||
105 | $this->assertArrayNotHasKey('AbsoluteLink', $displayed); |
||||
106 | |||||
107 | if (class_exists(Subsite::class)) { |
||||
108 | $this->assertArrayHasKey('SubsiteName', $displayed); |
||||
109 | } else { |
||||
110 | $this->assertArrayNotHasKey('SubsiteName', $displayed); |
||||
111 | } |
||||
112 | |||||
113 | // Export-only fields are not in display list |
||||
114 | $this->assertArrayNotHasKey('Terms', $displayed); |
||||
115 | $this->assertArrayNotHasKey('OwnerNames', $displayed); |
||||
116 | $this->assertArrayNotHasKey('ReviewDate', $displayed); |
||||
117 | $this->assertArrayNotHasKey('MetaDescription', $displayed); |
||||
118 | |||||
119 | // Tests print / export field |
||||
120 | /* @var $export GridFieldExportButton */ |
||||
121 | $export = $gridField->getConfig()->getComponentByType(GridFieldExportButton::class); |
||||
122 | $exported = $export->getExportColumns(); |
||||
123 | |||||
124 | // Make sure all shared columns are in this report |
||||
125 | $this->assertArrayHasKey('Title', $exported); |
||||
126 | $this->assertArrayHasKey('Created', $exported); |
||||
127 | $this->assertArrayHasKey('LastEdited', $exported); |
||||
128 | $this->assertArrayHasKey('i18n_singular_name', $exported); |
||||
129 | $this->assertArrayHasKey('StageState', $exported); |
||||
130 | |||||
131 | // Export-only fields |
||||
132 | $this->assertArrayHasKey('MetaDescription', $exported); |
||||
133 | |||||
134 | // Use correct link |
||||
135 | $this->assertArrayHasKey('AbsoluteLink', $exported); |
||||
136 | $this->assertArrayNotHasKey('RelativeLink', $exported); |
||||
137 | |||||
138 | if (class_exists(Subsite::class)) { |
||||
139 | $this->assertArrayHasKey('SubsiteName', $exported); |
||||
140 | } else { |
||||
141 | $this->assertArrayNotHasKey('SubsiteName', $exported); |
||||
142 | } |
||||
143 | |||||
144 | if (SitewideContentTaxonomy::enabled()) { |
||||
145 | $this->assertArrayHasKey('Terms', $exported); |
||||
146 | } else { |
||||
147 | $this->assertArrayNotHasKey('Terms', $exported); |
||||
148 | } |
||||
149 | |||||
150 | if (class_exists(SiteTreeContentReview::class)) { |
||||
151 | $this->assertArrayHasKey('OwnerNames', $exported); |
||||
152 | $this->assertArrayHasKey('ReviewDate', $exported); |
||||
153 | } else { |
||||
154 | $this->assertArrayNotHasKey('OwnerNames', $exported); |
||||
155 | $this->assertArrayNotHasKey('ReviewDate', $exported); |
||||
156 | } |
||||
157 | } |
||||
158 | } |
||||
159 |
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