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..27b9913fc9aaebf37f86d901a0aa255bb74037be --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/IndexTest.php @@ -0,0 +1,109 @@ +<?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..f70a3b354d61c87b458b43df05ba6b008b541dc8 --- /dev/null +++ b/app/code/Magento/CurrencySymbol/Test/Unit/Controller/Adminhtml/System/CurrencySymbol/SaveTest.php @@ -0,0 +1,149 @@ +<?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(__('The custom currency symbols were applied.')); + + $this->action->execute(); + } +}