|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TractorCow\Fluent\Tests\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Page; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\Control\Controller; |
|
8
|
|
|
use SilverStripe\Control\Director; |
|
9
|
|
|
use SilverStripe\Core\Config\Config; |
|
10
|
|
|
use SilverStripe\Dev\FunctionalTest; |
|
11
|
|
|
use TractorCow\Fluent\Extension\FluentDirectorExtension; |
|
12
|
|
|
use TractorCow\Fluent\Extension\FluentFilteredExtension; |
|
13
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; |
|
14
|
|
|
use TractorCow\Fluent\Model\Locale; |
|
15
|
|
|
use TractorCow\Fluent\State\FluentState; |
|
16
|
|
|
use TractorCow\Fluent\Tests\Extension\FluentDirectorExtensionTest\TestController; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class FluentDirectorExtensionTest |
|
20
|
|
|
* |
|
21
|
|
|
* @package TractorCow\Fluent\Tests\Extension |
|
22
|
|
|
*/ |
|
23
|
|
|
class FluentDirectorExtensionTest extends FunctionalTest |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected static $fixture_file = 'FluentDirectorExtensionTest.yml'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
protected static $required_extensions = [ |
|
34
|
|
|
SiteTree::class => [ |
|
35
|
|
|
FluentSiteTreeExtension::class, |
|
36
|
|
|
FluentFilteredExtension::class, |
|
37
|
|
|
], |
|
38
|
|
|
Director::class => [ |
|
39
|
|
|
FluentDirectorExtension::class, |
|
40
|
|
|
], |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
public function setUp() // phpcs:ignore SlevomatCodingStandard.TypeHints |
|
44
|
|
|
{ |
|
45
|
|
|
parent::setUp(); |
|
46
|
|
|
|
|
47
|
|
|
$this->logInWithPermission('ADMIN'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testVisitUrlByLocaleWithMultiByteCharacter() |
|
51
|
|
|
{ |
|
52
|
|
|
$locale = 'en_NZ'; |
|
53
|
|
|
FluentState::singleton()->withState(function (FluentState $state) use ($locale) { |
|
54
|
|
|
$state->setLocale($locale); |
|
55
|
|
|
|
|
56
|
|
|
$expectedTitle = sprintf('Page1 (%s)', $locale); |
|
57
|
|
|
|
|
58
|
|
|
/** @var Page|FluentSiteTreeExtension $page */ |
|
59
|
|
|
$page = Page::get()->filter(['Title' => $expectedTitle])->first(); |
|
60
|
|
|
$this->assertNotEmpty($page); |
|
61
|
|
|
$page->publishRecursive(); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$this->get($page->AbsoluteLink()); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$this->assertContains(sprintf('<title>%s', $expectedTitle), $this->content()); |
|
66
|
|
|
}); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testLocalizedControllerRouting() |
|
70
|
|
|
{ |
|
71
|
|
|
$locale = 'en_NZ'; |
|
72
|
|
|
FluentState::singleton()->withState(function (FluentState $state) use ($locale) { |
|
73
|
|
|
$state->setLocale($locale); |
|
74
|
|
|
|
|
75
|
|
|
$expectedTitle = sprintf('Page1 (%s)', $locale); |
|
76
|
|
|
|
|
77
|
|
|
/** @var Page|FluentSiteTreeExtension $page */ |
|
78
|
|
|
$page = Page::get()->filter(['Title' => $expectedTitle])->first(); |
|
79
|
|
|
$this->assertNotEmpty($page); |
|
80
|
|
|
$page->publishRecursive(); |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$this->get(Director::absoluteURL('nouvelle-z%C3%A9lande/TestController')); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertContains('Test Controller! en_NZ', $this->content()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function setUpRoutes() |
|
90
|
|
|
{ |
|
91
|
|
|
parent::setUpRoutes(); |
|
92
|
|
|
|
|
93
|
|
|
// Add controller-name auto-routing |
|
94
|
|
|
$rules = Director::config()->rules; |
|
95
|
|
|
|
|
96
|
|
|
// Modify the rule for our test controller to include the locale parameter |
|
97
|
|
|
$i = array_search('admin', array_keys($rules)); |
|
98
|
|
|
if ($i !== false) { |
|
99
|
|
|
$rule = [ |
|
100
|
|
|
'nouvelle-z%C3%A9lande/TestController//$Action/$ID/$OtherID' => [ |
|
101
|
|
|
'Controller' => TestController::class, |
|
102
|
|
|
'l' => 'en_NZ' |
|
103
|
|
|
] |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
$rules = array_slice($rules, 0, $i, true) + $rule + array_slice($rules, $i, null, true); |
|
|
|
|
|
|
107
|
|
|
} else { |
|
108
|
|
|
throw new \Exception('Could not find "admin" url rule'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// Add controller-name auto-routing |
|
112
|
|
|
Director::config()->set('rules', $rules); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths