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' ] ], ]; } }