Skip to content

Commit 11b032f

Browse files
committed
Merge remote-tracking branch '36008/fix-for-issue-#35952' into comm_247beta3
2 parents 536df3b + ba73b71 commit 11b032f

File tree

4 files changed

+290
-3
lines changed

4 files changed

+290
-3
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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+
}

app/code/Magento/Sales/ViewModel/Header/LogoPathResolver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ public function getPath(): ?string
5454
if ($order instanceof Order) {
5555
$storeId = $order->getStoreId();
5656
}
57+
$scopeType = ScopeInterface::SCOPE_STORE;
58+
if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
59+
$scopeType = ScopeInterface::SCOPE_WEBSITE;
60+
}
5761
$salesLogoPath = $this->scopeConfig->getValue(
5862
'sales/identity/logo_html',
59-
ScopeInterface::SCOPE_STORE,
63+
$scopeType,
6064
$storeId
6165
);
6266

@@ -66,7 +70,7 @@ public function getPath(): ?string
6670

6771
$headerLogoPath = $this->scopeConfig->getValue(
6872
'design/header/logo_src',
69-
ScopeInterface::SCOPE_STORE,
73+
$scopeType,
7074
$storeId
7175
);
7276

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\Theme\Test\Unit\ViewModel\Block\Html\Header;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Theme\ViewModel\Block\Html\Header\LogoPathResolver;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test logo path resolver view model
18+
*/
19+
class LogoPathResolverTest extends TestCase
20+
{
21+
/**
22+
* @var ScopeConfigInterface|MockObject
23+
*/
24+
private $scopeConfig;
25+
26+
/**
27+
* @var LogoPathResolver
28+
*/
29+
private $model;
30+
31+
/**
32+
* Test for case when app in single store mode
33+
* and logo path is defined in config
34+
* @return void
35+
*/
36+
public function testGetPathWhenInSingleStoreModeAndPathNotNull(): void
37+
{
38+
$this->scopeConfig->method('getValue')
39+
->withConsecutive(
40+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
41+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, null]
42+
)
43+
->willReturn('1', 'SingleStore.png');
44+
$valueForAssert = $this->model->getPath();
45+
$this->assertEquals('logo/SingleStore.png', $valueForAssert);
46+
$this->assertNotNull($valueForAssert);
47+
}
48+
49+
/**
50+
* Test for case when app in single store mode
51+
* and logo path is not defined in config
52+
* @return void
53+
*/
54+
public function testGetPathWhenInSingleStoreModeAndPathIsNull(): void
55+
{
56+
$this->scopeConfig->method('getValue')
57+
->withConsecutive(
58+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
59+
['design/header/logo_src', ScopeInterface::SCOPE_WEBSITE, null]
60+
)
61+
->willReturn('1', null);
62+
$this->assertNull($this->model->getPath());
63+
}
64+
65+
/**
66+
* Test for case when app in multi store mode
67+
* and logo path is defined in config
68+
* @return void
69+
*/
70+
public function testGetPathWhenInMultiStoreModeAndPathNotNull(): void
71+
{
72+
$this->scopeConfig->method('getValue')
73+
->withConsecutive(
74+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
75+
['design/header/logo_src', ScopeInterface::SCOPE_STORE, null]
76+
)
77+
->willReturn('0', 'MultiStore.png');
78+
$valueForAssert = $this->model->getPath();
79+
$this->assertEquals('logo/MultiStore.png', $valueForAssert);
80+
$this->assertNotNull($valueForAssert);
81+
}
82+
83+
/**
84+
* Test for case when app in multi store mode
85+
* and logo path is not defined in config
86+
* @return void
87+
*/
88+
public function testGetPathWhenInMultiStoreModeAndPathIsNull(): void
89+
{
90+
$this->scopeConfig->method('getValue')
91+
->withConsecutive(
92+
['general/single_store_mode/enabled', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
93+
['design/header/logo_src', ScopeInterface::SCOPE_STORE, null]
94+
)
95+
->willReturn('0', null);
96+
$this->assertNull($this->model->getPath());
97+
}
98+
99+
/**
100+
* @inheritdoc
101+
*/
102+
protected function setUp(): void
103+
{
104+
parent::setUp();
105+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
106+
$this->model = new LogoPathResolver($this->scopeConfig);
107+
}
108+
}

app/code/Magento/Theme/ViewModel/Block/Html/Header/LogoPathResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ public function __construct(
3939
public function getPath(): ?string
4040
{
4141
$path = null;
42+
$scopeType = ScopeInterface::SCOPE_STORE;
43+
if ($this->scopeConfig->getValue('general/single_store_mode/enabled') === "1") {
44+
$scopeType = ScopeInterface::SCOPE_WEBSITE;
45+
}
4246
$storeLogoPath = $this->scopeConfig->getValue(
4347
'design/header/logo_src',
44-
ScopeInterface::SCOPE_STORE
48+
$scopeType
4549
);
4650
if ($storeLogoPath !== null) {
4751
$path = Logo::UPLOAD_DIR . '/' . $storeLogoPath;

0 commit comments

Comments
 (0)