TranslatableSiteConfigTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @package translatable
4
 */
5
class TranslatableSiteConfigTest extends SapphireTest
6
{
7
    protected static $fixture_file = 'translatable/tests/unit/TranslatableSiteConfigTest.yml';
8
    
9
    protected $requiredExtensions = array(
10
        'SiteTree' => array('Translatable'),
11
        'SiteConfig' => array('Translatable'),
12
    );
13
    
14
    protected $illegalExtensions = array(
15
        'SiteTree' => array('SiteTreeSubsites')
16
    );
17
    
18
    private $origLocale;
19
20
    public function setUp()
21
    {
22
        parent::setUp();
23
                
24
        $this->origLocale = Translatable::default_locale();
25
        Translatable::set_default_locale("en_US");
26
    }
27
    
28
    public function tearDown()
29
    {
30
        Translatable::set_default_locale($this->origLocale);
31
        Translatable::set_current_locale($this->origLocale);
32
33
        parent::tearDown();
34
    }
35
    
36
    public function testCurrentCreatesDefaultForLocale()
37
    {
38
        Translatable::set_current_locale(Translatable::default_locale());
39
        $configEn = SiteConfig::current_site_config();
40
        Translatable::set_current_locale('fr_FR');
41
        $configFr = SiteConfig::current_site_config();
42
        Translatable::set_current_locale(Translatable::default_locale());
43
        
44
        $this->assertInstanceOf('SiteConfig', $configFr);
45
        $this->assertEquals($configFr->Locale, 'fr_FR');
46
        $this->assertEquals($configFr->Title, $configEn->Title, 'Copies title from existing config');
47
        $this->assertEquals(
48
            $configFr->getTranslationGroup(),
49
            $configEn->getTranslationGroup(),
50
            'Created in the same translation group'
51
        );
52
    }
53
    
54
    public function testCanEditTranslatedRootPages()
55
    {
56
        $configEn = $this->objFromFixture('SiteConfig', 'en_US');
0 ignored issues
show
Unused Code introduced by
$configEn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
        $configDe = $this->objFromFixture('SiteConfig', 'de_DE');
0 ignored issues
show
Unused Code introduced by
$configDe is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
        
59
        $pageEn = $this->objFromFixture('Page', 'root_en');
60
        $pageDe = $pageEn->createTranslation('de_DE');
0 ignored issues
show
Unused Code introduced by
$pageDe is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
61
        
62
        $translatorDe = $this->objFromFixture('Member', 'translator_de');
63
        $translatorEn = $this->objFromFixture('Member', 'translator_en');
64
        
65
        $this->assertFalse($pageEn->canEdit($translatorDe));
66
        $this->assertTrue($pageEn->canEdit($translatorEn));
67
    }
68
}
69