|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TractorCow\Fluent\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; |
|
8
|
|
|
use TractorCow\Fluent\State\FluentState; |
|
9
|
|
|
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubObject; |
|
10
|
|
|
|
|
11
|
|
|
class FluentExtensionTest extends SapphireTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected static $required_extensions = [ |
|
14
|
|
|
SiteTree::class => [ |
|
15
|
|
|
FluentSiteTreeExtension::class, |
|
16
|
|
|
], |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
public function testFluentLocaleAndFrontendAreAddedToDataQuery() |
|
20
|
|
|
{ |
|
21
|
|
|
FluentState::singleton() |
|
22
|
|
|
->setLocale('test') |
|
23
|
|
|
->setIsFrontend(true); |
|
24
|
|
|
|
|
25
|
|
|
$query = SiteTree::get()->dataQuery(); |
|
26
|
|
|
$this->assertSame('test', $query->getQueryParam('Fluent.Locale')); |
|
27
|
|
|
$this->assertTrue($query->getQueryParam('Fluent.IsFrontend')); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGetLocalisedTable() |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var SiteTree|FluentSiteTreeExtension $page */ |
|
33
|
|
|
$page = new SiteTree; |
|
34
|
|
|
$this->assertSame('SiteTree_Localised', $page->getLocalisedTable('SiteTree')); |
|
35
|
|
|
$this->assertSame('SiteTree_Localised_FR', $page->getLocalisedTable('SiteTree', 'FR')); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetLinkingMode() |
|
39
|
|
|
{ |
|
40
|
|
|
// Does not have a canViewInLocale method, locale is not current |
|
41
|
|
|
$stub = new FluentStubObject(); |
|
42
|
|
|
$this->assertSame('link', $stub->getLinkingMode('foo')); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
// Does not have a canViewInLocale method, locale is current |
|
45
|
|
|
FluentState::singleton()->setLocale('foo'); |
|
46
|
|
|
$this->assertSame('current', $stub->getLinkingMode('foo')); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|