|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Nexendrie\Translation\Bridges\NetteApplication; |
|
5
|
|
|
|
|
6
|
|
|
use Tester\Assert; |
|
7
|
|
|
use Nette\Application\Request; |
|
8
|
|
|
use Nette\Application\Application; |
|
9
|
|
|
|
|
10
|
|
|
require __DIR__ . "/../../../../bootstrap.php"; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author Jakub Konečný |
|
14
|
|
|
* @testCase |
|
15
|
|
|
*/ |
|
16
|
|
|
final class ParamLocaleResolverTest extends \Tester\TestCase { |
|
17
|
|
|
use \Testbench\TCompiledContainer; |
|
18
|
|
|
|
|
19
|
|
|
protected ParamLocaleResolver $resolver; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp(): void { |
|
22
|
|
|
$config = [ |
|
23
|
|
|
"translation" => [ |
|
24
|
|
|
"localeResolver" => "param" |
|
25
|
|
|
] |
|
26
|
|
|
]; |
|
27
|
|
|
$this->refreshContainer($config); |
|
28
|
|
|
$this->resolver = $this->getService(ParamLocaleResolver::class); // @phpstan-ignore assign.propertyType |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testResolve(): void { |
|
32
|
|
|
$parameters = [ |
|
33
|
|
|
"callback" => function() { |
|
34
|
|
|
return ""; |
|
35
|
|
|
} |
|
36
|
|
|
]; |
|
37
|
|
|
Assert::null($this->resolver->resolve()); |
|
38
|
|
|
/** @var Application $application */ |
|
39
|
|
|
$application = $this->getService(Application::class); |
|
40
|
|
|
$request = new Request("Micro", Request::FORWARD, $parameters); |
|
41
|
|
|
Assert::null($this->resolver->resolve()); |
|
42
|
|
|
$request->method = "GET"; |
|
43
|
|
|
$application->processRequest($request); |
|
44
|
|
|
$parameters["locale"] = "en"; |
|
45
|
|
|
$request->parameters = $parameters; |
|
46
|
|
|
$application->processRequest($request); |
|
47
|
|
|
Assert::same("en", $this->resolver->resolve()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testCustomParamName(): void { |
|
51
|
|
|
$this->resolver->param = "language"; |
|
52
|
|
|
$parameters = [ |
|
53
|
|
|
"callback" => function() { |
|
54
|
|
|
return ""; |
|
55
|
|
|
}, "language" => "en", |
|
56
|
|
|
]; |
|
57
|
|
|
/** @var Application $application */ |
|
58
|
|
|
$application = $this->getService(Application::class); |
|
59
|
|
|
$request = new Request("Micro", "GET", $parameters); |
|
60
|
|
|
$application->processRequest($request); |
|
61
|
|
|
Assert::same("en", $this->resolver->resolve()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$test = new ParamLocaleResolverTest(); |
|
66
|
|
|
$test->run(); |
|
67
|
|
|
?> |