|
1 |
| -<?php namespace spec\KiaKing\LaravelLocale; |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\KiaKing\LaravelLocale; |
2 | 4 |
|
3 | 5 | use PhpSpec\ObjectBehavior;
|
4 | 6 | use Prophecy\Argument;
|
5 | 7 | use Illuminate\Contracts\Config\Repository as Config;
|
6 | 8 | use Illuminate\Http\Request;
|
7 | 9 | use Illuminate\Contracts\Routing\UrlGenerator;
|
8 | 10 |
|
9 |
| -class LocaleUrlGeneratorSpec extends ObjectBehavior { |
10 |
| - |
11 |
| - function let(Config $config, Request $request, UrlGenerator $url) |
12 |
| - { |
13 |
| - $this->beConstructedWith($config, $request, $url); |
14 |
| - |
15 |
| - $config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']); |
16 |
| - $config->get('app.fallback_locale')->willReturn('ja'); |
17 |
| - } |
18 |
| - |
19 |
| - function it_is_initializable() |
20 |
| - { |
21 |
| - $this->shouldHaveType('KiaKing\LaravelLocale\LocaleUrlGenerator'); |
22 |
| - } |
23 |
| - |
24 |
| - function it_passes_non_prefixed_url_to_url_when_locale_is_default(Config $config, UrlGenerator $url) |
25 |
| - { |
26 |
| - $config->get('app.locale')->willReturn('ja'); |
27 |
| - $url->to('home', [], null)->shouldBeCalled(); |
28 |
| - |
29 |
| - $this->url('home'); |
30 |
| - } |
31 |
| - |
32 |
| - function it_passes_prefixed_url_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url) |
33 |
| - { |
34 |
| - $config->get('app.locale')->willReturn('en'); |
35 |
| - $url->to('en/home', [], null)->shouldBeCalled(); |
36 |
| - |
37 |
| - $this->url('home'); |
38 |
| - } |
39 |
| - |
40 |
| - function it_passes_non_prefixed_named_route_to_url_when_locale_is_default(Config $config, UrlGenerator $url) |
41 |
| - { |
42 |
| - $config->get('app.locale')->willReturn('ja'); |
43 |
| - $url->route('home', [], true)->shouldBeCalled(); |
44 |
| - |
45 |
| - $this->route('home'); |
46 |
| - } |
47 |
| - |
48 |
| - function it_passes_prefixed_named_route_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url) |
49 |
| - { |
50 |
| - $config->get('app.locale')->willReturn('en'); |
51 |
| - $url->route('en.home', [], true)->shouldBeCalled(); |
52 |
| - |
53 |
| - $this->route('home'); |
54 |
| - } |
55 |
| - |
56 |
| - function it_can_change_url_to_same_locale(Config $config, Request $request) |
57 |
| - { |
58 |
| - $config->get('app.locale')->willReturn('ja'); |
59 |
| - $request->fullUrl()->willReturn('http://example.com/?query=value'); |
60 |
| - |
61 |
| - $this->change('ja')->shouldReturn('http://example.com/?query=value'); |
62 |
| - } |
63 |
| - |
64 |
| - function it_can_change_url_to_other_locale_from_default(Config $config, Request $request) |
65 |
| - { |
66 |
| - $config->get('app.locale')->willReturn('ja'); |
67 |
| - $request->root()->willReturn('http://example.com'); |
68 |
| - $request->fullUrl()->willReturn('http://example.com/?query=value'); |
69 |
| - |
70 |
| - $this->change('en')->shouldReturn('http://example.com/en/?query=value'); |
71 |
| - } |
72 |
| - |
73 |
| - function it_can_change_url_to_default_locale_from_non_default_locale(Config $config, Request $request) |
74 |
| - { |
75 |
| - $config->get('app.locale')->willReturn('en'); |
76 |
| - $request->fullUrl()->willReturn('http://example.com/en/?query=value'); |
77 |
| - |
78 |
| - $this->change('ja')->shouldReturn('http://example.com/?query=value'); |
79 |
| - } |
80 |
| - |
81 |
| - function it_can_change_url_to_other_locale_from_non_default_locale(Config $config, Request $request) |
82 |
| - { |
83 |
| - $config->get('app.locale')->willReturn('en'); |
84 |
| - $request->fullUrl()->willReturn('http://example.com/en/?query=value'); |
85 |
| - |
86 |
| - $this->change('fr')->shouldReturn('http://example.com/fr/?query=value'); |
87 |
| - } |
88 |
| - |
| 11 | +class LocaleUrlGeneratorSpec extends ObjectBehavior |
| 12 | +{ |
| 13 | + function let(Config $config, Request $request, UrlGenerator $url) |
| 14 | + { |
| 15 | + $this->beConstructedWith($config, $request, $url); |
| 16 | + |
| 17 | + $config->get('locale.available_locales')->willReturn(['ja', 'en', 'fr']); |
| 18 | + $config->get('app.fallback_locale')->willReturn('ja'); |
| 19 | + } |
| 20 | + |
| 21 | + function it_is_initializable() |
| 22 | + { |
| 23 | + $this->shouldHaveType('KiaKing\LaravelLocale\LocaleUrlGenerator'); |
| 24 | + } |
| 25 | + |
| 26 | + function it_passes_non_prefixed_url_to_url_when_locale_is_default(Config $config, UrlGenerator $url) |
| 27 | + { |
| 28 | + $config->get('app.locale')->willReturn('ja'); |
| 29 | + $url->to('home', [], null)->shouldBeCalled(); |
| 30 | + |
| 31 | + $this->url('home'); |
| 32 | + } |
| 33 | + |
| 34 | + function it_passes_prefixed_url_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url) |
| 35 | + { |
| 36 | + $config->get('app.locale')->willReturn('en'); |
| 37 | + $url->to('en/home', [], null)->shouldBeCalled(); |
| 38 | + |
| 39 | + $this->url('home'); |
| 40 | + } |
| 41 | + |
| 42 | + function it_passes_non_prefixed_named_route_to_url_when_locale_is_default(Config $config, UrlGenerator $url) |
| 43 | + { |
| 44 | + $config->get('app.locale')->willReturn('ja'); |
| 45 | + $url->route('home', [], true)->shouldBeCalled(); |
| 46 | + |
| 47 | + $this->route('home'); |
| 48 | + } |
| 49 | + |
| 50 | + function it_passes_prefixed_named_route_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url) |
| 51 | + { |
| 52 | + $config->get('app.locale')->willReturn('en'); |
| 53 | + $url->route('en.home', [], true)->shouldBeCalled(); |
| 54 | + |
| 55 | + $this->route('home'); |
| 56 | + } |
| 57 | + |
| 58 | + function it_can_change_url_to_same_locale(Config $config, Request $request) |
| 59 | + { |
| 60 | + $config->get('app.locale')->willReturn('ja'); |
| 61 | + $request->fullUrl()->willReturn('http://example.com/?query=value'); |
| 62 | + |
| 63 | + $this->change('ja')->shouldReturn('http://example.com/?query=value'); |
| 64 | + } |
| 65 | + |
| 66 | + function it_can_change_url_to_other_locale_from_default(Config $config, Request $request) |
| 67 | + { |
| 68 | + $config->get('app.locale')->willReturn('ja'); |
| 69 | + $request->root()->willReturn('http://example.com'); |
| 70 | + $request->fullUrl()->willReturn('http://example.com/?query=value'); |
| 71 | + |
| 72 | + $this->change('en')->shouldReturn('http://example.com/en/?query=value'); |
| 73 | + } |
| 74 | + |
| 75 | + function it_can_change_url_to_default_locale_from_non_default_locale(Config $config, Request $request) |
| 76 | + { |
| 77 | + $config->get('app.locale')->willReturn('en'); |
| 78 | + $request->fullUrl()->willReturn('http://example.com/en/?query=value'); |
| 79 | + |
| 80 | + $this->change('ja')->shouldReturn('http://example.com/?query=value'); |
| 81 | + } |
| 82 | + |
| 83 | + function it_can_change_url_to_other_locale_from_non_default_locale(Config $config, Request $request) |
| 84 | + { |
| 85 | + $config->get('app.locale')->willReturn('en'); |
| 86 | + $request->fullUrl()->willReturn('http://example.com/en/?query=value'); |
| 87 | + |
| 88 | + $this->change('fr')->shouldReturn('http://example.com/fr/?query=value'); |
| 89 | + } |
89 | 90 | }
|
0 commit comments