Skip to content

Commit 26a83d5

Browse files
committed
#12147: The function "isUsingStaticUrlsAllowed" (configuration setting "cms/wysiwyg/use_static_urls_in_catalog") doesn't have any effect with the WYSIWYG editor image insertion
1 parent 5bd0104 commit 26a83d5

File tree

2 files changed

+105
-1
lines changed

2 files changed

+105
-1
lines changed

app/code/Magento/Catalog/Observer/CatalogCheckIsUsingStaticUrlsAllowedObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(\Magento\Catalog\Helper\Data $catalogData)
3232
*/
3333
public function execute(\Magento\Framework\Event\Observer $observer)
3434
{
35-
$storeId = $observer->getEvent()->getData('store_id');
35+
$storeId = (int)$observer->getEvent()->getData('store_id');
3636
$result = $observer->getEvent()->getData('result');
3737
$result->isAllowed = $this->catalogData->setStoreId($storeId)->isUsingStaticUrlsAllowed();
3838
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Observer;
8+
9+
use Magento\Catalog\Helper\Data;
10+
use Magento\Catalog\Observer\CatalogCheckIsUsingStaticUrlsAllowedObserver;
11+
use Magento\Framework\Event;
12+
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Provide tests for CatalogCheckIsUsingStaticUrlsAllowedObserver observer.
18+
*/
19+
class CatalogCheckIsUsingStaticUrlsAllowedObserverTest extends TestCase
20+
{
21+
/**
22+
* Test subject.
23+
*
24+
* @var CatalogCheckIsUsingStaticUrlsAllowedObserver
25+
*/
26+
private $model;
27+
28+
/**
29+
* @var Data|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $catalogData;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
$objectManager = new ObjectManager($this);
39+
$this->catalogData = $this->getMockBuilder(Data::class)
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$this->model = $objectManager->getObject(
43+
CatalogCheckIsUsingStaticUrlsAllowedObserver::class,
44+
['catalogData' => $this->catalogData]
45+
);
46+
}
47+
48+
/**
49+
* Test observer can correctly handle non integer store id values.
50+
*
51+
* @dataProvider executeDataProvider
52+
* @param string|int $storeId
53+
* @return void
54+
*/
55+
public function testExecute($storeId)
56+
{
57+
$result = new \stdClass();
58+
/** @var Observer|\PHPUnit_Framework_MockObject_MockObject $observer */
59+
$observer = $this->getMockBuilder(Observer::class)
60+
->disableOriginalConstructor()
61+
->getMock();
62+
$event = $this->getMockBuilder(Event::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$event->expects($this->exactly(2))
66+
->method('getData')
67+
->withConsecutive(
68+
$this->identicalTo('store_id'),
69+
$this->identicalTo('result')
70+
)->willReturnOnConsecutiveCalls(
71+
$storeId,
72+
$result
73+
);
74+
$observer->expects($this->exactly(2))
75+
->method('getEvent')
76+
->willReturn($event);
77+
$this->catalogData->expects($this->once())
78+
->method('setStoreId')
79+
->with(0)
80+
->willReturnSelf();
81+
$this->catalogData->expects($this->once())
82+
->method('isUsingStaticUrlsAllowed')
83+
->willReturn(true);
84+
$this->model->execute($observer);
85+
$this->assertTrue($result->isAllowed);
86+
}
87+
88+
/**
89+
* Provide test data for testExecute().
90+
*
91+
* @return array
92+
*/
93+
public function executeDataProvider()
94+
{
95+
return [
96+
[
97+
'store_id' => 0,
98+
],
99+
[
100+
'store_id' => ''
101+
]
102+
];
103+
}
104+
}

0 commit comments

Comments
 (0)