From d21f1e97ddadd135fd641c8b380c49e75bff2ea1 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Fri, 19 Jun 2015 16:50:49 -0500 Subject: [PATCH 01/15] MAGETWO-37579: User invalid email message not displayed - modified functional test to expect the new error message --- .../AssertUserInvalidEmailHostnameMessage.php | 55 +++++++++++++++++++ .../TestCase/CreateAdminUserEntityTest.xml | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInvalidEmailHostnameMessage.php diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInvalidEmailHostnameMessage.php b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInvalidEmailHostnameMessage.php new file mode 100644 index 0000000000000..74af3f80cd78f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInvalidEmailHostnameMessage.php @@ -0,0 +1,55 @@ +getEmail(); + $hostname = substr($email, strpos($email, '@')+1); + $expectedMessage = sprintf(self::ERROR_MESSAGE, $hostname, $email); + $actualMessage = $userEdit->getMessagesBlock()->getErrorMessages(); + \PHPUnit_Framework_Assert::assertEquals( + $expectedMessage, + $actualMessage, + 'Wrong error message is displayed.' + . "\nExpected: " . $expectedMessage + . "\nActual: " . $actualMessage + ); + } + + /** + * Returns message if equals to expected message. + * + * @return string + */ + public function toString() + { + return 'Error message about invalid hostname for email on creation user page is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/TestCase/CreateAdminUserEntityTest.xml b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/CreateAdminUserEntityTest.xml index 98c6794f0dfe3..cac4f73a49c5f 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/TestCase/CreateAdminUserEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/CreateAdminUserEntityTest.xml @@ -88,7 +88,7 @@ Active - %current_password% - + From cf665fc6e25245f0f0a73ddef81418e9257dea35 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 23 Jun 2015 15:31:14 +0300 Subject: [PATCH 02/15] MAGETWO-38913: Add unit test coverage for \Magento\CurrencySymbol\Block\* --- .../Block/Adminhtml/System/Currency.php | 7 ++ .../Adminhtml/System/Currency/Rate/Matrix.php | 1 + .../Block/Adminhtml/System/Currencysymbol.php | 6 ++ .../System/Currency/Rate/MatrixTest.php | 80 ++++++++++++++++ .../System/Currency/Rate/ServicesTest.php | 95 +++++++++++++++++++ .../Block/Adminhtml/System/CurrencyTest.php | 90 ++++++++++++++++++ .../Adminhtml/System/CurrencysymbolTest.php | 82 ++++++++++++++++ 7 files changed, 361 insertions(+) create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/MatrixTest.php create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/ServicesTest.php create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencysymbolTest.php diff --git a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php index 00e289b937267..2a75aaa720363 100644 --- a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php +++ b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php @@ -60,6 +60,7 @@ protected function _prepareLayout() * Get header * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getHeader() { @@ -70,6 +71,7 @@ public function getHeader() * Get save button html * * @return string + * @codeCoverageIgnore */ public function getSaveButtonHtml() { @@ -80,6 +82,7 @@ public function getSaveButtonHtml() * Get reset button html * * @return string + * @codeCoverageIgnore */ public function getResetButtonHtml() { @@ -90,6 +93,7 @@ public function getResetButtonHtml() * Get import button html * * @return string + * @codeCoverageIgnore */ public function getImportButtonHtml() { @@ -100,6 +104,7 @@ public function getImportButtonHtml() * Get services html * * @return string + * @codeCoverageIgnore */ public function getServicesHtml() { @@ -110,6 +115,7 @@ public function getServicesHtml() * Get rates matrix html * * @return string + * @codeCoverageIgnore */ public function getRatesMatrixHtml() { @@ -120,6 +126,7 @@ public function getRatesMatrixHtml() * Get import form action url * * @return string + * @codeCoverageIgnore */ public function getImportFormAction() { diff --git a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency/Rate/Matrix.php b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency/Rate/Matrix.php index 331416abdf994..84574cb3c1e5e 100644 --- a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency/Rate/Matrix.php +++ b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency/Rate/Matrix.php @@ -83,6 +83,7 @@ protected function _prepareLayout() * Get rates form action * * @return string + * @codeCoverageIgnore */ public function getRatesFormAction() { diff --git a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php index cced163b12413..93c7e6452f72b 100644 --- a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php @@ -77,6 +77,7 @@ protected function _prepareLayout() * Returns page header * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getHeader() { @@ -87,6 +88,7 @@ public function getHeader() * Returns URL for save action * * @return string + * @codeCoverageIgnore */ public function getFormActionUrl() { @@ -97,6 +99,7 @@ public function getFormActionUrl() * Returns website id * * @return int + * @codeCoverageIgnore */ public function getWebsiteId() { @@ -107,6 +110,7 @@ public function getWebsiteId() * Returns store id * * @return int + * @codeCoverageIgnore */ public function getStoreId() { @@ -117,6 +121,7 @@ public function getStoreId() * Returns Custom currency symbol properties * * @return array + * @codeCoverageIgnore */ public function getCurrencySymbolsData() { @@ -130,6 +135,7 @@ public function getCurrencySymbolsData() * Returns inheritance text * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getInheritText() { diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/MatrixTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/MatrixTest.php new file mode 100644 index 0000000000000..3e282ec82c9c4 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/MatrixTest.php @@ -0,0 +1,80 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } + + protected function tearDown() + { + unset($this->objectManagerHelper); + } + + public function testPrepareLayout() + { + $allowCurrencies = ['EUR', 'UAH', 'USD']; + $baseCurrencies = ['USD']; + $currencyRates = ['USD' => ['EUR' => -1, 'UAH' => 21.775, 'GBP' => 12, 'USD' => 1]]; + $expectedCurrencyRates = ['USD' => ['EUR' => null, 'UAH' => '21.7750', 'GBP' => '12.0000', 'USD' => '1.0000']]; + $newRates = ['USD' => ['EUR' => 0.7767, 'UAH' => 20, 'GBP' => 12, 'USD' => 1]]; + $expectedNewRates = ['USD' => ['EUR' => '0.7767', 'UAH' => '20.0000', 'GBP' => '12.0000', 'USD' => '1.0000']]; + + $backendSessionMock = $this->getMock('Magento\Backend\Model\Session', ['getRates', 'unsetData'], [], '', false); + $backendSessionMock->expects($this->once())->method('getRates')->willReturn($newRates); + + $currencyFactoryMock = $this->getMock('Magento\Directory\Model\CurrencyFactory', ['create'], [], '', false); + $currencyMock = $this->getMock( + 'Magento\Directory\Model\Currency', + ['getConfigAllowCurrencies', 'getConfigBaseCurrencies', 'getCurrencyRates'], + [], + '', + false + ); + $currencyFactoryMock->expects($this->once())->method('create')->willReturn($currencyMock); + $currencyMock->expects($this->once())->method('getConfigAllowCurrencies')->willReturn($allowCurrencies); + $currencyMock->expects($this->once())->method('getConfigBaseCurrencies')->willReturn($baseCurrencies); + $currencyMock->expects($this->once()) + ->method('getCurrencyRates') + ->with($baseCurrencies, $allowCurrencies) + ->willReturn($currencyRates); + + /** @var $layoutMock \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */ + $layoutMock = $this->getMockForAbstractClass( + 'Magento\Framework\View\LayoutInterface', + [], + '', + false, + false, + true, + [] + ); + + /** @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate\Services */ + $block = $this->objectManagerHelper->getObject( + 'Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate\Matrix', + [ + 'dirCurrencyFactory' => $currencyFactoryMock, + 'backendSession' => $backendSessionMock + ] + ); + $block->setLayout($layoutMock); + $this->assertEquals($allowCurrencies, $block->getAllowedCurrencies()); + $this->assertEquals($baseCurrencies, $block->getDefaultCurrencies()); + $this->assertEquals($expectedCurrencyRates, $block->getOldRates()); + $this->assertEquals($expectedNewRates, $block->getNewRates()); + } +} diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/ServicesTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/ServicesTest.php new file mode 100644 index 0000000000000..7c5bbb1e5022c --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/ServicesTest.php @@ -0,0 +1,95 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } + + protected function tearDown() + { + unset($this->objectManagerHelper); + } + + public function testPrepareLayout() + { + $options = [['value' => 'value', 'label' => 'label']]; + $service = 'service'; + + $sourceServiceFactoryMock = $this->getMock( + 'Magento\Directory\Model\Currency\Import\Source\ServiceFactory', + ['create'], + [], + '', + false + ); + $sourceServiceMock = $this->getMock( + 'Magento\Directory\Model\Currency\Import\Source\Service', + [], + [], + '', + false + ); + $backendSessionMock = $this->getMock( + 'Magento\Backend\Model\Session', + ['getCurrencyRateService'], + [], + '', + false + ); + + /** @var $layoutMock \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */ + $layoutMock = $this->getMockForAbstractClass( + 'Magento\Framework\View\LayoutInterface', + [], + '', + false, + false, + true, + ['createBlock'] + ); + + $blockMock = $this->getMock( + 'Magento\Framework\View\Element\Html\Select', + ['setOptions', 'setId', 'setName', 'setValue', 'setTitle'], + [], + '', + false + ); + + $layoutMock->expects($this->once())->method('createBlock')->willReturn($blockMock); + + $sourceServiceFactoryMock->expects($this->once())->method('create')->willReturn($sourceServiceMock); + $sourceServiceMock->expects($this->once())->method('toOptionArray')->willReturn($options); + $backendSessionMock->expects($this->once())->method('getCurrencyRateService')->with(true)->willReturn($service); + + $blockMock->expects($this->once())->method('setOptions')->with($options)->willReturnSelf(); + $blockMock->expects($this->once())->method('setId')->with('rate_services')->willReturnSelf(); + $blockMock->expects($this->once())->method('setName')->with('rate_services')->willReturnSelf(); + $blockMock->expects($this->once())->method('setValue')->with($service)->willReturnSelf(); + $blockMock->expects($this->once())->method('setTitle')->with('Import Service')->willReturnSelf(); + + /** @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate\Services */ + $block = $this->objectManagerHelper->getObject( + 'Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate\Services', + [ + 'srcCurrencyFactory' => $sourceServiceFactoryMock, + 'backendSession' => $backendSessionMock + ] + ); + $block->setLayout($layoutMock); + } +} diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php new file mode 100644 index 0000000000000..b939f876511a0 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php @@ -0,0 +1,90 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } + + protected function tearDown() + { + unset($this->objectManagerHelper); + } + + public function testPrepareLayout() + { + $childBlockMock = $this->getMock( + 'Magento\Framework\View\Element\BlockInterface', + ['addChild', 'toHtml'], + [], + '', + false + ); + + $blockMock = $this->getMock( + 'Magento\Framework\View\Element\BlockInterface', + [], + [], + '', + false + ); + + /** @var $layoutMock \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */ + $layoutMock = $this->getMockForAbstractClass( + 'Magento\Framework\View\LayoutInterface', + [], + '', + false, + false, + true, + ['getBlock', 'createBlock'] + ); + + $layoutMock->expects($this->any())->method('getBlock')->willReturn($childBlockMock); + $layoutMock->expects($this->any())->method('createBlock')->willReturn($blockMock); + + $childBlockMock->expects($this->at(0)) + ->method('addChild') + ->with( + 'save_button', + 'Magento\Backend\Block\Widget\Button', + [ + 'label' => __('Save Currency Rates'), + 'class' => 'save primary save-currency-rates', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save', 'target' => '#rate-form']], + ] + ] + ); + + $childBlockMock->expects($this->at(1)) + ->method('addChild') + ->with( + 'reset_button', + 'Magento\Backend\Block\Widget\Button', + ['label' => __('Reset'), 'onclick' => 'document.location.reload()', 'class' => 'reset'] + ); + + /** @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currency */ + $block = $this->objectManagerHelper->getObject( + 'Magento\CurrencySymbol\Block\Adminhtml\System\Currency', + [ + 'layout' => $layoutMock + ] + ); + $block->setLayout($layoutMock); + } +} diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencysymbolTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencysymbolTest.php new file mode 100644 index 0000000000000..15e63325366c6 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencysymbolTest.php @@ -0,0 +1,82 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } + + protected function tearDown() + { + unset($this->objectManagerHelper); + } + + public function testPrepareLayout() + { + $symbolSystemFactoryMock = $this->getMock( + 'Magento\CurrencySymbol\Model\System\CurrencysymbolFactory', + ['create'], + [], + '', + false + ); + + $blockMock = $this->getMock( + 'Magento\Framework\View\Element\BlockInterface', + ['addChild', 'toHtml'], + [], + '', + false + ); + + /** @var $layoutMock \Magento\Framework\View\LayoutInterface|\PHPUnit_Framework_MockObject_MockObject */ + $layoutMock = $this->getMockForAbstractClass( + 'Magento\Framework\View\LayoutInterface', + [], + '', + false, + false, + true, + ['getBlock'] + ); + + $layoutMock->expects($this->once())->method('getBlock')->willReturn($blockMock); + + $blockMock->expects($this->once()) + ->method('addChild') + ->with( + 'save_button', + 'Magento\Backend\Block\Widget\Button', + [ + 'label' => __('Save Currency Symbols'), + 'class' => 'save primary save-currency-symbols', + 'data_attribute' => [ + 'mage-init' => ['button' => ['event' => 'save', 'target' => '#currency-symbols-form']], + ] + ] + ); + + /** @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol */ + $block = $this->objectManagerHelper->getObject( + 'Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol', + [ + 'symbolSystemFactory' => $symbolSystemFactoryMock, + 'layout' => $layoutMock + ] + ); + $block->setLayout($layoutMock); + } +} From c5f57b22d3ae08658eabe851673d4d7d67d9667f Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Tue, 23 Jun 2015 18:40:44 +0300 Subject: [PATCH 03/15] MAGETWO-38916: Add unit test coverage for \Magento\CurrencySymbol\Model\* - refactoring of the model --- .../Model/System/Currencysymbol.php | 135 +++++++++--------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index 66510bd9522d6..f42a6cec05975 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -137,11 +137,9 @@ public function __construct( } /** - * Returns currency symbol properties array based on config values + * Return currency symbol properties array based on config values * * @return array - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getCurrencySymbolsData() { @@ -151,52 +149,9 @@ public function getCurrencySymbolsData() $this->_symbolsData = []; - $allowedCurrencies = explode( - self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, - $this->_scopeConfig->getValue( - self::XML_PATH_ALLOWED_CURRENCIES, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - null - ) - ); - - /* @var $storeModel \Magento\Store\Model\System\Store */ - $storeModel = $this->_systemStore; - foreach ($storeModel->getWebsiteCollection() as $website) { - $websiteShow = false; - foreach ($storeModel->getGroupCollection() as $group) { - if ($group->getWebsiteId() != $website->getId()) { - continue; - } - foreach ($storeModel->getStoreCollection() as $store) { - if ($store->getGroupId() != $group->getId()) { - continue; - } - if (!$websiteShow) { - $websiteShow = true; - $websiteSymbols = $website->getConfig(self::XML_PATH_ALLOWED_CURRENCIES); - $allowedCurrencies = array_merge( - $allowedCurrencies, - explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $websiteSymbols) - ); - } - $storeSymbols = $this->_scopeConfig->getValue( - self::XML_PATH_ALLOWED_CURRENCIES, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $store - ); - $allowedCurrencies = array_merge( - $allowedCurrencies, - explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $storeSymbols) - ); - } - } - } - ksort($allowedCurrencies); - $currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL); - foreach ($allowedCurrencies as $code) { + foreach ($this->getAllowedCurrencies() as $code) { $currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies']; $symbol = $currencies[$code][0] ?: $code; $name = $currencies[$code][1] ?: $code; @@ -207,18 +162,15 @@ public function getCurrencySymbolsData() } else { $this->_symbolsData[$code]['displaySymbol'] = $this->_symbolsData[$code]['parentSymbol']; } - if ($this->_symbolsData[$code]['parentSymbol'] == $this->_symbolsData[$code]['displaySymbol']) { - $this->_symbolsData[$code]['inherited'] = true; - } else { - $this->_symbolsData[$code]['inherited'] = false; - } + $this->_symbolsData[$code]['inherited'] = + ($this->_symbolsData[$code]['parentSymbol'] == $this->_symbolsData[$code]['displaySymbol']); } return $this->_symbolsData; } /** - * Saves currency symbol to config + * Save currency symbol to config * * @param $symbols array * @return $this @@ -226,10 +178,8 @@ public function getCurrencySymbolsData() public function setCurrencySymbolsData($symbols = []) { foreach ($this->getCurrencySymbolsData() as $code => $values) { - if (isset($symbols[$code])) { - if ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code])) { - unset($symbols[$code]); - } + if (isset($symbols[$code]) && ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code]))) { + unset($symbols[$code]); } } if ($symbols) { @@ -238,15 +188,12 @@ public function setCurrencySymbolsData($symbols = []) $value['options']['fields']['customsymbol']['inherit'] = 1; } - $this->_configFactory->create()->setSection( - self::CONFIG_SECTION - )->setWebsite( - null - )->setStore( - null - )->setGroups( - $value - )->save(); + $this->_configFactory->create() + ->setSection(self::CONFIG_SECTION) + ->setWebsite(null) + ->setStore(null) + ->setGroups($value) + ->save(); $this->_eventManager->dispatch( 'admin_system_config_changed_section_currency_before_reinit', @@ -270,7 +217,7 @@ public function setCurrencySymbolsData($symbols = []) } /** - * Returns custom currency symbol by currency code + * Return custom currency symbol by currency code * * @param string $code * @return string|false @@ -320,4 +267,58 @@ protected function _unserializeStoreConfig($configPath, $storeId = null) return is_array($result) ? $result : []; } + + /** + * Return allowed currencies + * + * @return array + */ + protected function getAllowedCurrencies() + { + $allowedCurrencies = explode( + self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, + $this->_scopeConfig->getValue( + self::XML_PATH_ALLOWED_CURRENCIES, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + null + ) + ); + + /* @var $storeModel \Magento\Store\Model\System\Store */ + $storeModel = $this->_systemStore; + /** @var \Magento\Store\Model\Website $website */ + foreach ($storeModel->getWebsiteCollection() as $website) { + $websiteShow = false; + /** @var \Magento\Store\Model\Group $group */ + foreach ($storeModel->getGroupCollection() as $group) { + if ($group->getWebsiteId() != $website->getId()) { + continue; + } + /** @var \Magento\Store\Model\Store $store */ + foreach ($storeModel->getStoreCollection() as $store) { + if ($store->getGroupId() != $group->getId()) { + continue; + } + if (!$websiteShow) { + $websiteShow = true; + $websiteSymbols = $website->getConfig(self::XML_PATH_ALLOWED_CURRENCIES); + $allowedCurrencies = array_merge( + $allowedCurrencies, + explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $websiteSymbols) + ); + } + $storeSymbols = $this->_scopeConfig->getValue( + self::XML_PATH_ALLOWED_CURRENCIES, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $store + ); + $allowedCurrencies = array_merge( + $allowedCurrencies, + explode(self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR, $storeSymbols) + ); + } + } + } + return ksort($allowedCurrencies); + } } From 4b83b8e9b50e55d760b2364877f85c9f20b644aa Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Thu, 25 Jun 2015 17:03:50 +0300 Subject: [PATCH 04/15] MAGETWO-38916: Add unit test coverage for \Magento\CurrencySymbol\Model\* - unit tests --- .../Model/System/Currencysymbol.php | 3 +- .../Unit/Model/System/CurrencysymbolTest.php | 333 ++++++++++++++++++ 2 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php diff --git a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index f42a6cec05975..ff9351925c139 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -182,6 +182,7 @@ public function setCurrencySymbolsData($symbols = []) unset($symbols[$code]); } } + $value = []; if ($symbols) { $value['options']['fields']['customsymbol']['value'] = serialize($symbols); } else { @@ -319,6 +320,6 @@ protected function getAllowedCurrencies() } } } - return ksort($allowedCurrencies); + return array_unique($allowedCurrencies); } } diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php new file mode 100644 index 0000000000000..2d4f08eabd86e --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php @@ -0,0 +1,333 @@ +objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->scopeConfigMock = $this->getMock( + 'Magento\Framework\App\Config\ScopeConfigInterface', + ['getValue', 'isSetFlag'], + [], + '', + false + ); + $this->localeResolverMock = $this->getMock( + 'Magento\Framework\Locale\ResolverInterface', + [ + 'getLocale', + 'getDefaultLocalePath', + 'setDefaultLocale', + 'getDefaultLocale', + 'setLocale', + 'emulate', + 'revert' + ], + [], + '', + false + ); + $this->systemStoreMock = $this->getMock( + 'Magento\Store\Model\System\Store', + ['getWebsiteCollection', 'getGroupCollection', 'getStoreCollection'], + [], + '', + false + ); + $this->configFactoryMock = $this->getMock( + 'Magento\Config\Model\Config\Factory', + ['create'], + [], + '', + false + ); + $this->eventManagerMock = $this->getMock( + 'Magento\Framework\Event\ManagerInterface', + ['dispatch'], + [], + '', + false + ); + $this->coreConfigMock = $this->getMock( + 'Magento\Framework\App\Config\ReinitableConfigInterface', + ['reinit', 'setValue', 'getValue', 'isSetFlag'], + [], + '', + false + ); + $this->storeManagerMock = $this->getMock( + 'Magento\Store\Model\StoreManagerInterface', + [], + [], + '', + false + ); + $this->cacheTypeListMock = $this->getMock( + 'Magento\Framework\App\Cache\TypeListInterface', + [], + [], + '', + false + ); + $this->configMock = $this->getMock( + 'Magento\Config\Model\Config', + ['setSection', 'setWebsite', 'setStore', 'setGroups', 'save'], + [], + '', + false + ); + $this->websiteMock = $this->getMock('Magento\Store\Model\Website', ['getId', 'getConfig'], [], '', false); + $this->groupMock = $this->getMock('Magento\Store\Model\Group', ['getId', 'getWebsiteId'], [], '', false); + $this->storeMock = $this->getMock('Magento\Store\Model\Store', ['getGroupId'], [], '', false); + + + $this->model = $this->objectManagerHelper->getObject( + 'Magento\CurrencySymbol\Model\System\Currencysymbol', + [ + 'scopeConfig' => $this->scopeConfigMock, + 'localeResolver' => $this->localeResolverMock, + 'systemStore' => $this->systemStoreMock, + 'configFactory' => $this->configFactoryMock, + 'eventManager' => $this->eventManagerMock, + 'coreConfig' => $this->coreConfigMock, + 'storeManager' => $this->storeManagerMock, + 'cacheTypeList' => $this->cacheTypeListMock, + ] + ); + } + + protected function tearDown() + { + unset($this->objectManagerHelper); + } + + public function testGetCurrencySymbolData() + { + $expectedSymbolsData = [ + 'EUR' => [ + 'parentSymbol' => '€', + 'displayName' => 'Euro', + 'displaySymbol' => '€', + 'inherited' => true + ], + 'USD' => [ + 'parentSymbol' => '$', + 'displayName' => 'US Dollar', + 'displaySymbol' => '$', + 'inherited' => true + ] + ]; + $websiteId = 1; + $groupId = 2; + $currencies = 'USD,EUR'; + + $this->prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies); + $this->assertEquals($expectedSymbolsData, $this->model->getCurrencySymbolsData()); + } + + public function testSetCurrencySymbolData() + { + $websiteId = 1; + $groupId = 2; + $currencies = 'USD,EUR'; + $symbols = []; + $value['options']['fields']['customsymbol']['inherit'] = 1; + + $this->prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies); + + $this->configFactoryMock->expects($this->any())->method('create')->willReturn($this->configMock); + $this->configMock->expects($this->any()) + ->method('setSection') + ->with(Currencysymbol::CONFIG_SECTION) + ->willReturnSelf(); + $this->configMock->expects($this->any())->method('setWebsite')->with(null)->willReturnSelf(); + $this->configMock->expects($this->any())->method('setStore')->with(null)->willReturnSelf(); + $this->configMock->expects($this->any())->method('setGroups')->with($value)->willReturnSelf(); + + $this->coreConfigMock->expects($this->once())->method('reinit'); + $this->storeManagerMock->expects($this->once())->method('reinitStores'); + + $this->cacheTypeListMock->expects($this->atLeastOnce())->method('invalidate'); + + $this->eventManagerMock->expects($this->atLeastOnce())->method('dispatch')->willReturnMap( + [ + ['admin_system_config_changed_section_currency_before_reinit', null, null], + ['admin_system_config_changed_section_currency', null, null] + ] + ); + + $this->assertInstanceOf( + 'Magento\CurrencySymbol\Model\System\Currencysymbol', + $this->model->setCurrencySymbolsData($symbols) + ); + } + + /** + * @dataProvider getCurrencySymbolDataProvider + */ + public function testGetCurrencySymbol($code, $expectedSymbol, $serializedCustomSymbols) + { + $this->scopeConfigMock->expects($this->any()) + ->method('getValue') + ->willReturnMap( + [ + [ + CurrencySymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL, + ScopeInterface::SCOPE_STORE, + null, + $serializedCustomSymbols + ], + ] + ); + $currencySymbol = $this->model->getCurrencySymbol($code); + $this->assertEquals($expectedSymbol, $currencySymbol); + } + + public function getCurrencySymbolDataProvider() + { + return [ + 'existentCustomSymbol' => [ + 'code' => 'USD', + 'expectedSymbol' => '$', + 'serializedCustomSymbols' => 'a:1:{s:3:"USD";s:1:"$";}' + ], + 'nonExistentCustomSymbol' => [ + 'code' => 'UAH', + 'expectedSymbol' => false, + 'serializedCustomSymbols' => 'a:1:{s:3:"USD";s:1:"$";}' + ] + ]; + } + + /** + * Prepare mocks for getCurrencySymbolsData + * + * @param int $websiteId + * @param int $groupId + * @param string $currencies + */ + protected function prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies) + { + $this->systemStoreMock->expects($this->once()) + ->method('getWebsiteCollection') + ->willReturn([$this->websiteMock]); + $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn([$this->groupMock]); + $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn([$this->storeMock]); + $this->websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); + $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); + $this->groupMock->expects($this->any())->method('getId')->willReturn($groupId); + $this->storeMock->expects($this->any())->method('getGroupId')->willReturn($groupId); + + $this->scopeConfigMock->expects($this->any()) + ->method('getValue') + ->willReturnMap( + [ + [CurrencySymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL, ScopeInterface::SCOPE_STORE, null, ''], + [ + CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, + ScopeInterface::SCOPE_STORE, + $this->storeMock, + $currencies + ], + [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, null, $currencies], + [ + CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, + ScopeInterface::SCOPE_STORE, + $this->storeMock, + $currencies + ] + ] + ); + + $this->websiteMock->expects($this->any()) + ->method('getConfig') + ->with(CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES) + ->willReturn($currencies); + $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en'); + } + +} From a305dafb1c059c79585ed874bf531b13f41729c8 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Thu, 25 Jun 2015 17:03:50 +0300 Subject: [PATCH 05/15] MAGETWO-38916: Add unit test coverage for \Magento\CurrencySymbol\Model\* - unit tests --- app/code/Magento/CurrencySymbol/Model/Observer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CurrencySymbol/Model/Observer.php b/app/code/Magento/CurrencySymbol/Model/Observer.php index a72a261640d15..e769c3d81503f 100644 --- a/app/code/Magento/CurrencySymbol/Model/Observer.php +++ b/app/code/Magento/CurrencySymbol/Model/Observer.php @@ -33,6 +33,7 @@ public function __construct(\Magento\CurrencySymbol\Helper\Data $currencySymbolD * * @param \Magento\Framework\Event\Observer $observer * @return $this + * @codeCoverageIgnore */ public function currencyDisplayOptions(\Magento\Framework\Event\Observer $observer) { From f85c9fd2996db080e716d56f30f938d4b53db237 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Thu, 25 Jun 2015 21:39:42 -0500 Subject: [PATCH 06/15] MAGETWO-38915: Add unit test coverage for \Magento\CurrencySymbol\Helper\* --- .../Magento/CurrencySymbol/Helper/Data.php | 56 --------- .../Magento/CurrencySymbol/Model/Observer.php | 38 ++++-- .../Test/Unit/Model/ObserverTest.php | 115 ++++++++++++++++++ .../Magento/Framework/Locale/Currency.php | 18 ++- 4 files changed, 158 insertions(+), 69 deletions(-) delete mode 100644 app/code/Magento/CurrencySymbol/Helper/Data.php create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php diff --git a/app/code/Magento/CurrencySymbol/Helper/Data.php b/app/code/Magento/CurrencySymbol/Helper/Data.php deleted file mode 100644 index e3ae5efd76a48..0000000000000 --- a/app/code/Magento/CurrencySymbol/Helper/Data.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ -namespace Magento\CurrencySymbol\Helper; - -class Data extends \Magento\Framework\App\Helper\AbstractHelper -{ - /** - * @var \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory - */ - protected $_symbolFactory; - - /** - * @param \Magento\Framework\App\Helper\Context $context - * @param \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory - */ - public function __construct( - \Magento\Framework\App\Helper\Context $context, - \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory - ) { - $this->_symbolFactory = $symbolFactory; - parent::__construct( - $context - ); - } - - /** - * Get currency display options - * - * @param string $baseCode - * @return array - */ - public function getCurrencyOptions($baseCode) - { - $currencyOptions = []; - $currencySymbol = $this->_symbolFactory->create(); - if ($currencySymbol) { - $customCurrencySymbol = $currencySymbol->getCurrencySymbol($baseCode); - - if ($customCurrencySymbol) { - $currencyOptions['symbol'] = $customCurrencySymbol; - $currencyOptions['display'] = \Magento\Framework\Currency::USE_SYMBOL; - } - } - - return $currencyOptions; - } -} diff --git a/app/code/Magento/CurrencySymbol/Model/Observer.php b/app/code/Magento/CurrencySymbol/Model/Observer.php index e769c3d81503f..3e55902031ee3 100644 --- a/app/code/Magento/CurrencySymbol/Model/Observer.php +++ b/app/code/Magento/CurrencySymbol/Model/Observer.php @@ -6,26 +6,24 @@ /** * Currency Symbol Observer - * - * @author Magento Core Team */ namespace Magento\CurrencySymbol\Model; +use Magento\Framework\Locale\Currency; + class Observer { /** - * Currency symbol data - * - * @var \Magento\CurrencySymbol\Helper\Data + * @var \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory */ - protected $_currencySymbolData = null; + protected $symbolFactory; /** - * @param \Magento\CurrencySymbol\Helper\Data $currencySymbolData + * @param \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory */ - public function __construct(\Magento\CurrencySymbol\Helper\Data $currencySymbolData) + public function __construct(\Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory) { - $this->_currencySymbolData = $currencySymbolData; + $this->symbolFactory = $symbolFactory; } /** @@ -39,8 +37,28 @@ public function currencyDisplayOptions(\Magento\Framework\Event\Observer $observ { $baseCode = $observer->getEvent()->getBaseCode(); $currencyOptions = $observer->getEvent()->getCurrencyOptions(); - $currencyOptions->setData($this->_currencySymbolData->getCurrencyOptions($baseCode)); + $currencyOptions->setData($this->getCurrencyOptions($baseCode)); return $this; } + + /** + * Get currency display options + * + * @param string $baseCode + * @return array + */ + protected function getCurrencyOptions($baseCode) + { + $currencyOptions = []; + if ($baseCode) { + $customCurrencySymbol = $this->symbolFactory->create()->getCurrencySymbol($baseCode); + if ($customCurrencySymbol) { + $currencyOptions[Currency::CURRENCY_OPTION_SYMBOL] = $customCurrencySymbol; + $currencyOptions[Currency::CURRENCY_OPTION_DISPLAY] = \Magento\Framework\Currency::USE_SYMBOL; + } + } + + return $currencyOptions; + } } diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php new file mode 100644 index 0000000000000..6c5c69594dfe0 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php @@ -0,0 +1,115 @@ +mockSymbolFactory = $this->getMock( + 'Magento\CurrencySymbol\Model\System\CurrencysymbolFactory', + ['create'], + [], + '', + false + ); + + $this->mockSymbol = $this->getMock( + 'Magento\CurrencySymbol\Model\System\Currencysymbol', + ['getCurrencySymbol'], + [], + '', + false + ); + + $this->mockEventObserver = $this->getMock( + 'Magento\Framework\Event\Observer', + ['getEvent'], + [], + '', + false + ); + + $this->mockEvent = $this->getMock( + 'Magento\Framework\Event', + ['getBaseCode', 'getCurrencyOptions'], + [], + '', + false + ); + + $this->mockEventObserver->expects($this->any())->method('getEvent')->willReturn($this->mockEvent); + $this->mockSymbolFactory->expects($this->any())->method('create')->willReturn($this->mockSymbol); + + $this->observer = new Magento\CurrencySymbol\Model\Observer($this->mockSymbolFactory); + } + + public function testCurrencyDisplayOptionsEmpty() + { + $sampleCurrencyOptionObject = new \Magento\Framework\Object; + //Return invalid value + $this->mockEvent->expects($this->once())->method('getBaseCode')->willReturn(null); + $this->mockEvent->expects($this->once())->method('getCurrencyOptions')->willReturn($sampleCurrencyOptionObject); + $this->mockSymbol->expects($this->never())->method('getCurrencySymbol')->with(null)->willReturn(null); + + $this->observer->currencyDisplayOptions($this->mockEventObserver); + + // Check if option set is empty + $this->assertEquals([], $sampleCurrencyOptionObject->getData()); + } + + public function testCurrencyDisplayOptions() + { + $sampleCurrencyOptionObject = new \Magento\Framework\Object; + $sampleCurrency = 'USD'; + $sampleCurrencySymbol = '$'; + + $expectedCurrencyOptions = [ + \Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol, + \Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => \Magento\Framework\Currency::USE_SYMBOL + ]; + + //Return invalid value + $this->mockEvent->expects($this->once())->method('getBaseCode')->willReturn($sampleCurrency); + $this->mockEvent->expects($this->once())->method('getCurrencyOptions')->willReturn($sampleCurrencyOptionObject); + $this->mockSymbol->expects($this->once()) + ->method('getCurrencySymbol') + ->with($sampleCurrency) + ->willReturn($sampleCurrencySymbol); + + $this->observer->currencyDisplayOptions($this->mockEventObserver); + + // Check if option set is empty + $this->assertEquals($expectedCurrencyOptions, $sampleCurrencyOptionObject->getData()); + } +} diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index f0be6c1217227..efca02a754d0a 100644 --- a/lib/internal/Magento/Framework/Locale/Currency.php +++ b/lib/internal/Magento/Framework/Locale/Currency.php @@ -11,6 +11,18 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface * Default currency */ const DEFAULT_CURRENCY = 'USD'; + + /**#@+ + * Currency Options + */ + const CURRENCY_OPTION_SYMBOL = 'symbol'; + + const CURRENCY_OPTION_CURRENCY = 'currency'; + + const CURRENCY_OPTION_NAME = 'name'; + + const CURRENCY_OPTION_DISPLAY = 'name'; + /** * @var array */ @@ -72,9 +84,9 @@ public function getCurrency($currency) $currencyObject = $this->_currencyFactory->create( ['options' => $this->getDefaultCurrency(), 'locale' => $this->_localeResolver->getLocale()] ); - $options['name'] = $currency; - $options['currency'] = $currency; - $options['symbol'] = $currency; + $options[self::CURRENCY_OPTION_NAME] = $currency; + $options[self::CURRENCY_OPTION_CURRENCY] = $currency; + $options[self::CURRENCY_OPTION_SYMBOL] = $currency; } $options = new \Magento\Framework\Object($options); From 51ea456e6c7af1308589e4ff40453e933d90ca41 Mon Sep 17 00:00:00 2001 From: Anup Dugar Date: Fri, 26 Jun 2015 11:14:07 -0500 Subject: [PATCH 07/15] MAGETWO-38915: Add unit test coverage for \Magento\CurrencySymbol\Helper\* - Fixed constant value --- lib/internal/Magento/Framework/Locale/Currency.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index efca02a754d0a..9df31a3da5749 100644 --- a/lib/internal/Magento/Framework/Locale/Currency.php +++ b/lib/internal/Magento/Framework/Locale/Currency.php @@ -21,7 +21,7 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface const CURRENCY_OPTION_NAME = 'name'; - const CURRENCY_OPTION_DISPLAY = 'name'; + const CURRENCY_OPTION_DISPLAY = 'display'; /** * @var array From 42b2384a6d0079873838a14e0aee24f761eb231a Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 26 Jun 2015 19:30:13 +0300 Subject: [PATCH 08/15] MAGETWO-38914: Add unit test coverage for \Magento\CurrencySymbol\Controller\* - unit tests for Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol --- .../System/CurrencySymbol/IndexTest.php | 109 +++++++++++++ .../System/CurrencySymbol/SaveTest.php | 149 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php create mode 100644 app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php new file mode 100644 index 0000000000000..27b9913fc9aae --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php @@ -0,0 +1,109 @@ +menuItemMock = $this->getMock('Magento\Backend\Model\Menu\Item', [], [], '', false); + $this->menuMock = $this->getMock('Magento\Backend\Model\Menu', [], [], '', false); + + $this->titleMock = $this->getMock('Magento\Framework\View\Page\Title', [], [], '', false); + + $this->pageConfigMock = $this->getMock('Magento\Framework\View\Page\Config', [], [], '', false); + + $this->pageMock = $this->getMock('Magento\Framework\View\Result\Page', [], [], '', false); + + $this->blockMock = $this->getMockForAbstractClass( + 'Magento\Framework\View\Element\BlockInterface', + [], + '', + false, + false, + true, + ['addLink', 'setActive', 'getMenuModel'] + ); + + $this->layoutMock = $this->getMock('Magento\Framework\View\Layout', [], [], '', false); + + $this->viewMock = $this->getMock('Magento\Framework\App\ViewInterface', [], [], '', false); + + $this->action = $objectManager->getObject( + 'Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Index', + [ + 'view' => $this->viewMock + ] + ); + } + + public function testExecute() + { + $this->menuMock->expects($this->once())->method('getParentItems')->willReturn([$this->menuItemMock]); + $this->titleMock->expects($this->atLeastOnce())->method('prepend'); + $this->pageConfigMock->expects($this->atLeastOnce())->method('getTitle')->willReturn($this->titleMock); + $this->pageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock); + $this->blockMock->expects($this->atLeastOnce())->method('addLink'); + $this->blockMock->expects($this->once())->method('setActive'); + $this->blockMock->expects($this->once())->method('getMenuModel')->willReturn($this->menuMock); + $this->layoutMock->expects($this->atLeastOnce())->method('getBlock')->willReturn($this->blockMock); + $this->viewMock->expects($this->once())->method('loadLayout')->willReturnSelf(); + $this->viewMock->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layoutMock); + $this->viewMock->expects($this->atLeastOnce())->method('getPage')->willReturn($this->pageMock); + + $this->action->execute(); + } +} diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php new file mode 100644 index 0000000000000..f70a3b354d61c --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php @@ -0,0 +1,149 @@ +requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false); + + $this->helperMock = $this->getMock('Magento\Backend\Helper\Data', [], [], '', false); + + $this->redirectMock = $this->getMock('Magento\Framework\App\Response\RedirectInterface', [], [], '', false); + + $this->responseMock = $this->getMock( + 'Magento\Framework\App\ResponseInterface', + ['setRedirect', 'sendResponse'], + [], + '', + false + ); + + $this->currencySymbolMock = $this->getMock( + 'Magento\CurrencySymbol\Model\System\Currencysymbol', + [], + [], + '', + false + ); + + $this->filterManagerMock = $this->getMock( + 'Magento\Framework\Filter\FilterManager', + ['stripTags'], + [], + '', + false + ); + + $this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false); + + $this->messageManagerMock = $this->getMock('Magento\Framework\Message\ManagerInterface', [], [], '', false); + $this->action = $objectManager->getObject( + 'Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save', + [ + 'request' => $this->requestMock, + 'response' => $this->responseMock, + 'objectManager' => $this->objectManagerMock, + 'redirect' => $this->redirectMock, + 'helper' => $this->helperMock, + 'messageManager' => $this->messageManagerMock + ] + ); + } + + public function testExecute() + { + $firstElement = 'firstElement'; + $symbolsDataArray = [$firstElement]; + $redirectUrl = 'redirectUrl'; + + $this->requestMock->expects($this->once()) + ->method('getParam') + ->with('custom_currency_symbol') + ->willReturn($symbolsDataArray); + + $this->helperMock->expects($this->once())->method('getUrl')->with('*'); + $this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl); + + $this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray); + $this->responseMock->expects($this->once())->method('setRedirect'); + + $this->filterManagerMock->expects($this->once()) + ->method('stripTags') + ->with($firstElement) + ->willReturn($firstElement); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with('Magento\CurrencySymbol\Model\System\Currencysymbol') + ->willReturn($this->currencySymbolMock); + + $this->objectManagerMock->expects($this->once()) + ->method('get') + ->with('Magento\Framework\Filter\FilterManager') + ->willReturn($this->filterManagerMock); + + $this->messageManagerMock->expects($this->once()) + ->method('addSuccess') + ->with(__('The custom currency symbols were applied.')); + + $this->action->execute(); + } +} From f04ea6d2960034ab2fa535dd52263801f5b2bae4 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 26 Jun 2015 21:57:24 +0300 Subject: [PATCH 09/15] MAGETWO-38913: Add unit test coverage for \Magento\CurrencySymbol\Block\* - removed codeCoverageIgnore from one method --- .../CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php index 93c7e6452f72b..64807eee23004 100644 --- a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currencysymbol.php @@ -121,7 +121,6 @@ public function getStoreId() * Returns Custom currency symbol properties * * @return array - * @codeCoverageIgnore */ public function getCurrencySymbolsData() { From 8331b26ad8c2469bda52ade9c67ca4e12cfed424 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Fri, 26 Jun 2015 22:03:30 +0300 Subject: [PATCH 10/15] MAGETWO-38916: Add unit test coverage for \Magento\CurrencySymbol\Model\* - removed unnecessary doc block tags --- app/code/Magento/CurrencySymbol/Model/Observer.php | 1 - app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/code/Magento/CurrencySymbol/Model/Observer.php b/app/code/Magento/CurrencySymbol/Model/Observer.php index 3e55902031ee3..be7d871fe6701 100644 --- a/app/code/Magento/CurrencySymbol/Model/Observer.php +++ b/app/code/Magento/CurrencySymbol/Model/Observer.php @@ -31,7 +31,6 @@ public function __construct(\Magento\CurrencySymbol\Model\System\CurrencysymbolF * * @param \Magento\Framework\Event\Observer $observer * @return $this - * @codeCoverageIgnore */ public function currencyDisplayOptions(\Magento\Framework\Event\Observer $observer) { diff --git a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index ff9351925c139..ac0d784c1f87e 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -285,7 +285,6 @@ protected function getAllowedCurrencies() ) ); - /* @var $storeModel \Magento\Store\Model\System\Store */ $storeModel = $this->_systemStore; /** @var \Magento\Store\Model\Website $website */ foreach ($storeModel->getWebsiteCollection() as $website) { From 5c7425bf8f69b560d405b18066e06474b3b9e3c9 Mon Sep 17 00:00:00 2001 From: Cari Spruiell Date: Tue, 30 Jun 2015 13:38:19 -0500 Subject: [PATCH 11/15] MAGETWO-38915: Add unit test coverage for \Magento\CurrencySymbol\Helper\* - corrected key value used in expected test results --- .../Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php index 6c5c69594dfe0..dedfd4661734a 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php @@ -96,7 +96,7 @@ public function testCurrencyDisplayOptions() $expectedCurrencyOptions = [ \Magento\Framework\Locale\Currency::CURRENCY_OPTION_SYMBOL => $sampleCurrencySymbol, - \Magento\Framework\Locale\Currency::CURRENCY_OPTION_NAME => \Magento\Framework\Currency::USE_SYMBOL + \Magento\Framework\Locale\Currency::CURRENCY_OPTION_DISPLAY => \Magento\Framework\Currency::USE_SYMBOL ]; //Return invalid value From a6b95a44dc997c8fb067c984102cfc3c6dddc7e7 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 1 Jul 2015 14:54:11 +0300 Subject: [PATCH 12/15] MAGETWO-38914: Add unit test coverage for \Magento\CurrencySymbol\Controller\* - fixed code format --- .../Controller/Adminhtml/System/CurrencySymbol/IndexTest.php | 4 +++- .../Controller/Adminhtml/System/CurrencySymbol/SaveTest.php | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php index 27b9913fc9aae..b75df9bce15b8 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php @@ -52,7 +52,9 @@ class IndexTest extends \PHPUnit_Framework_TestCase */ protected $pageConfigMock; - /** @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject + */ protected $titleMock; public function setUp() diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php index f70a3b354d61c..1bebe51f64b07 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php @@ -57,7 +57,6 @@ class SaveTest extends \PHPUnit_Framework_TestCase */ protected $filterManagerMock; - public function setUp() { $objectManager = new ObjectManager($this); From 8fefb126734220da43ea61a6dd1a9a88e8b48311 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 1 Jul 2015 17:57:15 +0300 Subject: [PATCH 13/15] MAGETWO-39392: Merge and Fix Builds --- .../Controller/Adminhtml/System/CurrencySymbol/SaveTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php index 1bebe51f64b07..5d6b9d997fc07 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php @@ -141,7 +141,7 @@ public function testExecute() $this->messageManagerMock->expects($this->once()) ->method('addSuccess') - ->with(__('The custom currency symbols were applied.')); + ->with(__('You applied the custom currency symbols.')); $this->action->execute(); } From 31cc4650af20263f0909b0037dcfd1fe1714a254 Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 1 Jul 2015 19:25:51 +0300 Subject: [PATCH 14/15] MAGETWO-39392: Merge and Fix Builds - intermediate commit to rename to lowercase --- .../System/{CurrencySymbol => CurrencySymbolTemp}/IndexTest.php | 0 .../System/{CurrencySymbol => CurrencySymbolTemp}/SaveTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/{CurrencySymbol => CurrencySymbolTemp}/IndexTest.php (100%) rename app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/{CurrencySymbol => CurrencySymbolTemp}/SaveTest.php (100%) diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/IndexTest.php similarity index 100% rename from app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php rename to app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/IndexTest.php diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/SaveTest.php similarity index 100% rename from app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php rename to app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/SaveTest.php From af3f50c37657a104893b0e715edd2af30622628d Mon Sep 17 00:00:00 2001 From: Arkadii Chyzhov Date: Wed, 1 Jul 2015 19:41:49 +0300 Subject: [PATCH 15/15] MAGETWO-39392: Merge and Fix Builds - fixes for tests --- .../Magento/CurrencySymbol/Model/Observer.php | 9 +- .../IndexTest.php | 0 .../SaveTest.php | 0 .../Test/Unit/Model/ObserverTest.php | 9 +- .../Unit/Model/System/CurrencysymbolTest.php | 88 +++++++++---------- 5 files changed, 51 insertions(+), 55 deletions(-) rename app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/{CurrencySymbolTemp => Currencysymbol}/IndexTest.php (100%) rename app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/{CurrencySymbolTemp => Currencysymbol}/SaveTest.php (100%) diff --git a/app/code/Magento/CurrencySymbol/Model/Observer.php b/app/code/Magento/CurrencySymbol/Model/Observer.php index be7d871fe6701..558983912e340 100644 --- a/app/code/Magento/CurrencySymbol/Model/Observer.php +++ b/app/code/Magento/CurrencySymbol/Model/Observer.php @@ -3,14 +3,13 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - -/** - * Currency Symbol Observer - */ namespace Magento\CurrencySymbol\Model; use Magento\Framework\Locale\Currency; +/** + * Currency Symbol Observer + */ class Observer { /** @@ -19,7 +18,7 @@ class Observer protected $symbolFactory; /** - * @param \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory + * @param \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory */ public function __construct(\Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory) { diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/IndexTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/IndexTest.php similarity index 100% rename from app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/IndexTest.php rename to app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/IndexTest.php diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/SaveTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/SaveTest.php similarity index 100% rename from app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbolTemp/SaveTest.php rename to app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/SaveTest.php diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php index dedfd4661734a..71fcf4aad4774 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php @@ -3,11 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +namespace Magento\CurrencySymbol\Test\Unit\Model; + +use \Magento\CurrencySymbol\Model\System\CurrencysymbolFactory; /** * Test for \Magento\CurrencySymbol\Model\Observer */ -class ObserverTest extends PHPUnit_Framework_TestCase +class ObserverTest extends \PHPUnit_Framework_TestCase { /** * @var \Magento\CurrencySymbol\Model\Observer @@ -15,7 +18,7 @@ class ObserverTest extends PHPUnit_Framework_TestCase private $observer; /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $mockSymbolFactory + * @var \PHPUnit_Framework_MockObject_MockObject|CurrencysymbolFactory $mockSymbolFactory */ private $mockSymbolFactory; @@ -71,7 +74,7 @@ public function setUp() $this->mockEventObserver->expects($this->any())->method('getEvent')->willReturn($this->mockEvent); $this->mockSymbolFactory->expects($this->any())->method('create')->willReturn($this->mockSymbol); - $this->observer = new Magento\CurrencySymbol\Model\Observer($this->mockSymbolFactory); + $this->observer = new \Magento\CurrencySymbol\Model\Observer($this->mockSymbolFactory); } public function testCurrencyDisplayOptionsEmpty() diff --git a/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php b/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php index 2d4f08eabd86e..edc5b01f3fd99 100644 --- a/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php @@ -35,31 +35,11 @@ class CurrencysymbolTest extends \PHPUnit_Framework_TestCase */ protected $systemStoreMock; - /** - * @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject - */ - protected $websiteMock; - - /** - * @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject - */ - protected $groupMock; - - /** - * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject - */ - protected $storeMock; - /** * @var \Magento\Config\Model\Config\Factory|\PHPUnit_Framework_MockObject_MockObject */ protected $configFactoryMock; - /** - * @var \Magento\Config\Model\Config|\PHPUnit_Framework_MockObject_MockObject - */ - protected $configMock; - /** * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -153,17 +133,6 @@ protected function setUp() '', false ); - $this->configMock = $this->getMock( - 'Magento\Config\Model\Config', - ['setSection', 'setWebsite', 'setStore', 'setGroups', 'save'], - [], - '', - false - ); - $this->websiteMock = $this->getMock('Magento\Store\Model\Website', ['getId', 'getConfig'], [], '', false); - $this->groupMock = $this->getMock('Magento\Store\Model\Group', ['getId', 'getWebsiteId'], [], '', false); - $this->storeMock = $this->getMock('Magento\Store\Model\Store', ['getGroupId'], [], '', false); - $this->model = $this->objectManagerHelper->getObject( 'Magento\CurrencySymbol\Model\System\Currencysymbol', @@ -219,14 +188,25 @@ public function testSetCurrencySymbolData() $this->prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies); - $this->configFactoryMock->expects($this->any())->method('create')->willReturn($this->configMock); - $this->configMock->expects($this->any()) + /** + * @var \Magento\Config\Model\Config|\PHPUnit_Framework_MockObject_MockObject + */ + $configMock = $this->getMock( + 'Magento\Config\Model\Config', + ['setSection', 'setWebsite', 'setStore', 'setGroups', 'save'], + [], + '', + false + ); + + $this->configFactoryMock->expects($this->any())->method('create')->willReturn($configMock); + $configMock->expects($this->any()) ->method('setSection') ->with(Currencysymbol::CONFIG_SECTION) ->willReturnSelf(); - $this->configMock->expects($this->any())->method('setWebsite')->with(null)->willReturnSelf(); - $this->configMock->expects($this->any())->method('setStore')->with(null)->willReturnSelf(); - $this->configMock->expects($this->any())->method('setGroups')->with($value)->willReturnSelf(); + $configMock->expects($this->any())->method('setWebsite')->with(null)->willReturnSelf(); + $configMock->expects($this->any())->method('setStore')->with(null)->willReturnSelf(); + $configMock->expects($this->any())->method('setGroups')->with($value)->willReturnSelf(); $this->coreConfigMock->expects($this->once())->method('reinit'); $this->storeManagerMock->expects($this->once())->method('reinitStores'); @@ -292,15 +272,30 @@ public function getCurrencySymbolDataProvider() */ protected function prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $currencies) { + /** + * @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject + */ + $websiteMock = $this->getMock('Magento\Store\Model\Website', ['getId', 'getConfig'], [], '', false); + + /** + * @var \Magento\Store\Model\Group|\PHPUnit_Framework_MockObject_MockObject + */ + $groupMock = $this->getMock('Magento\Store\Model\Group', ['getId', 'getWebsiteId'], [], '', false); + + /** + * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject + */ + $storeMock = $this->getMock('Magento\Store\Model\Store', ['getGroupId'], [], '', false); + $this->systemStoreMock->expects($this->once()) ->method('getWebsiteCollection') - ->willReturn([$this->websiteMock]); - $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn([$this->groupMock]); - $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn([$this->storeMock]); - $this->websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); - $this->groupMock->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); - $this->groupMock->expects($this->any())->method('getId')->willReturn($groupId); - $this->storeMock->expects($this->any())->method('getGroupId')->willReturn($groupId); + ->willReturn([$websiteMock]); + $this->systemStoreMock->expects($this->once())->method('getGroupCollection')->willReturn([$groupMock]); + $this->systemStoreMock->expects($this->once())->method('getStoreCollection')->willReturn([$storeMock]); + $websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); + $groupMock->expects($this->any())->method('getWebsiteId')->willReturn($websiteId); + $groupMock->expects($this->any())->method('getId')->willReturn($groupId); + $storeMock->expects($this->any())->method('getGroupId')->willReturn($groupId); $this->scopeConfigMock->expects($this->any()) ->method('getValue') @@ -310,24 +305,23 @@ protected function prepareMocksForGetCurrencySymbolsData($websiteId, $groupId, $ [ CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, - $this->storeMock, + $storeMock, $currencies ], [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, null, $currencies], [ CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, - $this->storeMock, + $storeMock, $currencies ] ] ); - $this->websiteMock->expects($this->any()) + $websiteMock->expects($this->any()) ->method('getConfig') ->with(CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES) ->willReturn($currencies); $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en'); } - }