From 427315195bdd379a0207fc9b2aaf69a5b5b86c79 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 28 Aug 2018 22:23:59 +0200 Subject: Moved translation/internationalization to Helpers\Translator class --- .../Helpers/TranslationServiceProviderTest.php | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/Unit/Helpers/TranslationServiceProviderTest.php (limited to 'tests/Unit/Helpers/TranslationServiceProviderTest.php') diff --git a/tests/Unit/Helpers/TranslationServiceProviderTest.php b/tests/Unit/Helpers/TranslationServiceProviderTest.php new file mode 100644 index 00000000..c5ba7386 --- /dev/null +++ b/tests/Unit/Helpers/TranslationServiceProviderTest.php @@ -0,0 +1,86 @@ +getApp(['make', 'instance', 'get']); + /** @var Config|MockObject $config */ + $config = $this->createMock(Config::class); + /** @var Session|MockObject $session */ + $session = $this->createMock(Session::class); + /** @var Translator|MockObject $translator */ + $translator = $this->createMock(Translator::class); + + /** @var TranslationServiceProvider|MockObject $serviceProvider */ + $serviceProvider = $this->getMockBuilder(TranslationServiceProvider::class) + ->setConstructorArgs([$app]) + ->setMethods(['initGettext', 'setLocale']) + ->getMock(); + + $serviceProvider->expects($this->once()) + ->method('initGettext'); + + $app->expects($this->exactly(2)) + ->method('get') + ->withConsecutive(['config'], ['session']) + ->willReturnOnConsecutiveCalls($config, $session); + + $defaultLocale = 'fo_OO'; + $locale = 'te_ST.WTF-9'; + $locales = ['fo_OO' => 'Foo', 'fo_OO.BAR' => 'Foo (Bar)', 'te_ST.WTF-9' => 'WTF\'s Testing?']; + $config->expects($this->exactly(2)) + ->method('get') + ->withConsecutive( + ['locales'], + ['default_locale'] + ) + ->willReturnOnConsecutiveCalls( + $locales, + $defaultLocale + ); + + $session->expects($this->once()) + ->method('get') + ->with('locale', $defaultLocale) + ->willReturn($locale); + $session->expects($this->once()) + ->method('set') + ->with('locale', $locale); + + $app->expects($this->once()) + ->method('make') + ->with( + Translator::class, + [ + 'locale' => $locale, + 'locales' => $locales, + 'localeChangeCallback' => [$serviceProvider, 'setLocale'] + ] + ) + ->willReturn($translator); + + $app->expects($this->exactly(2)) + ->method('instance') + ->withConsecutive( + [Translator::class, $translator], + ['translator', $translator] + ); + + $serviceProvider->register(); + } +} + + -- cgit v1.2.3-54-g00ecf