|
5 | 5 | */
|
6 | 6 | namespace Magento\CurrencySymbol\Test\Unit\Controller\Adminhtml\System\Currencysymbol;
|
7 | 7 |
|
| 8 | +use Magento\Backend\Helper\Data; |
| 9 | +use Magento\Backend\Model\View\Result\Redirect; |
| 10 | +use Magento\Backend\Model\View\Result\RedirectFactory; |
| 11 | +use Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save; |
| 12 | +use Magento\CurrencySymbol\Model\System\Currencysymbol; |
| 13 | +use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory; |
| 14 | +use Magento\Framework\App\RequestInterface; |
| 15 | +use Magento\Framework\App\Response\RedirectInterface; |
| 16 | +use Magento\Framework\App\ResponseInterface; |
| 17 | +use Magento\Framework\Filter\FilterManager; |
| 18 | +use Magento\Framework\Message\ManagerInterface; |
8 | 19 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | +use PHPUnit\Framework\MockObject\MockObject; |
9 | 22 |
|
10 | 23 | /**
|
11 |
| - * Class SaveTest |
| 24 | + * Test ot to save currency symbol controller |
12 | 25 | */
|
13 |
| -class SaveTest extends \PHPUnit\Framework\TestCase |
| 26 | +class SaveTest extends TestCase |
14 | 27 | {
|
15 | 28 | /**
|
16 |
| - * @var \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save |
| 29 | + * @var Save |
17 | 30 | */
|
18 | 31 | protected $action;
|
19 | 32 |
|
20 | 33 | /**
|
21 |
| - * @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject |
| 34 | + * @var RedirectFactory|MockObject |
| 35 | + */ |
| 36 | + private $resultRedirectFactory; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var RequestInterface|MockObject |
22 | 40 | */
|
23 | 41 | protected $requestMock;
|
24 | 42 |
|
25 | 43 | /**
|
26 |
| - * @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject |
| 44 | + * @var ResponseInterface|MockObject |
27 | 45 | */
|
28 | 46 | protected $responseMock;
|
29 | 47 |
|
30 | 48 | /**
|
31 |
| - * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 49 | + * @var ManagerInterface|MockObject |
32 | 50 | */
|
33 |
| - protected $objectManagerMock; |
| 51 | + protected $messageManagerMock; |
34 | 52 |
|
35 | 53 | /**
|
36 |
| - * @var \Magento\CurrencySymbol\Model\System\Currencysymbol|\PHPUnit_Framework_MockObject_MockObject |
| 54 | + * @var RedirectInterface|MockObject |
37 | 55 | */
|
38 |
| - protected $currencySymbolMock; |
| 56 | + protected $redirectMock; |
39 | 57 |
|
40 | 58 | /**
|
41 |
| - * @var \Magento\Framework\Message\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 59 | + * @var Data|MockObject |
42 | 60 | */
|
43 |
| - protected $messageManagerMock; |
| 61 | + protected $helperMock; |
44 | 62 |
|
45 | 63 | /**
|
46 |
| - * @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject |
| 64 | + * @var FilterManager|MockObject |
47 | 65 | */
|
48 |
| - protected $redirectMock; |
| 66 | + private $filterManager; |
49 | 67 |
|
50 | 68 | /**
|
51 |
| - * @var \Magento\Backend\Helper\Data|\PHPUnit_Framework_MockObject_MockObject |
| 69 | + * @var CurrencysymbolFactory|MockObject |
52 | 70 | */
|
53 |
| - protected $helperMock; |
| 71 | + private $currencySymbolFactory; |
54 | 72 |
|
55 | 73 | /**
|
56 |
| - * @var \Magento\Framework\Filter\FilterManager|\PHPUnit_Framework_MockObject_MockObject |
| 74 | + * @inheritdoc |
57 | 75 | */
|
58 |
| - protected $filterManagerMock; |
59 |
| - |
60 | 76 | protected function setUp()
|
61 | 77 | {
|
62 | 78 | $objectManager = new ObjectManager($this);
|
63 |
| - |
64 |
| - $this->requestMock = $this->createMock(\Magento\Framework\App\RequestInterface::class); |
65 |
| - |
66 |
| - $this->helperMock = $this->createMock(\Magento\Backend\Helper\Data::class); |
67 |
| - |
68 |
| - $this->redirectMock = $this->createMock(\Magento\Framework\App\Response\RedirectInterface::class); |
69 |
| - |
| 79 | + $this->requestMock = $this->createMock(RequestInterface::class); |
| 80 | + $this->helperMock = $this->createMock(Data::class); |
| 81 | + $this->redirectMock = $this->createMock(RedirectInterface::class); |
70 | 82 | $this->responseMock = $this->createPartialMock(
|
71 |
| - \Magento\Framework\App\ResponseInterface::class, |
| 83 | + ResponseInterface::class, |
72 | 84 | ['setRedirect', 'sendResponse']
|
73 | 85 | );
|
74 |
| - |
75 |
| - $this->currencySymbolMock = $this->createMock(\Magento\CurrencySymbol\Model\System\Currencysymbol::class); |
76 |
| - |
77 |
| - $this->filterManagerMock = $this->createPartialMock( |
78 |
| - \Magento\Framework\Filter\FilterManager::class, |
| 86 | + $this->messageManagerMock = $this->createMock(ManagerInterface::class); |
| 87 | + $this->resultRedirectFactory = $this->createMock(RedirectFactory::class); |
| 88 | + $this->filterManager = $this->createPartialMock( |
| 89 | + FilterManager::class, |
79 | 90 | ['stripTags']
|
80 | 91 | );
|
| 92 | + $this->currencySymbolFactory = $this->createMock(CurrencysymbolFactory::class); |
81 | 93 |
|
82 |
| - $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class); |
83 |
| - |
84 |
| - $this->messageManagerMock = $this->createMock(\Magento\Framework\Message\ManagerInterface::class); |
85 | 94 | $this->action = $objectManager->getObject(
|
86 |
| - \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol\Save::class, |
| 95 | + Save::class, |
87 | 96 | [
|
88 | 97 | 'request' => $this->requestMock,
|
89 | 98 | 'response' => $this->responseMock,
|
90 |
| - 'objectManager' => $this->objectManagerMock, |
91 | 99 | 'redirect' => $this->redirectMock,
|
92 | 100 | 'helper' => $this->helperMock,
|
93 |
| - 'messageManager' => $this->messageManagerMock |
| 101 | + 'messageManager' => $this->messageManagerMock, |
| 102 | + 'resultRedirectFactory' => $this->resultRedirectFactory, |
| 103 | + 'filterManager' => $this->filterManager, |
| 104 | + 'currencySymbolFactory' => $this->currencySymbolFactory, |
94 | 105 | ]
|
95 | 106 | );
|
96 | 107 | }
|
97 | 108 |
|
| 109 | + /** |
| 110 | + * Test to Save custom Currency symbol |
| 111 | + */ |
98 | 112 | public function testExecute()
|
99 | 113 | {
|
100 | 114 | $firstElement = 'firstElement';
|
101 | 115 | $symbolsDataArray = [$firstElement];
|
102 |
| - $redirectUrl = 'redirectUrl'; |
103 | 116 |
|
104 | 117 | $this->requestMock->expects($this->once())
|
105 | 118 | ->method('getParam')
|
106 | 119 | ->with('custom_currency_symbol')
|
107 | 120 | ->willReturn($symbolsDataArray);
|
108 | 121 |
|
109 |
| - $this->helperMock->expects($this->once())->method('getUrl')->with('*'); |
110 |
| - $this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl); |
111 |
| - |
112 |
| - $this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray); |
113 |
| - $this->responseMock->expects($this->once())->method('setRedirect'); |
114 |
| - |
115 |
| - $this->filterManagerMock->expects($this->once()) |
| 122 | + $currencySymbol = $this->createMock(Currencysymbol::class); |
| 123 | + $currencySymbol->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray); |
| 124 | + $this->currencySymbolFactory->method('create')->willReturn($currencySymbol); |
| 125 | + $this->filterManager->expects($this->once()) |
116 | 126 | ->method('stripTags')
|
117 | 127 | ->with($firstElement)
|
118 | 128 | ->willReturn($firstElement);
|
119 | 129 |
|
120 |
| - $this->objectManagerMock->expects($this->once()) |
121 |
| - ->method('create') |
122 |
| - ->with(\Magento\CurrencySymbol\Model\System\Currencysymbol::class) |
123 |
| - ->willReturn($this->currencySymbolMock); |
124 |
| - |
125 |
| - $this->objectManagerMock->expects($this->once()) |
126 |
| - ->method('get') |
127 |
| - ->with(\Magento\Framework\Filter\FilterManager::class) |
128 |
| - ->willReturn($this->filterManagerMock); |
129 |
| - |
130 | 130 | $this->messageManagerMock->expects($this->once())
|
131 | 131 | ->method('addSuccessMessage')
|
132 | 132 | ->with(__('You applied the custom currency symbols.'));
|
133 | 133 |
|
134 |
| - $this->action->execute(); |
| 134 | + $redirect = $this->createMock(Redirect::class); |
| 135 | + $redirect->expects($this->once())->method('setPath')->with('*')->willReturnSelf(); |
| 136 | + $this->resultRedirectFactory->method('create')->willReturn($redirect); |
| 137 | + |
| 138 | + $this->assertEquals($redirect, $this->action->execute()); |
135 | 139 | }
|
136 | 140 | }
|
0 commit comments