From 736ed23c721ecf50327ce0173ea4ecd7ce224973 Mon Sep 17 00:00:00 2001
From: Arkadii Chyzhov <achyzhov@ebay.com>
Date: Tue, 23 Jun 2015 15:31:14 +0300
Subject: [PATCH] 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 00e289b9372..2a75aaa7203 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 331416abdf9..84574cb3c1e 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 cced163b124..93c7e6452f7 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 00000000000..3e282ec82c9
--- /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 00000000000..7c5bbb1e502
--- /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 00000000000..b939f876511
--- /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 00000000000..15e63325366
--- /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);
+    }
+}
-- 
GitLab