Passed
Push — master ( f0cb22...699e9b )
by Robbie
01:46
created

FluentExtensionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFluentLocaleAndFrontendAreAddedToDataQuery() 0 9 1
A testGetLocalisedTable() 0 6 1
A testGetLinkingMode() 0 9 1
1
<?php
2
3
namespace TractorCow\Fluent\Tests\Extension;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\SapphireTest;
7
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
8
use TractorCow\Fluent\State\FluentState;
9
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject;
10
11
class FluentExtensionTest extends SapphireTest
12
{
13
    protected static $required_extensions = [
14
        SiteTree::class => [
15
            FluentSiteTreeExtension::class,
16
        ],
17
    ];
18
19
    public function testFluentLocaleAndFrontendAreAddedToDataQuery()
20
    {
21
        FluentState::singleton()
22
            ->setLocale('test')
23
            ->setIsFrontend(true);
24
25
        $query = SiteTree::get()->dataQuery();
26
        $this->assertSame('test', $query->getQueryParam('Fluent.Locale'));
27
        $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

27
        $this->assertTrue(/** @scrutinizer ignore-type */ $query->getQueryParam('Fluent.IsFrontend'));
Loading history...
28
    }
29
30
    public function testGetLocalisedTable()
31
    {
32
        /** @var SiteTree|FluentSiteTreeExtension $page */
33
        $page = new SiteTree;
34
        $this->assertSame('SiteTree_Localised', $page->getLocalisedTable('SiteTree'));
35
        $this->assertSame('SiteTree_Localised_FR', $page->getLocalisedTable('SiteTree', 'FR'));
36
    }
37
38
    public function testGetLinkingMode()
39
    {
40
        // Does not have a canViewInLocale method, locale is not current
41
        $stub = new FluentStubObject();
42
        $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

42
        $this->assertSame('link', $stub->/** @scrutinizer ignore-call */ getLinkingMode('foo'));
Loading history...
43
44
        // Does not have a canViewInLocale method, locale is current
45
        FluentState::singleton()->setLocale('foo');
46
        $this->assertSame('current', $stub->getLinkingMode('foo'));
47
    }
48
}
49