Completed
Push — master ( 84107b...f0cb22 )
by Robbie
11s
created

FluentSiteTreeExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetLocaleInformation() 0 16 1
A testGetLocales() 0 10 1
A testGetLinkingMode() 0 8 1
A setUp() 0 5 1
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\Control\Director;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Dev\SapphireTest;
10
use SilverStripe\ORM\ArrayList;
11
use SilverStripe\View\ArrayData;
12
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
13
use TractorCow\Fluent\Model\Locale;
14
use TractorCow\Fluent\State\FluentState;
15
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject;
16
17
class FluentSiteTreeExtensionTest extends SapphireTest
18
{
19
    protected static $fixture_file = 'FluentSiteTreeExtensionTest.yml';
20
21
    protected static $required_extensions = [
22
        SiteTree::class => [FluentSiteTreeExtension::class],
23
        FluentStubObject::class => [FluentSiteTreeExtension::class],
24
    ];
25
26
    protected function setUp()
27
    {
28
        parent::setUp();
29
30
        Config::inst()->update(Director::class, 'alternate_base_url', 'http://mocked');
0 ignored issues
show
Bug introduced by
The method update() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. It seems like you code against a sub-type of SilverStripe\Config\Coll...nfigCollectionInterface such as SilverStripe\Config\Coll...\MemoryConfigCollection. ( Ignorable by Annotation )

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

30
        Config::inst()->/** @scrutinizer ignore-call */ update(Director::class, 'alternate_base_url', 'http://mocked');
Loading history...
31
    }
32
33
    public function testGetLocaleInformation()
34
    {
35
        $result = $this->objFromFixture(Page::class, 'nz-page')->LocaleInformation('en_NZ');
36
37
        $this->assertInstanceOf(ArrayData::class, $result);
38
        $this->assertEquals([
39
            'Locale' => 'en_NZ',
40
            'LocaleRFC1766' => 'en-NZ',
41
            'Title' => 'English (New Zealand)',
42
            'LanguageNative' => 'English',
43
            'Language' => 'en',
44
            'Link' => '/newzealand/a-page/',
45
            'AbsoluteLink' => 'http://mocked/newzealand/a-page/',
46
            'LinkingMode' => 'link',
47
            'URLSegment' => 'newzealand'
48
        ], $result->toMap());
49
    }
50
51
    public function testGetLocales()
52
    {
53
        $result = $this->objFromFixture(Page::class, 'nz-page')->Locales();
54
55
        $this->assertInstanceOf(ArrayList::class, $result);
56
        $this->assertCount(2, $result);
57
        $this->assertDOSEquals([
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Dev\SapphireTest::assertDOSEquals() has been deprecated: 4.0.0:5.0.0 Use assertListEquals() instead ( Ignorable by Annotation )

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

57
        /** @scrutinizer ignore-deprecated */ $this->assertDOSEquals([

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
            ['Locale' => 'en_NZ'],
59
            ['Locale' => 'de_DE'],
60
        ], $result);
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type array; however, parameter $dataObjectSet of SilverStripe\Dev\SapphireTest::assertDOSEquals() does only seem to accept SilverStripe\ORM\SS_List, maybe add an additional type check? ( Ignorable by Annotation )

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

60
        ], /** @scrutinizer ignore-type */ $result);
Loading history...
61
    }
62
63
    public function testGetLinkingMode()
64
    {
65
        // Does not have a canViewInLocale method, locale is not current
66
        $this->assertSame('link', (new FluentStubObject)->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

66
        $this->assertSame('link', (new FluentStubObject)->/** @scrutinizer ignore-call */ getLinkingMode('foo'));
Loading history...
67
68
        // Does not have a canViewInLocale method, locale is current
69
        FluentState::singleton()->setLocale('foo');
70
        $this->assertSame('current', (new FluentStubObject)->getLinkingMode('foo'));
71
    }
72
}
73