Completed
Pull Request — master (#6)
by Robbie
02:40
created

CwpStatsReportTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testCount() 0 28 3
1
<?php
2
3
namespace CWP\Core\Tests;
4
5
use CWP\Core\Report\CwpStatsReport;
6
use Page;
0 ignored issues
show
Bug introduced by
The type Page 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...
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Subsites\Model\Subsite;
0 ignored issues
show
Bug introduced by
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. 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...
9
10
class CwpStatsReportTest extends SapphireTest
11
{
12
    protected static $fixture_file = 'CwpStatsReportTest.yml';
13
14
    public function testCount()
15
    {
16
        // Publish all pages apart from page3.
17
        $this->objFromFixture(Page::class, 'page1')->publishRecursive();
18
        $this->objFromFixture(Page::class, 'page2')->publishRecursive();
19
        $this->objFromFixture(Page::class, 'page3')->publishRecursive();
20
21
        // Add page5s to a subsite, if the module is installed.
22
        $page5s = $this->objFromFixture(Page::class, 'page5s');
23
        if (class_exists(Subsite::class)) {
24
            $subsite = Subsite::create();
25
            $subsite->Title = 'subsite';
26
            $subsite->write();
27
28
            $page5s->SubsiteID = $subsite->ID;
29
            $page5s->write();
30
        }
31
        $page5s->publishRecursive();
32
33
        $report = CwpStatsReport::create();
34
        $records = $report->sourceRecords([])->toArray();
35
        $i = 0;
36
        $this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
37
        if (class_exists(Subsite::class)) {
38
            $this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
39
            $this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
40
        }
41
        $this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
42
    }
43
}
44