123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\Framework\Locale\Test\Unit\Deployed;
- use Magento\Framework\App\DeploymentConfig;
- use Magento\Framework\App\State;
- use Magento\Framework\Config\ConfigOptionsListConstants as Constants;
- use Magento\Framework\Locale\AvailableLocalesInterface;
- use Magento\Framework\Locale\Deployed\Options;
- use Magento\Framework\Locale\ListsInterface;
- use Magento\Framework\View\Design\ThemeInterface;
- use Magento\Framework\View\DesignInterface;
- use \PHPUnit_Framework_MockObject_MockObject as MockObject;
- /**
- * Test for Options class.
- *
- * @see Options
- */
- class OptionsTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var State|MockObject
- */
- private $stateMock;
- /**
- * @var AvailableLocalesInterface|MockObject
- */
- private $availableLocalesMock;
- /**
- * @var DesignInterface|MockObject
- */
- private $designMock;
- /**
- * @var ListsInterface|MockObject
- */
- private $localeListsMock;
- /**
- * @var DeploymentConfig|MockObject
- */
- private $deploymentConfigMock;
- /**
- * @var Options
- */
- private $model;
- /**
- * @inheritdoc
- */
- protected function setUp()
- {
- $this->stateMock = $this->getMockBuilder(State::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->availableLocalesMock = $this->getMockBuilder(AvailableLocalesInterface::class)
- ->getMockForAbstractClass();
- $this->designMock = $this->getMockBuilder(DesignInterface::class)
- ->getMockForAbstractClass();
- $this->localeListsMock = $this->getMockBuilder(ListsInterface::class)
- ->getMockForAbstractClass();
- $this->deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
- $this->model = new Options(
- $this->localeListsMock,
- $this->stateMock,
- $this->availableLocalesMock,
- $this->designMock,
- $this->deploymentConfigMock
- );
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @param array $locales
- * @return void
- *
- * @dataProvider getFullLocalesDataProvider
- */
- public function testGetOptionLocalesFull(string $mode, int $scdOnDemand, array $locales): void
- {
- $this->localeListsMock->expects($this->once())
- ->method('getOptionLocales')
- ->willReturn($locales);
- $this->prepareGetLocalesFull($mode, $scdOnDemand);
- $this->assertEquals($locales, array_values($this->model->getOptionLocales()));
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @param array $locales
- * @return void
- *
- * @dataProvider getFullLocalesDataProvider
- */
- public function testGetTranslatedOptionLocalesFull(string $mode, int $scdOnDemand, array $locales): void
- {
- $this->localeListsMock->expects($this->once())
- ->method('getTranslatedOptionLocales')
- ->willReturn($locales);
- $this->prepareGetLocalesFull($mode, $scdOnDemand);
- $this->assertEquals($locales, array_values($this->model->getTranslatedOptionLocales()));
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @param array $locales
- * @param array $expectedLocales
- * @param array $deployedCodes
- * @return void
- *
- * @dataProvider getLimitedLocalesDataProvider
- */
- public function testGetOptionLocalesLimited(
- string $mode,
- int $scdOnDemand,
- array $locales,
- array $expectedLocales,
- array $deployedCodes
- ): void {
- $this->localeListsMock->expects($this->once())
- ->method('getOptionLocales')
- ->willReturn($locales);
- $this->prepareGetLocalesLimited($mode, $scdOnDemand, $deployedCodes);
- $this->assertEquals($expectedLocales, array_values($this->model->getOptionLocales()));
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @param array $locales
- * @param array $expectedLocales
- * @param array $deployedCodes
- * @return void
- *
- * @dataProvider getLimitedLocalesDataProvider
- */
- public function testGetTranslatedOptionLocalesLimited(
- string $mode,
- int $scdOnDemand,
- array $locales,
- array $expectedLocales,
- array $deployedCodes
- ): void {
- $this->localeListsMock->expects($this->once())
- ->method('getTranslatedOptionLocales')
- ->willReturn($locales);
- $this->prepareGetLocalesLimited($mode, $scdOnDemand, $deployedCodes);
- $this->assertEquals($expectedLocales, array_values($this->model->getTranslatedOptionLocales()));
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @param array $deployedCodes
- * @return void
- */
- private function prepareGetLocalesLimited(string $mode, int $scdOnDemand, $deployedCodes): void
- {
- $this->stateMock->expects($this->once())
- ->method('getMode')
- ->willReturn($mode);
- $this->deploymentConfigMock->expects($this->any())
- ->method('getConfigData')
- ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
- ->willReturn($scdOnDemand);
- $area = 'area';
- $code = 'code';
- $themeMock = $this->getMockBuilder(ThemeInterface::class)
- ->getMockForAbstractClass();
- $themeMock->expects($this->once())
- ->method('getCode')
- ->willReturn($code);
- $themeMock->expects($this->once())
- ->method('getArea')
- ->willReturn($area);
- $this->designMock->expects($this->once())
- ->method('getDesignTheme')
- ->willReturn($themeMock);
- $this->availableLocalesMock->expects($this->once())
- ->method('getList')
- ->with($code, $area)
- ->willReturn($deployedCodes);
- }
- /**
- * @param string $mode
- * @param int $scdOnDemand
- * @return void
- */
- private function prepareGetLocalesFull(string $mode, int $scdOnDemand): void
- {
- $this->stateMock->expects($this->once())
- ->method('getMode')
- ->willReturn($mode);
- $this->deploymentConfigMock->expects($this->any())
- ->method('getConfigData')
- ->with(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
- ->willReturn($scdOnDemand);
- $this->designMock->expects($this->never())
- ->method('getDesignTheme');
- }
- /**
- * @return array
- */
- public function getFullLocalesDataProvider(): array
- {
- $deLocale = [
- 'value' => 'de_DE',
- 'label' => 'German (German)'
- ];
- $daLocale = [
- 'value' => 'da_DK',
- 'label' => 'Danish (Denmark)'
- ];
- return [
- [
- State::MODE_PRODUCTION,
- 1,
- [$daLocale, $deLocale],
- ],
- [
- State::MODE_DEVELOPER,
- 0,
- [$daLocale, $deLocale],
- ],
- [
- State::MODE_DEVELOPER,
- 1,
- [$deLocale],
- ],
- [
- State::MODE_DEFAULT,
- 0,
- [$daLocale],
- ],
- [
- State::MODE_DEFAULT,
- 1,
- [$daLocale, $deLocale],
- ],
- ];
- }
- /**
- * @return array
- */
- public function getLimitedLocalesDataProvider(): array
- {
- $deLocale = [
- 'value' => 'de_DE',
- 'label' => 'German (German)'
- ];
- $daLocale = [
- 'value' => 'da_DK',
- 'label' => 'Danish (Denmark)'
- ];
- return [
- [
- State::MODE_PRODUCTION,
- 0,
- [
- $daLocale,
- $deLocale
- ],
- [
- $deLocale
- ],
- [
- 'de_DE'
- ]
- ],
- [
- State::MODE_PRODUCTION,
- 0,
- [
- $daLocale,
- $deLocale
- ],
- [
- $daLocale,
- $deLocale
- ],
- [
- 'da_DK',
- 'de_DE'
- ]
- ],
- ];
- }
- }
|