diff --git a/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php b/app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency.php index 00e289b9372672f2618304f9d661e1c9ae84614d..2a75aaa72036330cc3818242c28622176ecfbc36 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 @@ class Currency extends \Magento\Backend\Block\Template * Get header * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getHeader() { @@ -70,6 +71,7 @@ class Currency extends \Magento\Backend\Block\Template * Get save button html * * @return string + * @codeCoverageIgnore */ public function getSaveButtonHtml() { @@ -80,6 +82,7 @@ class Currency extends \Magento\Backend\Block\Template * Get reset button html * * @return string + * @codeCoverageIgnore */ public function getResetButtonHtml() { @@ -90,6 +93,7 @@ class Currency extends \Magento\Backend\Block\Template * Get import button html * * @return string + * @codeCoverageIgnore */ public function getImportButtonHtml() { @@ -100,6 +104,7 @@ class Currency extends \Magento\Backend\Block\Template * Get services html * * @return string + * @codeCoverageIgnore */ public function getServicesHtml() { @@ -110,6 +115,7 @@ class Currency extends \Magento\Backend\Block\Template * Get rates matrix html * * @return string + * @codeCoverageIgnore */ public function getRatesMatrixHtml() { @@ -120,6 +126,7 @@ class Currency extends \Magento\Backend\Block\Template * 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 331416abdf9945aaec43ce4c5a7652005b489e17..84574cb3c1e5e6a9a9aeebbd9543beaf5ec0455e 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 @@ class Matrix extends \Magento\Backend\Block\Template * 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 cced163b12413d310e865149ff098d40053f768b..64807eee230041d4bd53d40ef963adcf5b88fc2b 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 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns page header * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getHeader() { @@ -87,6 +88,7 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns URL for save action * * @return string + * @codeCoverageIgnore */ public function getFormActionUrl() { @@ -97,6 +99,7 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns website id * * @return int + * @codeCoverageIgnore */ public function getWebsiteId() { @@ -107,6 +110,7 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns store id * * @return int + * @codeCoverageIgnore */ public function getStoreId() { @@ -130,6 +134,7 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns inheritance text * * @return \Magento\Framework\Phrase + * @codeCoverageIgnore */ public function getInheritText() { diff --git a/app/code/Magento/CurrencySymbol/Helper/Data.php b/app/code/Magento/CurrencySymbol/Helper/Data.php deleted file mode 100644 index e3ae5efd76a484db1673e6cbd1322b9dd8a204d7..0000000000000000000000000000000000000000 --- a/app/code/Magento/CurrencySymbol/Helper/Data.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * Currency Symbol helper - * - * @author Magento Core Team <core@magentocommerce.com> - */ -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 a72a261640d15daefc3b9042d527d097da6bac4a..558983912e340245ab17bc41d84e08fb7b13a84f 100644 --- a/app/code/Magento/CurrencySymbol/Model/Observer.php +++ b/app/code/Magento/CurrencySymbol/Model/Observer.php @@ -3,29 +3,26 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +namespace Magento\CurrencySymbol\Model; + +use Magento\Framework\Locale\Currency; /** * Currency Symbol Observer - * - * @author Magento Core Team <core@magentocommerce.com> */ -namespace Magento\CurrencySymbol\Model; - 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 $symbolFactory */ - public function __construct(\Magento\CurrencySymbol\Helper\Data $currencySymbolData) + public function __construct(\Magento\CurrencySymbol\Model\System\CurrencysymbolFactory $symbolFactory) { - $this->_currencySymbolData = $currencySymbolData; + $this->symbolFactory = $symbolFactory; } /** @@ -38,8 +35,28 @@ class Observer { $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/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index 66510bd9522d6f05a8fe9e0e9e6849f624305a7b..ac0d784c1f87e4b9fb30ae651fe22a8ebe072c3f 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -137,11 +137,9 @@ class Currencysymbol } /** - * 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 @@ class Currencysymbol $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 @@ class Currencysymbol } 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,27 +178,23 @@ class Currencysymbol 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]); } } + $value = []; if ($symbols) { $value['options']['fields']['customsymbol']['value'] = serialize($symbols); } else { $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 +218,7 @@ class Currencysymbol } /** - * Returns custom currency symbol by currency code + * Return custom currency symbol by currency code * * @param string $code * @return string|false @@ -320,4 +268,57 @@ class Currencysymbol 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 + ) + ); + + $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 array_unique($allowedCurrencies); + } } 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 0000000000000000000000000000000000000000..3e282ec82c9c4585ce8d425560927185a48e9d06 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/MatrixTest.php @@ -0,0 +1,80 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Block\Adminhtml\System\Currency\Rate; + +class MatrixTest extends \PHPUnit_Framework_TestCase +{ + /** + * Object manager helper + * + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManagerHelper; + + protected function setUp() + { + $this->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 0000000000000000000000000000000000000000..7c5bbb1e5022c071b0585bf70cbc2c17b142d059 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/Currency/Rate/ServicesTest.php @@ -0,0 +1,95 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Block\Adminhtml\System\Currency\Rate; + +class ServicesTest extends \PHPUnit_Framework_TestCase +{ + /** + * Object manager helper + * + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManagerHelper; + + protected function setUp() + { + $this->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 0000000000000000000000000000000000000000..b939f876511a0198ddb439c89387854c85b04886 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencyTest.php @@ -0,0 +1,90 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Block\Adminhtml\System; + +class CurrencyTest extends \PHPUnit_Framework_TestCase +{ + /** + * Object manager helper + * + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManagerHelper; + + protected function setUp() + { + $this->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 0000000000000000000000000000000000000000..15e63325366c6e395dc1c079c691a69ce8194271 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Block/Adminhtml/System/CurrencysymbolTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Block\Adminhtml\System; + +class CurrencysymbolTest extends \PHPUnit_Framework_TestCase +{ + /** + * Object manager helper + * + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManagerHelper; + + protected function setUp() + { + $this->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); + } +} 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 0000000000000000000000000000000000000000..b75df9bce15b8c98e8c0b754a09c22491f431c31 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/IndexTest.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Controller\Adminhtml\System\Currencysymbol; + +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +/** + * Class IndexTest + */ +class IndexTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Index + */ + protected $action; + + /** + * @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $viewMock; + + /** + * @var \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject + */ + protected $layoutMock; + + /** + * @var \Magento\Framework\View\Element\BlockInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $blockMock; + + /** + * @var \Magento\Backend\Model\Menu|\PHPUnit_Framework_MockObject_MockObject + */ + protected $menuMock; + + /** + * @var \Magento\Backend\Model\Menu\Item|\PHPUnit_Framework_MockObject_MockObject + */ + protected $menuItemMock; + + /** + * @var \Magento\Framework\View\Result\Page|\PHPUnit_Framework_MockObject_MockObject + */ + protected $pageMock; + + /** + * @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject + */ + protected $pageConfigMock; + + /** + * @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject + */ + protected $titleMock; + + public function setUp() + { + $objectManager = new ObjectManager($this); + + $this->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 0000000000000000000000000000000000000000..5d6b9d997fc073eda72d344b707780d7b6aa0220 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/Currencysymbol/SaveTest.php @@ -0,0 +1,148 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Controller\Adminhtml\System\Currencysymbol; + +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; + +/** + * Class SaveTest + */ +class SaveTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save + */ + protected $action; + + /** + * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $requestMock; + + /** + * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $responseMock; + + /** + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $objectManagerMock; + + /** + * @var \Magento\CurrencySymbol\Model\System\Currencysymbol|\PHPUnit_Framework_MockObject_MockObject + */ + protected $currencySymbolMock; + + /** + * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $messageManagerMock; + + /** + * @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $redirectMock; + + /** + * @var \Magento\Backend\Helper\Data|\PHPUnit_Framework_MockObject_MockObject + */ + protected $helperMock; + + /** + * @var \Magento\Framework\Filter\FilterManager|\PHPUnit_Framework_MockObject_MockObject + */ + protected $filterManagerMock; + + public function setUp() + { + $objectManager = new ObjectManager($this); + + $this->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(__('You applied the custom currency symbols.')); + + $this->action->execute(); + } +} 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 0000000000000000000000000000000000000000..71fcf4aad4774aa4e9ecde6a4c4fcdefb77a4fce --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/ObserverTest.php @@ -0,0 +1,118 @@ +<?php +/** + * 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 +{ + /** + * @var \Magento\CurrencySymbol\Model\Observer + */ + private $observer; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|CurrencysymbolFactory $mockSymbolFactory + */ + private $mockSymbolFactory; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\CurrencySymbol\Model\System\Currencysymbol $mockSymbol + */ + private $mockSymbol; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Event\Observer $mockEvent + */ + private $mockEventObserver; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Event $mockEvent + */ + private $mockEvent; + + public function setUp() + { + $this->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_DISPLAY => \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/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 0000000000000000000000000000000000000000..edc5b01f3fd99f21cd8a8b71ad2c83f820331f39 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Model/System/CurrencysymbolTest.php @@ -0,0 +1,327 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\CurrencySymbol\Test\Unit\Model\System; + +use Magento\CurrencySymbol\Model\System\Currencysymbol; +use Magento\Store\Model\ScopeInterface; + +/** + * Class CurrencysymbolTest + */ +class CurrencysymbolTest extends \PHPUnit_Framework_TestCase +{ + /** + * Object manager helper + * + * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + */ + protected $objectManagerHelper; + + /** + * @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeResolverMock; + + /** + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $scopeConfigMock; + + /** + * @var \Magento\Store\Model\System\Store|\PHPUnit_Framework_MockObject_MockObject + */ + protected $systemStoreMock; + + /** + * @var \Magento\Config\Model\Config\Factory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $configFactoryMock; + + /** + * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $eventManagerMock; + + /** + * @var \Magento\Framework\App\Config\ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $coreConfigMock; + + /** + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $storeManagerMock; + + /** + * @var \Magento\Framework\App\Cache\TypeListInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $cacheTypeListMock; + + /** + * @var \Magento\CurrencySymbol\Model\System\Currencysymbol + */ + protected $model; + + protected function setUp() + { + $this->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->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); + + /** + * @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(); + $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'); + + $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) + { + /** + * @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([$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') + ->willReturnMap( + [ + [CurrencySymbol::XML_PATH_CUSTOM_CURRENCY_SYMBOL, ScopeInterface::SCOPE_STORE, null, ''], + [ + CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, + ScopeInterface::SCOPE_STORE, + $storeMock, + $currencies + ], + [CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, ScopeInterface::SCOPE_STORE, null, $currencies], + [ + CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES, + ScopeInterface::SCOPE_STORE, + $storeMock, + $currencies + ] + ] + ); + + $websiteMock->expects($this->any()) + ->method('getConfig') + ->with(CurrencySymbol::XML_PATH_ALLOWED_CURRENCIES) + ->willReturn($currencies); + $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en'); + } +} 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 0000000000000000000000000000000000000000..74af3f80cd78f038dcd04a1e76d4a23dd0013fe3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInvalidEmailHostnameMessage.php @@ -0,0 +1,55 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\User\Test\Constraint; + +use Magento\User\Test\Fixture\User; +use Magento\User\Test\Page\Adminhtml\UserEdit; +use Magento\Mtf\Constraint\AbstractConstraint; + +/** + * Class AssertUserInvalidEmailHostnameMessage + */ +class AssertUserInvalidEmailHostnameMessage extends AbstractConstraint +{ + /* tags */ + const SEVERITY = 'low'; + /* end tags */ + + const ERROR_MESSAGE = '\'%s\' is not a valid hostname for email address \'%s\''; + + /** + * Asserts that error message equals to expected message. + * + * @param UserEdit $userEdit + * @param User $user + * @return void + */ + public function processAssert(UserEdit $userEdit, User $user) + { + $email = $user->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 98c6794f0dfe3b4934290320024399493b1188ab..cac4f73a49c5f3ef40d607580ae439c728ed6ce2 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 @@ <data name="user/data/is_active" xsi:type="string">Active</data> <data name="isDuplicated" xsi:type="string">-</data> <data name="user/data/current_password" xsi:type="string">%current_password%</data> - <constraint name="Magento\User\Test\Constraint\AssertUserInvalidEmailMessage"/> + <constraint name="Magento\User\Test\Constraint\AssertUserInvalidEmailHostnameMessage"/> </variation> </testCase> </config> diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index f0be6c12172278b8e3a32b86848f296cd606d96a..9df31a3da5749caabd7d6bd2cce8dedafbb1d465 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 = 'display'; + /** * @var array */ @@ -72,9 +84,9 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface $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);