|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Backend\Test\Unit\Helper\Dashboard; |
| 10 | + |
| 11 | +use Magento\Backend\Helper\Dashboard\Data as HelperData; |
| 12 | +use Magento\Framework\App\DeploymentConfig; |
| 13 | +use Magento\Framework\Config\ConfigOptionsListConstants; |
| 14 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 15 | +use Magento\Store\Model\ResourceModel\Store\Collection as StoreCollection; |
| 16 | +use Magento\Store\Model\Store; |
| 17 | +use Magento\Store\Model\StoreManagerInterface; |
| 18 | +use PHPUnit\Framework\MockObject\MockObject; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +class DataTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * Stub path install |
| 25 | + */ |
| 26 | + private const STUB_PATH_INSTALL = 'Sat, 6 Sep 2014 16:46:11 UTC'; |
| 27 | + |
| 28 | + /** |
| 29 | + * Stub chart data hash |
| 30 | + */ |
| 31 | + private const STUB_CHART_DATA_HASH = '52870842b23068a78220e01eb9d4404d'; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \Magento\Backend\Helper\Dashboard\Data |
| 35 | + */ |
| 36 | + private $helper; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var StoreManagerInterface|MockObject |
| 40 | + */ |
| 41 | + private $storeManagerMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var DeploymentConfig|MockObject |
| 45 | + */ |
| 46 | + private $deploymentConfigMock; |
| 47 | + |
| 48 | + /** |
| 49 | + * Prepare environment for test |
| 50 | + */ |
| 51 | + protected function setUp() |
| 52 | + { |
| 53 | + $this->storeManagerMock = $this->createMock(StoreManagerInterface::class); |
| 54 | + $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class); |
| 55 | + $this->deploymentConfigMock->expects($this->once())->method('get') |
| 56 | + ->with(ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE) |
| 57 | + ->will($this->returnValue(self::STUB_PATH_INSTALL)); |
| 58 | + |
| 59 | + $objectManager = new ObjectManager($this); |
| 60 | + $this->helper = $objectManager->getObject( |
| 61 | + HelperData::class, |
| 62 | + [ |
| 63 | + 'storeManager' => $this->storeManagerMock, |
| 64 | + 'deploymentConfig' => $this->deploymentConfigMock |
| 65 | + ] |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Test getStores() when $_stores attribute is null |
| 71 | + */ |
| 72 | + public function testGetStoresWhenStoreAttributeIsNull() |
| 73 | + { |
| 74 | + $storeMock = $this->createPartialMock(Store::class, ['getResourceCollection']); |
| 75 | + $storeCollectionMock = $this->createMock(StoreCollection::class); |
| 76 | + |
| 77 | + $storeCollectionMock->expects($this->once())->method('load')->willReturnSelf(); |
| 78 | + $storeMock->expects($this->once())->method('getResourceCollection')->willReturn($storeCollectionMock); |
| 79 | + $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); |
| 80 | + |
| 81 | + $this->assertEquals($storeCollectionMock, $this->helper->getStores()); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Test getDatePeriods() method |
| 86 | + */ |
| 87 | + public function testGetDatePeriods() |
| 88 | + { |
| 89 | + $this->assertEquals( |
| 90 | + [ |
| 91 | + '24h' => (string)__('Last 24 Hours'), |
| 92 | + '7d' => (string)__('Last 7 Days'), |
| 93 | + '1m' => (string)__('Current Month'), |
| 94 | + '1y' => (string)__('YTD'), |
| 95 | + '2y' => (string)__('2YTD') |
| 96 | + ], |
| 97 | + $this->helper->getDatePeriods() |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Test getChartDataHash() method |
| 103 | + */ |
| 104 | + public function testGetChartDataHash() |
| 105 | + { |
| 106 | + $this->assertEquals( |
| 107 | + self::STUB_CHART_DATA_HASH, |
| 108 | + $this->helper->getChartDataHash(self::STUB_PATH_INSTALL) |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
0 commit comments