|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\Core\Translation; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
|
18
|
|
|
use Sylius\Component\Locale\Context\LocaleNotFoundException; |
|
19
|
|
|
use Sylius\Component\Resource\Model\TranslatableInterface; |
|
20
|
|
|
use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface; |
|
21
|
|
|
use Sylius\Component\Resource\Translation\TranslatableEntityLocaleAssignerInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class TranslatableEntityLocaleAssignerSpec extends ObjectBehavior |
|
24
|
|
|
{ |
|
25
|
|
|
function let(LocaleContextInterface $localeContext, TranslationLocaleProviderInterface $translationLocaleProvider): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->beConstructedWith($localeContext, $translationLocaleProvider); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_implements_traslatable_entity_locale_assigner_interface(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->shouldImplement(TranslatableEntityLocaleAssignerInterface::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_should_assign_current_and_default_locale_to_given_translatable_entity( |
|
36
|
|
|
LocaleContextInterface $localeContext, |
|
37
|
|
|
TranslationLocaleProviderInterface $translationLocaleProvider, |
|
38
|
|
|
TranslatableInterface $translatableEntity |
|
39
|
|
|
): void { |
|
40
|
|
|
$localeContext->getLocaleCode()->willReturn('de_DE'); |
|
41
|
|
|
$translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US'); |
|
42
|
|
|
|
|
43
|
|
|
$translatableEntity->setCurrentLocale('de_DE')->shouldBeCalled(); |
|
44
|
|
|
$translatableEntity->setFallbackLocale('en_US')->shouldBeCalled(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assignLocale($translatableEntity); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_should_use_default_locale_as_current_if_could_not_resolve_the_current_locale( |
|
50
|
|
|
LocaleContextInterface $localeContext, |
|
51
|
|
|
TranslationLocaleProviderInterface $translationLocaleProvider, |
|
52
|
|
|
TranslatableInterface $translatableEntity |
|
53
|
|
|
): void { |
|
54
|
|
|
$localeContext->getLocaleCode()->willThrow(new LocaleNotFoundException()); |
|
55
|
|
|
$translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US'); |
|
56
|
|
|
|
|
57
|
|
|
$translatableEntity->setCurrentLocale('en_US')->shouldBeCalled(); |
|
58
|
|
|
$translatableEntity->setFallbackLocale('en_US')->shouldBeCalled(); |
|
59
|
|
|
|
|
60
|
|
|
$this->assignLocale($translatableEntity); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|