|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Reports\Test\Unit\Block\Adminhtml\Grid; |
| 8 | + |
| 9 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test for class \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid. |
| 13 | + */ |
| 14 | +class AbstractGridTest extends \PHPUnit\Framework\TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid|\PHPUnit_Framework_MockObject_MockObject |
| 18 | + */ |
| 19 | + private $model; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + private $storeManagerMock; |
| 25 | + |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $objectManager = new ObjectManager($this); |
| 29 | + |
| 30 | + $this->storeManagerMock = $this->getMockForAbstractClass( |
| 31 | + \Magento\Store\Model\StoreManagerInterface::class, |
| 32 | + [], |
| 33 | + '', |
| 34 | + true, |
| 35 | + true, |
| 36 | + true, |
| 37 | + ['getStore'] |
| 38 | + ); |
| 39 | + |
| 40 | + $this->model = $objectManager->getObject( |
| 41 | + \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid::class, |
| 42 | + ['_storeManager' => $this->storeManagerMock] |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @param $storeIds |
| 48 | + * |
| 49 | + * @dataProvider getCurrentCurrencyCodeDataProvider |
| 50 | + */ |
| 51 | + public function testGetCurrentCurrencyCode($storeIds) |
| 52 | + { |
| 53 | + $storeMock = $this->getMockForAbstractClass( |
| 54 | + \Magento\Store\Api\Data\StoreInterface::class, |
| 55 | + [], |
| 56 | + '', |
| 57 | + true, |
| 58 | + true, |
| 59 | + true, |
| 60 | + ['getBaseCurrencyCode', 'getCurrentCurrencyCode'] |
| 61 | + ); |
| 62 | + |
| 63 | + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); |
| 64 | + |
| 65 | + $this->model->setStoreIds($storeIds); |
| 66 | + |
| 67 | + if ($storeIds) { |
| 68 | + $storeMock->expects($this->once())->method('getCurrentCurrencyCode')->willReturn('EUR'); |
| 69 | + $expectedCurrencyCode = 'EUR'; |
| 70 | + } else { |
| 71 | + $storeMock->expects($this->once())->method('getBaseCurrencyCode')->willReturn('USD'); |
| 72 | + $expectedCurrencyCode = 'USD'; |
| 73 | + } |
| 74 | + |
| 75 | + $currencyCode = $this->model->getCurrentCurrencyCode(); |
| 76 | + $this->assertEquals($expectedCurrencyCode, $currencyCode); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * DataProvider for testGetCurrentCurrencyCode. |
| 81 | + * |
| 82 | + * @return array |
| 83 | + */ |
| 84 | + public function getCurrentCurrencyCodeDataProvider() |
| 85 | + { |
| 86 | + return [ |
| 87 | + [[]], |
| 88 | + [[2]], |
| 89 | + ]; |
| 90 | + } |
| 91 | +} |
0 commit comments