|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TractorCow\Fluent\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use SilverStripe\Core\Config\Config; |
|
8
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; |
|
9
|
|
|
use TractorCow\Fluent\State\FluentState; |
|
10
|
|
|
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject; |
|
11
|
|
|
|
|
12
|
|
|
class FluentExtensionTest extends SapphireTest |
|
13
|
|
|
{ |
|
14
|
|
|
protected static $required_extensions = [ |
|
15
|
|
|
SiteTree::class => [ |
|
16
|
|
|
FluentSiteTreeExtension::class, |
|
17
|
|
|
], |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
public function testFluentLocaleAndFrontendAreAddedToDataQuery() |
|
21
|
|
|
{ |
|
22
|
|
|
FluentState::singleton() |
|
23
|
|
|
->setLocale('test') |
|
24
|
|
|
->setIsFrontend(true); |
|
25
|
|
|
|
|
26
|
|
|
$query = SiteTree::get()->dataQuery(); |
|
27
|
|
|
$this->assertSame('test', $query->getQueryParam('Fluent.Locale')); |
|
28
|
|
|
$this->assertTrue($query->getQueryParam('Fluent.IsFrontend')); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetLocalisedTable() |
|
32
|
|
|
{ |
|
33
|
|
|
/** @var SiteTree|FluentSiteTreeExtension $page */ |
|
34
|
|
|
$page = new SiteTree; |
|
35
|
|
|
$this->assertSame('SiteTree_Localised', $page->getLocalisedTable('SiteTree')); |
|
36
|
|
|
$this->assertSame('SiteTree_Localised_FR', $page->getLocalisedTable('SiteTree', 'FR')); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGetLinkingMode() |
|
40
|
|
|
{ |
|
41
|
|
|
// Does not have a canViewInLocale method, locale is not current |
|
42
|
|
|
$stub = new FluentStubObject(); |
|
43
|
|
|
$this->assertSame('link', $stub->getLinkingMode('foo')); |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
// Does not have a canViewInLocale method, locale is current |
|
46
|
|
|
FluentState::singleton()->setLocale('foo'); |
|
47
|
|
|
$this->assertSame('current', $stub->getLinkingMode('foo')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
View Code Duplication |
public function testLocalisedFieldFieldIncludeActive() |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
Config::modify()->set(SiteTree::class, 'field_include', ['TestField']); |
|
53
|
|
|
|
|
54
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType'); |
|
55
|
|
|
$this->assertEquals(true, $isLocalised); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testLocalisedFieldFieldIncludeInactive() |
|
59
|
|
|
{ |
|
60
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType'); |
|
61
|
|
|
$this->assertEquals(false, $isLocalised); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
View Code Duplication |
public function testLocalisedFieldFieldExcludeActive() |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
Config::modify()->set(SiteTree::class, 'field_exclude', ['TestField']); |
|
67
|
|
|
|
|
68
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'Text'); |
|
69
|
|
|
$this->assertEquals(false, $isLocalised); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testLocalisedFieldFieldExcludeInactive() |
|
73
|
|
|
{ |
|
74
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'Text'); |
|
75
|
|
|
$this->assertEquals(true, $isLocalised); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
public function testLocalisedFieldDataIncludeActive() |
|
|
|
|
|
|
79
|
|
|
{ |
|
80
|
|
|
Config::modify()->set(SiteTree::class, 'data_include', ['UnsupportedType']); |
|
81
|
|
|
|
|
82
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType'); |
|
83
|
|
|
$this->assertEquals(true, $isLocalised); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testLocalisedFieldDataIncludeInactive() |
|
87
|
|
|
{ |
|
88
|
|
|
$isLocalised = SiteTree::singleton()->isFieldLocalised('TestField', 'UnsupportedType'); |
|
89
|
|
|
$this->assertEquals(false, $isLocalised); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|