Completed
Push — master ( 6b5b46...bad9f2 )
by Damian
14s
created

FluentFilteredExtensionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace TractorCow\Fluent\Tests\Extension;
4
5
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...
6
use SilverStripe\CMS\Model\SiteTree;
7
use SilverStripe\Dev\SapphireTest;
8
use TractorCow\Fluent\Extension\FluentFilteredExtension;
9
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
10
use TractorCow\Fluent\Model\Domain;
11
use TractorCow\Fluent\Model\Locale;
12
use TractorCow\Fluent\State\FluentState;
13
14
class FluentFilteredExtensionTest extends SapphireTest
15
{
16
    protected static $fixture_file = 'FluentFilteredExtensionTest.yml';
17
18
    protected static $required_extensions = [
19
        SiteTree::class => [
20
            FluentSiteTreeExtension::class,
21
            FluentFilteredExtension::class,
22
        ],
23
    ];
24
25
    protected function setUp()
26
    {
27
        parent::setUp();
28
29
        // Clear cache
30
        Locale::clearCached();
31
        Domain::clearCached();
32
        FluentState::singleton()
33
            ->setLocale('en_NZ')
34
            ->setIsDomainMode(false);
35
    }
36
37
    public function testAugmentSQLFrontend()
38
    {
39
        FluentState::singleton()
40
            ->setLocale('en_NZ')
41
            ->setIsFrontend(true);
42
43
        $this->assertEquals(1, SiteTree::get()->count());
44
    }
45
46
    public function testAugmentSQLCMS()
47
    {
48
        FluentState::singleton()
49
            ->setLocale('en_NZ')
50
            ->setIsFrontend(false);
51
52
        $this->assertEquals(2, SiteTree::get()->count());
53
    }
54
55
    public function testUpdateCMSFields()
56
    {
57
        /** @var Page|FluentSiteTreeExtension $page */
58
        $page = SiteTree::get()->filter('URLSegment', 'home')->first();
59
        $fields = $page->getCMSFields();
0 ignored issues
show
Bug introduced by
The method getCMSFields() does not exist on TractorCow\Fluent\Extens...FluentSiteTreeExtension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        $fields = $page->getCMSFields();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
61
        $this->assertNotNull($fields->dataFieldByName('FilteredLocales'));
62
    }
63
64
    public function testUpdateStatusFlags()
65
    {
66
        FluentState::singleton()
67
            ->setLocale('en_US')
68
            ->setIsFrontend(false);
69
70
        /** @var Page|FluentSiteTreeExtension $page */
71
        $page = $this->objFromFixture('Page', 'about');
72
        $flags = $page->getStatusFlags();
0 ignored issues
show
Bug introduced by
The method getStatusFlags() does not exist on TractorCow\Fluent\Extens...FluentSiteTreeExtension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        /** @scrutinizer ignore-call */ 
73
        $flags = $page->getStatusFlags();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
74
        $this->assertTrue(array_key_exists('fluentfiltered', $flags));
75
76
        if (!array_key_exists('fluentfiltered', $flags)) {
77
            return;
78
        }
79
80
        $this->assertEquals('Filtered', $flags['fluentfiltered']['text']);
81
    }
82
}
83