Skip to content

Commit b1ec397

Browse files
committed
Merge remote-tracking branch 'origin/MC-35998' into 2.4-develop-pr36
2 parents 237c2b1 + ddf3f68 commit b1ec397

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

lib/internal/Magento/Framework/App/StaticResource.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,28 @@ public function launch()
124124
)
125125
) {
126126
$this->response->setHttpResponseCode(404);
127-
} else {
128-
$path = $this->request->get('resource');
127+
return $this->response;
128+
}
129+
130+
$path = $this->request->get('resource');
131+
try {
129132
$params = $this->parsePath($path);
130-
$this->state->setAreaCode($params['area']);
131-
$this->objectManager->configure($this->configLoader->load($params['area']));
132-
$file = $params['file'];
133-
unset($params['file']);
134-
$asset = $this->assetRepo->createAsset($file, $params);
135-
$this->response->setFilePath($asset->getSourceFile());
136-
$this->publisher->publish($asset);
133+
} catch (\InvalidArgumentException $e) {
134+
if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
135+
$this->response->setHttpResponseCode(404);
136+
return $this->response;
137+
}
138+
throw $e;
137139
}
140+
141+
$this->state->setAreaCode($params['area']);
142+
$this->objectManager->configure($this->configLoader->load($params['area']));
143+
$file = $params['file'];
144+
unset($params['file']);
145+
$asset = $this->assetRepo->createAsset($file, $params);
146+
$this->response->setFilePath($asset->getSourceFile());
147+
$this->publisher->publish($asset);
148+
138149
return $this->response;
139150
}
140151

lib/internal/Magento/Framework/App/Test/Unit/StaticResourceTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class StaticResourceTest extends TestCase
8484
*/
8585
private $object;
8686

87+
/**
88+
* @inheridoc
89+
*/
8790
protected function setUp(): void
8891
{
8992
$this->stateMock = $this->createMock(State::class);
@@ -109,6 +112,9 @@ protected function setUp(): void
109112
);
110113
}
111114

115+
/**
116+
* Test to lunch on production mode
117+
*/
112118
public function testLaunchProductionMode()
113119
{
114120
$this->stateMock->expects($this->once())
@@ -249,6 +255,9 @@ public function launchDataProvider()
249255
];
250256
}
251257

258+
/**
259+
* Test to lunch with wrong path on developer mode
260+
*/
252261
public function testLaunchWrongPath()
253262
{
254263
$this->expectException('InvalidArgumentException');
@@ -263,6 +272,28 @@ public function testLaunchWrongPath()
263272
$this->object->launch();
264273
}
265274

275+
/**
276+
* Test to lunch with wrong path on production mode
277+
*/
278+
public function testLaunchWrongPathProductionMode()
279+
{
280+
$mode = State::MODE_PRODUCTION;
281+
$path = 'wrong/path.js';
282+
283+
$this->stateMock->method('getMode')->willReturn($mode);
284+
$this->deploymentConfigMock->method('getConfigData')
285+
->with(ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
286+
->willReturn(true);
287+
$this->requestMock->method('get')->with('resource')->willReturn($path);
288+
$this->responseMock->expects($this->once())
289+
->method('setHttpResponseCode')
290+
->with(404);
291+
$this->object->launch();
292+
}
293+
294+
/**
295+
* Test to Ability to handle exceptions on developer mode
296+
*/
266297
public function testCatchExceptionDeveloperMode()
267298
{
268299
$this->objectManagerMock->expects($this->once())
@@ -286,6 +317,9 @@ public function testCatchExceptionDeveloperMode()
286317
$this->assertTrue($this->object->catchException($bootstrap, $exception));
287318
}
288319

320+
/**
321+
* Test to lunch with wrong path
322+
*/
289323
public function testLaunchPathAbove()
290324
{
291325
$this->expectException('InvalidArgumentException');

0 commit comments

Comments
 (0)