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