Passed
Pull Request — master (#300)
by
unknown
01:41
created

testLocalisedFieldFieldIncludeInactive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace TractorCow\Fluent\Tests\Extension;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Core\Config\Config;
8
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
9
use TractorCow\Fluent\State\FluentState;
10
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject;
11
12
class FluentExtensionTest extends SapphireTest
13
{
14
    protected static $required_extensions = [
15
        SiteTree::class => [
16
            FluentSiteTreeExtension::class,
17
        ],
18
    ];
19
20
    public function testFluentLocaleAndFrontendAreAddedToDataQuery()
21
    {
22
        FluentState::singleton()
23
            ->setLocale('test')
24
            ->setIsFrontend(true);
25
26
        $query = SiteTree::get()->dataQuery();
27
        $this->assertSame('test', $query->getQueryParam('Fluent.Locale'));
28
        $this->assertTrue($query->getQueryParam('Fluent.IsFrontend'));
0 ignored issues
show
Bug introduced by
$query->getQueryParam('Fluent.IsFrontend') of type string is incompatible with the type boolean expected by parameter $condition of PHPUnit_Framework_Assert::assertTrue(). ( Ignorable by Annotation )

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

28
        $this->assertTrue(/** @scrutinizer ignore-type */ $query->getQueryParam('Fluent.IsFrontend'));
Loading history...
29
    }
30
31
    public function testGetLocalisedTable()
32
    {
33
        /** @var SiteTree|FluentSiteTreeExtension $page */
34
        $page = new SiteTree;
35
        $this->assertSame('SiteTree_Localised', $page->getLocalisedTable('SiteTree'));
36
        $this->assertSame('SiteTree_Localised_FR', $page->getLocalisedTable('SiteTree', 'FR'));
37
    }
38
39
    public function testGetLinkingMode()
40
    {
41
        // Does not have a canViewInLocale method, locale is not current
42
        $stub = new FluentStubObject();
43
        $this->assertSame('link', $stub->getLinkingMode('foo'));
0 ignored issues
show
Bug introduced by
The method getLinkingMode() does not exist on TractorCow\Fluent\Tests\...n\Stub\FluentStubObject. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

43
        $this->assertSame('link', $stub->/** @scrutinizer ignore-call */ getLinkingMode('foo'));
Loading history...
44
45
        // Does not have a canViewInLocale method, locale is current
46
        FluentState::singleton()->setLocale('foo');
47
        $this->assertSame('current', $stub->getLinkingMode('foo'));
48
    }
49
50 View Code Duplication
    public function testLocalisedFieldFieldIncludeActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        Config::modify()->set(SiteTree::class, 'field_include', ['TestField']);
53
54
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType');
55
        $this->assertEquals(true, $isLocalised);
56
    }
57
58
    public function testLocalisedFieldFieldIncludeInactive()
59
    {
60
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType');
61
        $this->assertEquals(false, $isLocalised);
62
    }
63
64 View Code Duplication
    public function testLocalisedFieldFieldExcludeActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        Config::modify()->set(SiteTree::class, 'field_exclude', ['TestField']);
67
68
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'Text');
69
        $this->assertEquals(false, $isLocalised);
70
    }
71
72
    public function testLocalisedFieldFieldExcludeInactive()
73
    {
74
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'Text');
75
        $this->assertEquals(true, $isLocalised);
76
    }
77
78 View Code Duplication
    public function testLocalisedFieldDataIncludeActive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        Config::modify()->set(SiteTree::class, 'data_include', ['UnsupportedType']);
81
82
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType');
83
        $this->assertEquals(true, $isLocalised);
84
    }
85
86
    public function testLocalisedFieldDataIncludeInactive()
87
    {
88
        $isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType');
89
        $this->assertEquals(false, $isLocalised);
90
    }
91
}
92