|
| 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\Sales\Test\Unit\ViewModel\Header; |
| 9 | + |
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Framework\Registry; |
| 12 | +use Magento\Sales\Model\Order; |
| 13 | +use Magento\Sales\ViewModel\Header\LogoPathResolver; |
| 14 | +use Magento\Store\Model\ScopeInterface; |
| 15 | +use PHPUnit\Framework\MockObject\MockObject; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +/** |
| 19 | + * Test logo path resolver view model |
| 20 | + */ |
| 21 | +class LogoPathResolverTest extends TestCase |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var ScopeConfigInterface|MockObject |
| 25 | + */ |
| 26 | + private $scopeConfig; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var LogoPathResolver |
| 30 | + */ |
| 31 | + private $model; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var Registry|MockObject |
| 35 | + */ |
| 36 | + private $registry; |
| 37 | + |
| 38 | + /** |
| 39 | + * Test for case when app in single store mode |
| 40 | + * and logo path is defined in config |
| 41 | + * @return void |
| 42 | + */ |
| 43 | + public function testGetPathWhenInSingleStoreModeAndSalesLogoPathNotNull(): void |
| 44 | + { |
| 45 | + $this->scopeConfig->method('getValue') |
| 46 | + ->withConsecutive( |
| 47 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 48 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1] |
| 49 | + ) |
| 50 | + ->willReturn( |
| 51 | + "1", |
| 52 | + 'sales_identity_logo_html_value' |
| 53 | + ); |
| 54 | + $valueForAssert = $this->model->getPath(); |
| 55 | + $this->assertEquals('sales/store/logo_html/sales_identity_logo_html_value', $valueForAssert); |
| 56 | + $this->assertNotNull($valueForAssert); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Test for case when app in single store mode |
| 61 | + * and logo path is not defined in config |
| 62 | + * and header logo path is defined in config |
| 63 | + * @return void |
| 64 | + */ |
| 65 | + public function testGetPathWhenInSingleStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNotNull(): void |
| 66 | + { |
| 67 | + $this->scopeConfig->method('getValue') |
| 68 | + ->withConsecutive( |
| 69 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 70 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1], |
| 71 | + ['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1] |
| 72 | + ) |
| 73 | + ->willReturn('1', null, 'SingleStore.png'); |
| 74 | + $valueForAssert = $this->model->getPath(); |
| 75 | + $this->assertEquals('logo/SingleStore.png', $valueForAssert); |
| 76 | + $this->assertNotNull($valueForAssert); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Test for case when app in single store mode |
| 81 | + * and logo path is not defined in config |
| 82 | + * and header logo path is not defined in config |
| 83 | + * @return void |
| 84 | + */ |
| 85 | + public function testGetPathWhenInSingleStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNull(): void |
| 86 | + { |
| 87 | + $this->scopeConfig->method('getValue') |
| 88 | + ->withConsecutive( |
| 89 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 90 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1], |
| 91 | + ['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1] |
| 92 | + ) |
| 93 | + ->willReturn('1', null, null); |
| 94 | + $valueForAssert = $this->model->getPath(); |
| 95 | + $this->assertNull($valueForAssert); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Test for case when app in multi store mode |
| 100 | + * and logo path is defined in config |
| 101 | + * @return void |
| 102 | + */ |
| 103 | + public function testGetPathWhenInMultiStoreModeAndPathNotNull(): void |
| 104 | + { |
| 105 | + $this->scopeConfig->method('getValue') |
| 106 | + ->withConsecutive( |
| 107 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 108 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_STORE, 1] |
| 109 | + ) |
| 110 | + ->willReturn('0', 'sales_identity_logo_html_value'); |
| 111 | + $valueForAssert = $this->model->getPath(); |
| 112 | + $this->assertEquals('sales/store/logo_html/sales_identity_logo_html_value', $valueForAssert); |
| 113 | + $this->assertNotNull($valueForAssert); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Test for case when app in single store mode |
| 118 | + * and logo path is not defined in config |
| 119 | + * and header logo path is not defined in config |
| 120 | + * @return void |
| 121 | + */ |
| 122 | + public function testGetPathWhenInMultiStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNull(): void |
| 123 | + { |
| 124 | + $this->scopeConfig->method('getValue') |
| 125 | + ->withConsecutive( |
| 126 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 127 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_STORE, 1], |
| 128 | + ['design/header/logo_src', ScopeInterface::SCOPE_STORE, 1] |
| 129 | + ) |
| 130 | + ->willReturn('0', null, null); |
| 131 | + $valueForAssert = $this->model->getPath(); |
| 132 | + $this->assertNull($valueForAssert); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Test for case when app in single store mode |
| 137 | + * and logo path is not defined in config |
| 138 | + * and header logo path is defined in config |
| 139 | + * @return void |
| 140 | + */ |
| 141 | + public function testGetPathWhenInMultiStoreModeAndSalesLogoPathIsNullAndHeaderLogoPathIsNotNull(): void |
| 142 | + { |
| 143 | + $this->scopeConfig->method('getValue') |
| 144 | + ->withConsecutive( |
| 145 | + ['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null], |
| 146 | + ['sales/identity/logo_html', ScopeInterface::SCOPE_WEBSITE, 1], |
| 147 | + ['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, 1] |
| 148 | + ) |
| 149 | + ->willReturn('1', null, 'MultiStore.png'); |
| 150 | + $valueForAssert = $this->model->getPath(); |
| 151 | + $this->assertEquals('logo/MultiStore.png', $valueForAssert); |
| 152 | + $this->assertNotNull($valueForAssert); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * @inheritdoc |
| 157 | + */ |
| 158 | + protected function setUp(): void |
| 159 | + { |
| 160 | + parent::setUp(); |
| 161 | + $this->scopeConfig = $this->createMock(ScopeConfigInterface::class); |
| 162 | + $this->registry = $this->createMock(Registry::class); |
| 163 | + $orderMock = $this->createMock(Order::class); |
| 164 | + $orderMock->method('getStoreId') |
| 165 | + ->willReturn(1); |
| 166 | + $this->registry->method('registry') |
| 167 | + ->with('current_order') |
| 168 | + ->willReturn($orderMock); |
| 169 | + $this->model = new LogoPathResolver($this->scopeConfig, $this->registry); |
| 170 | + } |
| 171 | +} |
0 commit comments