These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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'); |
||
57 | $configDe = $this->objFromFixture('SiteConfig', 'de_DE'); |
||
58 | |||
59 | $pageEn = $this->objFromFixture('Page', 'root_en'); |
||
60 | $pageDe = $pageEn->createTranslation('de_DE'); |
||
61 | |||
62 | $translatorDe = $this->objFromFixture('Member', 'translator_de'); |
||
63 | $translatorEn = $this->objFromFixture('Member', 'translator_en'); |
||
64 | |||
65 | $this->assertFalse($pageEn->canEdit($translatorDe)); |
||
0 ignored issues
–
show
|
|||
66 | $this->assertTrue($pageEn->canEdit($translatorEn)); |
||
0 ignored issues
–
show
It seems like
$translatorEn defined by $this->objFromFixture('Member', 'translator_en') on line 63 can also be of type object<DataObject> ; however, DataObject::canEdit() does only seem to accept object<Member>|null , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
67 | } |
||
68 | } |
||
69 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.