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..93c7e6452f72b937212d60a9f8eb07d247bb9090 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() { @@ -117,6 +121,7 @@ class Currencysymbol extends \Magento\Backend\Block\Widget\Form * Returns Custom currency symbol properties * * @return array + * @codeCoverageIgnore */ public function getCurrencySymbolsData() { @@ -130,6 +135,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/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); + } +}