Skip to content

Commit a0b4e0a

Browse files
committed
Merge remote-tracking branch '38886/patch-11' into novcommpr-3
2 parents 0b9e5a6 + bcb6d69 commit a0b4e0a

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

app/code/Magento/Csp/Model/Mode/ConfigManager.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2019 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,7 +11,7 @@
1111
use Magento\Framework\App\ObjectManager;
1212
use Magento\Csp\Api\Data\ModeConfiguredInterface;
1313
use Magento\Csp\Api\ModeConfigManagerInterface;
14-
use Magento\Csp\Model\Mode\Data\ModeConfigured;
14+
use Magento\Csp\Model\Mode\Data\ModeConfiguredFactory;
1515
use Magento\Framework\App\Area;
1616
use Magento\Framework\App\Config\ScopeConfigInterface;
1717
use Magento\Framework\App\State;
@@ -43,24 +43,33 @@ class ConfigManager implements ModeConfigManagerInterface
4343
*/
4444
private Http $request;
4545

46+
/**
47+
* @var ModeConfiguredFactory
48+
*/
49+
private $modeConfiguredFactory;
50+
4651
/**
4752
* @param ScopeConfigInterface $config
4853
* @param Store $store
4954
* @param State $state
5055
* @param Http|null $request
56+
* @param ModeConfiguredFactory|null $modeConfiguredFactory
5157
*/
5258
public function __construct(
5359
ScopeConfigInterface $config,
5460
Store $store,
5561
State $state,
56-
?Http $request = null
62+
?Http $request = null,
63+
?ModeConfiguredFactory $modeConfiguredFactory = null
5764
) {
5865
$this->config = $config;
5966
$this->storeModel = $store;
6067
$this->state = $state;
6168

6269
$this->request = $request
6370
?? ObjectManager::getInstance()->get(Http::class);
71+
$this->modeConfiguredFactory = $modeConfiguredFactory
72+
?? ObjectManager::getInstance()->get(ModeConfiguredFactory::class);
6473
}
6574

6675
/**
@@ -118,9 +127,9 @@ public function getConfigured(): ModeConfiguredInterface
118127
);
119128
}
120129

121-
return new ModeConfigured(
122-
(bool) $reportOnly,
123-
!empty($reportUri) ? $reportUri : null
124-
);
130+
return $this->modeConfiguredFactory->create([
131+
'reportOnly' => (bool) $reportOnly,
132+
'reportUri' => !empty($reportUri) ? (string)$reportUri : null
133+
]);
125134
}
126135
}

app/code/Magento/Csp/Test/Unit/Model/Mode/ConfigManagerTest.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Csp\Test\Unit\Model\Mode;
109

10+
use Magento\Csp\Api\Data\ModeConfiguredInterface;
1111
use Magento\Csp\Model\Mode\ConfigManager;
12-
use Magento\Csp\Model\Mode\Data\ModeConfigured;
12+
use Magento\Csp\Model\Mode\Data\ModeConfiguredFactory;
1313
use Magento\Framework\App\Area;
1414
use Magento\Framework\App\Config\ScopeConfigInterface;
1515
use Magento\Framework\App\Request\Http;
@@ -51,6 +51,16 @@ class ConfigManagerTest extends TestCase
5151
*/
5252
private $requestMock;
5353

54+
/**
55+
* @var ModeConfiguredFactory
56+
*/
57+
private $modeConfiguredFactoryMock;
58+
59+
/**
60+
* @var ModeConfiguredInterface
61+
*/
62+
private $modeConfiguredInterfaceMock;
63+
5464
/**
5565
* Set Up
5666
*/
@@ -62,6 +72,8 @@ protected function setUp(): void
6272
$this->storeMock = $this->createMock(Store::class);
6373
$this->stateMock = $this->createMock(State::class);
6474
$this->requestMock = $this->createMock(Http::class);
75+
$this->modeConfiguredFactoryMock = $this->createPartialMock(ModeConfiguredFactory::class, ['create']);
76+
$this->modeConfiguredInterfaceMock = $this->createMock(ModeConfiguredInterface::class);
6577

6678
$this->model = $objectManager->getObject(
6779
ConfigManager::class,
@@ -70,6 +82,7 @@ protected function setUp(): void
7082
'storeModel' => $this->storeMock,
7183
'state' => $this->stateMock,
7284
'request' => $this->requestMock,
85+
'modeConfiguredFactory' => $this->modeConfiguredFactoryMock
7386
]
7487
);
7588
}
@@ -107,9 +120,14 @@ public function testConfiguredCSPForAdminArea()
107120
$this->scopeConfigMock->expects($this->any())
108121
->method('getValue')
109122
->willReturn('testReportUri');
123+
$this->modeConfiguredFactoryMock->expects($this->once())
124+
->method('create')
125+
->with(['reportOnly' => true, 'reportUri' => 'testReportUri'])
126+
->willReturn($this->modeConfiguredInterfaceMock);
127+
110128
$result = $this->model->getConfigured();
111129

112-
$this->assertInstanceOf(ModeConfigured::class, $result);
130+
$this->assertInstanceOf(ModeConfiguredInterface::class, $result);
113131
}
114132

115133
/**
@@ -139,11 +157,14 @@ public function testCheckoutPageReportOnly(): void
139157
})
140158
->willReturnOnConsecutiveCalls(true, 'testReportUri');
141159

160+
$this->modeConfiguredFactoryMock->expects($this->once())
161+
->method('create')
162+
->with(['reportOnly' => true, 'reportUri' => 'testReportUri'])
163+
->willReturn($this->modeConfiguredInterfaceMock);
164+
142165
$result = $this->model->getConfigured();
143166

144-
$this->assertInstanceOf(ModeConfigured::class, $result);
145-
$this->assertTrue($result->isReportOnly());
146-
$this->assertEquals($result->getReportUri(), 'testReportUri');
167+
$this->assertInstanceOf(ModeConfiguredInterface::class, $result);
147168
}
148169

149170
/**
@@ -174,10 +195,13 @@ public function testNonCheckoutPageReportOnly(): void
174195
})
175196
->willReturnOnConsecutiveCalls(null, true, null, 'testPageReportUri');
176197

198+
$this->modeConfiguredFactoryMock->expects($this->once())
199+
->method('create')
200+
->with(['reportOnly' => true, 'reportUri' => 'testPageReportUri'])
201+
->willReturn($this->modeConfiguredInterfaceMock);
202+
177203
$result = $this->model->getConfigured();
178204

179-
$this->assertInstanceOf(ModeConfigured::class, $result);
180-
$this->assertTrue($result->isReportOnly());
181-
$this->assertEquals($result->getReportUri(), 'testPageReportUri');
205+
$this->assertInstanceOf(ModeConfiguredInterface::class, $result);
182206
}
183207
}

0 commit comments

Comments
 (0)