|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Translatable\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Page; |
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\Security\Member; |
|
9
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
10
|
|
|
use SilverStripe\Translatable\Model\Translatable; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @package translatable |
|
14
|
|
|
*/ |
|
15
|
|
|
class TranslatableSiteConfigTest extends SapphireTest |
|
16
|
|
|
{ |
|
17
|
|
|
protected static $fixture_file = 'TranslatableSiteConfigTest.yml'; |
|
18
|
|
|
|
|
19
|
|
|
protected static $required_extensions = [ |
|
20
|
|
|
SiteTree::class => [Translatable::class], |
|
21
|
|
|
SiteConfig::class => [Translatable::class], |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
protected static $illegal_extensions = [ |
|
25
|
|
|
// @todo: Update namespace to match subsites |
|
26
|
|
|
SiteTree::class => array('SiteTreeSubsites') |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
private $origLocale; |
|
30
|
|
|
|
|
31
|
|
|
protected function setUp() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::setUp(); |
|
34
|
|
|
|
|
35
|
|
|
$this->origLocale = Translatable::default_locale(); |
|
36
|
|
|
Translatable::set_default_locale('en_US'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
protected function tearDown() |
|
40
|
|
|
{ |
|
41
|
|
|
Translatable::set_default_locale($this->origLocale); |
|
42
|
|
|
Translatable::set_current_locale($this->origLocale); |
|
43
|
|
|
|
|
44
|
|
|
parent::tearDown(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testCurrentCreatesDefaultForLocale() |
|
48
|
|
|
{ |
|
49
|
|
|
Translatable::set_current_locale(Translatable::default_locale()); |
|
50
|
|
|
$configEn = SiteConfig::current_site_config(); |
|
51
|
|
|
Translatable::set_current_locale('fr_FR'); |
|
52
|
|
|
$configFr = SiteConfig::current_site_config(); |
|
53
|
|
|
Translatable::set_current_locale(Translatable::default_locale()); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertInstanceOf(SiteConfig::class, $configFr); |
|
56
|
|
|
$this->assertEquals($configFr->Locale, 'fr_FR'); |
|
57
|
|
|
$this->assertEquals($configFr->Title, $configEn->Title, 'Copies title from existing config'); |
|
58
|
|
|
$this->assertEquals( |
|
59
|
|
|
$configFr->getTranslationGroup(), |
|
60
|
|
|
$configEn->getTranslationGroup(), |
|
61
|
|
|
'Created in the same translation group' |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testCanEditTranslatedRootPages() |
|
66
|
|
|
{ |
|
67
|
|
|
$configEn = $this->objFromFixture(SiteConfig::class, 'en_US'); |
|
|
|
|
|
|
68
|
|
|
$configDe = $this->objFromFixture(SiteConfig::class, 'de_DE'); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$pageEn = $this->objFromFixture(Page::class, 'root_en'); |
|
71
|
|
|
$pageDe = $pageEn->createTranslation('de_DE'); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$translatorDe = $this->objFromFixture(Member::class, 'translator_de'); |
|
74
|
|
|
$translatorEn = $this->objFromFixture(Member::class, 'translator_en'); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertFalse($pageEn->canEdit($translatorDe)); |
|
|
|
|
|
|
77
|
|
|
$this->assertTrue($pageEn->canEdit($translatorEn)); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.