Passed
Pull Request — master (#12)
by Robbie
04:58 queued 01:01
created

BasePageTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSelectedLanguage() 0 9 2
A testPdfFilename() 0 7 1
A setUp() 0 7 1
A localeProvider() 0 6 1
A testHomePagePdfLink() 0 4 1
A testPdfLink() 0 4 1
A testPdfLinkDisabled() 0 5 1
A tearDown() 0 4 1
1
<?php
2
3
namespace CWP\CWP\Tests\PageTypes;
4
5
6
7
use Translatable;
0 ignored issues
show
Bug introduced by
The type Translatable 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...
8
use SilverStripe\Core\Config\Config;
9
use CWP\CWP\PageTypes\BasePage;
10
use SilverStripe\Dev\SapphireTest;
11
12
13
class BasePageTest extends SapphireTest
14
{
15
    public static $fixture_file = 'BasePageTest.yml';
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
21
        Config::nest();
22
        Config::inst()->update(BasePage::class, 'pdf_export', true);
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

22
        Config::inst()->/** @scrutinizer ignore-call */ update(BasePage::class, 'pdf_export', true);
Loading history...
23
        Config::inst()->update(BasePage::class, 'generated_pdf_path', 'assets/_generated_pdfs');
24
    }
25
26
    public function testPdfFilename()
27
    {
28
        $page = $this->objFromFixture(BasePage::class, 'test-page-one');
29
        $this->assertContains(
30
            'assets/_generated_pdfs/test-page-one-1.pdf',
31
            $page->getPdfFilename(),
32
            'Generated filename for PDF'
33
        );
34
    }
35
36
    public function testPdfLink()
37
    {
38
        $page = $this->objFromFixture(BasePage::class, 'test-page-one');
39
        $this->assertContains('test-page-one/downloadpdf', $page->PdfLink(), 'Link to download PDF');
40
    }
41
42
    public function testHomePagePdfLink()
43
    {
44
        $page = $this->objFromFixture(BasePage::class, 'home-page');
45
        $this->assertContains('home/downloadpdf', $page->PdfLink(), 'Link to download PDF');
46
    }
47
48
    public function testPdfLinkDisabled()
49
    {
50
        Config::inst()->update(BasePage::class, 'pdf_export', false);
51
        $page = $this->objFromFixture(BasePage::class, 'test-page-one');
52
        $this->assertFalse($page->PdfLink(), 'No PDF link as the functionality is disabled');
53
    }
54
55
    /**
56
     * Test that the native language name can be returned for the current locale
57
     *
58
     * @see i18n
59
     * @param string $locale
60
     * @param string $expected
61
     * @dataProvider localeProvider
62
     */
63
    public function testGetSelectedLanguage($locale, $expected)
64
    {
65
        if (!class_exists('Translatable')) {
66
            $this->markTestSkipped('Language tests require Translatable module.');
67
        }
68
69
        Translatable::set_current_locale($locale);
70
        $page = $this->objFromFixture(BasePage::class, 'test-page-one');
71
        $this->assertSame($expected, $page->getSelectedLanguage());
72
    }
73
74
    /**
75
     * @return array[]
76
     */
77
    public function localeProvider()
78
    {
79
        return array(
80
            array('en_NZ', 'English'),
81
            array('af_ZA', 'Afrikaans'),
82
            array('es_ES', 'espa&ntilde;ol')
83
        );
84
    }
85
86
    public function tearDown()
87
    {
88
        Config::unnest();
89
        parent::tearDown();
90
    }
91
}
92