Passed
Push — master ( 84eff8...411d56 )
by Robbie
02:49
created

CwpStatsReportTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace CWP\CWP\Tests\Report;
4
5
use CWP\CWP\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\CMS\Model\SiteTree;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Dev\SapphireTest;
10
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...
11
12
class CwpStatsReportTest extends SapphireTest
13
{
14
    protected static $fixture_file = 'CwpStatsReportTest.yml';
15
16
    protected function setUp()
17
    {
18
        Config::modify()->set(SiteTree::class, 'create_default_pages', false);
19
20
        parent::setUp();
21
    }
22
23
    public function testCount()
24
    {
25
        // Publish all pages apart from page3.
26
        $this->objFromFixture(Page::class, 'page1')->publishRecursive();
27
        $this->objFromFixture(Page::class, 'page2')->publishRecursive();
28
        $this->objFromFixture(Page::class, 'page3')->publishRecursive();
29
30
        // Add page5s to a subsite, if the module is installed.
31
        $page5s = $this->objFromFixture(Page::class, 'page5s');
32
        if (class_exists(Subsite::class)) {
33
            $subsite = Subsite::create();
34
            $subsite->Title = 'subsite';
35
            $subsite->write();
36
37
            $page5s->SubsiteID = $subsite->ID;
38
            $page5s->write();
39
        }
40
        $page5s->publishRecursive();
41
42
        $report = CwpStatsReport::create();
43
        $records = $report->sourceRecords([])->toArray();
44
        $i = 0;
45
        $this->assertEquals($records[$i++]['Count'], 4, 'Four pages in total, across locales, subsites, live only.');
46
        if (class_exists(Subsite::class)) {
47
            $this->assertEquals($records[$i++]['Count'], 3, 'Three pages in the main site, if subsites installed.');
48
            $this->assertEquals($records[$i++]['Count'], 1, 'One page in the subsite, if subsites installed');
49
        }
50
        $this->assertEquals($records[$i++]['Count'], 1, 'One file in total.');
51
    }
52
}
53