Passed
Push — 1 ( 67274c )
by Robbie
02:29
created

CwpStatsReportTest::testCount()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 19
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 27
rs 8.8571
1
<?php
2
3
class CwpStatsReportTest extends SapphireTest {
4
5
	protected static $fixture_file = 'cwp-core/tests/CwpStatsReportTest.yml';
6
7
	public function testCount() {
8
		// Publish all pages apart from page3.
9
		$this->objFromFixture('Page', 'page1')->doPublish();
10
		$this->objFromFixture('Page', 'page2')->doPublish();
11
		$this->objFromFixture('Page', 'page3')->doPublish();
12
13
		// Add page5s to a subsite, if the module is installed.
14
		$page5s = $this->objFromFixture('Page', 'page5s');
15
		if(class_exists('Subsite')) {
16
			$subsite = Subsite::create();
0 ignored issues
show
Bug introduced by
The type 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
			$subsite->Title = 'subsite';
18
			$subsite->write();
19
20
			$page5s->SubsiteID = $subsite->ID;
21
			$page5s->write();
22
		}
23
		$page5s->doPublish();
24
25
		$report = CwpStatsReport::create();
26
		$records = $report->sourceRecords(array())->toArray();
27
		$i = 0;
28
		$this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
29
		if(class_exists('Subsite')) {
30
			$this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
31
			$this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
32
		}
33
		$this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
34
	}
35
36
}
37