Skip to content

Commit 53a52ec

Browse files
committed
Merge pull request #365 from magento-tango/MAGETWO-48529
[Tango] Bug fixes
2 parents ab3be84 + c45e492 commit 53a52ec

File tree

7 files changed

+188
-14
lines changed

7 files changed

+188
-14
lines changed

app/code/Magento/Cms/Model/Wysiwyg/Config.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Cms\Model\Wysiwyg;
77

8+
use Magento\Framework\Filesystem;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
810
use Magento\Ui\Component\Wysiwyg\ConfigInterface;
911

1012
/**
@@ -91,6 +93,11 @@ class Config extends \Magento\Framework\DataObject implements ConfigInterface
9193
*/
9294
protected $_storeManager;
9395

96+
/**
97+
* @var Filesystem
98+
*/
99+
protected $filesystem;
100+
94101
/**
95102
* @param \Magento\Backend\Model\UrlInterface $backendUrl
96103
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -100,6 +107,7 @@ class Config extends \Magento\Framework\DataObject implements ConfigInterface
100107
* @param \Magento\Widget\Model\Widget\Config $widgetConfig
101108
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
102109
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
110+
* @param Filesystem $filesystem
103111
* @param array $windowSize
104112
* @param array $data
105113
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -113,6 +121,7 @@ public function __construct(
113121
\Magento\Widget\Model\Widget\Config $widgetConfig,
114122
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
115123
\Magento\Store\Model\StoreManagerInterface $storeManager,
124+
Filesystem $filesystem,
116125
array $windowSize = [],
117126
array $data = []
118127
) {
@@ -125,6 +134,7 @@ public function __construct(
125134
$this->_widgetConfig = $widgetConfig;
126135
$this->_windowSize = $windowSize;
127136
$this->_storeManager = $storeManager;
137+
$this->filesystem = $filesystem;
128138
parent::__construct($data);
129139
}
130140

@@ -157,6 +167,9 @@ public function getConfig($data = [])
157167
'add_widgets' => true,
158168
'no_display' => false,
159169
'encode_directives' => true,
170+
'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(),
171+
'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl())
172+
. $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/',
160173
'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'),
161174
'popup_css' => $this->_assetRepo->getUrl(
162175
'mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/ConfigTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/**
99
* @covers \Magento\Cms\Model\Wysiwyg\Config
10+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1011
*/
1112
class ConfigTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -60,13 +61,19 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
6061
*/
6162
protected $assetFileMock;
6263

64+
/**
65+
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
protected $filesystemMock;
68+
6369
/**
6470
* @var array
6571
*/
6672
protected $windowSize = [];
6773

6874
protected function setUp()
6975
{
76+
$this->filesystemMock = $this->getMock(\Magento\Framework\Filesystem::class, [], [], '', false);
7077
$this->backendUrlMock = $this->getMockBuilder('Magento\Backend\Model\UrlInterface')
7178
->disableOriginalConstructor()
7279
->getMock();
@@ -110,7 +117,8 @@ protected function setUp()
110117
'widgetConfig' => $this->widgetConfigMock,
111118
'scopeConfig' => $this->scopeConfigMock,
112119
'windowSize' => $this->windowSize,
113-
'storeManager' => $this->storeManagerMock
120+
'storeManager' => $this->storeManagerMock,
121+
'filesystem' => $this->filesystemMock,
114122
]
115123
);
116124
}
@@ -139,12 +147,26 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
139147
['cms/wysiwyg/directive'],
140148
['cms/wysiwyg_images/index']
141149
);
150+
$this->backendUrlMock->expects($this->once())
151+
->method('getBaseUrl')
152+
->willReturn('localhost/index.php/');
142153
$this->assetRepoMock->expects($this->atLeastOnce())
143154
->method('getUrl')
144155
->withConsecutive(
145156
['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'],
146157
['mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css']
147158
);
159+
$this->filesystemMock->expects($this->once())
160+
->method('getUri')
161+
->willReturn('pub/static');
162+
/** @var \Magento\Framework\View\Asset\ContextInterface|\PHPUnit_Framework_MockObject_MockObject $contextMock */
163+
$contextMock = $this->getMock(\Magento\Framework\View\Asset\ContextInterface::class);
164+
$contextMock->expects($this->once())
165+
->method('getBaseUrl')
166+
->willReturn('localhost/pub/static/');
167+
$this->assetRepoMock->expects($this->once())
168+
->method('getStaticViewFileContext')
169+
->willReturn($contextMock);
148170
$this->authorizationMock->expects($this->atLeastOnce())
149171
->method('isAllowed')
150172
->with('Magento_Cms::media_gallery')
@@ -161,6 +183,8 @@ public function testGetConfig($data, $isAuthorizationAllowed, $expectedResults)
161183
$this->assertEquals($expectedResults[0], $config->getData('someData'));
162184
$this->assertEquals($expectedResults[1], $config->getData('wysiwygPluginSettings'));
163185
$this->assertEquals($expectedResults[2], $config->getData('pluginSettings'));
186+
$this->assertEquals('localhost/pub/static/', $config->getData('baseStaticUrl'));
187+
$this->assertEquals('localhost/pub/static/', $config->getData('baseStaticDefaultUrl'));
164188
}
165189

166190
public function getConfigDataProvider()
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Config\Test\Unit;
7+
8+
class ViewFactoryTest extends \PHPUnit_Framework_TestCase
9+
{
10+
const AREA = 'frontend';
11+
12+
/**
13+
* @var \Magento\Framework\Config\ViewFactory
14+
*/
15+
protected $model;
16+
17+
/**
18+
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
protected $objectManager;
21+
22+
/**
23+
* @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $theme;
26+
27+
/**
28+
* @var \Magento\Framework\Config\View|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
protected $view;
31+
32+
protected function setUp()
33+
{
34+
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
35+
$this->model = new \Magento\Framework\Config\ViewFactory($this->objectManager);
36+
$this->theme = $this->getMock('Magento\Framework\View\Design\ThemeInterface');
37+
$this->view = $this->getMock('Magento\Framework\Config\View', [], [], '', false);
38+
}
39+
40+
public function testCreate()
41+
{
42+
$this->objectManager->expects($this->once())
43+
->method('create')
44+
->with('Magento\Framework\Config\View', [])
45+
->willReturn($this->view);
46+
$this->assertEquals($this->view, $this->model->create());
47+
}
48+
49+
public function testCreateWithArguments()
50+
{
51+
/** @var \Magento\Theme\Model\View\Design|\PHPUnit_Framework_MockObject_MockObject $design */
52+
$design = $this->getMock('Magento\Theme\Model\View\Design', [], [], '', false);
53+
$design->expects($this->once())
54+
->method('setDesignTheme')
55+
->with($this->theme, self::AREA);
56+
57+
/** @var \Magento\Framework\Config\FileResolver|\PHPUnit_Framework_MockObject_MockObject $fileResolver */
58+
$fileResolver = $this->getMock('Magento\Framework\Config\FileResolver', [], [], '', false);
59+
60+
$valueMap = [
61+
['Magento\Theme\Model\View\Design', [], $design],
62+
['Magento\Framework\Config\FileResolver', ['designInterface' => $design], $fileResolver],
63+
['Magento\Framework\Config\View', ['fileResolver' => $fileResolver], $this->view],
64+
];
65+
$this->objectManager->expects($this->exactly(3))
66+
->method('create')
67+
->willReturnMap($valueMap);
68+
69+
$this->assertEquals($this->view, $this->model->create($this->getArguments()));
70+
}
71+
72+
/**
73+
* @expectedException \Magento\Framework\Exception\LocalizedException
74+
* @expectedExceptionMessage wrong theme doesn't implement ThemeInterface
75+
*/
76+
public function testCreateException()
77+
{
78+
$this->model->create([
79+
'themeModel' => 'wrong theme',
80+
'area' => self::AREA
81+
]);
82+
}
83+
84+
/**
85+
* @return array
86+
*/
87+
protected function getArguments()
88+
{
89+
return [
90+
'themeModel' => $this->theme,
91+
'area' => self::AREA
92+
];
93+
}
94+
}

lib/internal/Magento/Framework/Config/ViewFactory.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,38 @@ public function __construct(ObjectManagerInterface $objectManager)
2626
}
2727

2828
/**
29+
* Create new view object
30+
*
31+
* @param array $arguments
2932
* @return \Magento\Framework\Config\View
33+
* @throws \Magento\Framework\Exception\LocalizedException
3034
*/
31-
public function create()
35+
public function create(array $arguments = [])
3236
{
37+
$viewConfigArguments = [];
38+
39+
if (isset($arguments['themeModel']) && isset($arguments['area'])) {
40+
if (!($arguments['themeModel'] instanceof \Magento\Framework\View\Design\ThemeInterface)) {
41+
throw new \Magento\Framework\Exception\LocalizedException(
42+
new \Magento\Framework\Phrase('%1 doesn\'t implement ThemeInterface', [$arguments['themeModel']])
43+
);
44+
}
45+
/** @var \Magento\Theme\Model\View\Design $design */
46+
$design = $this->objectManager->create('Magento\Theme\Model\View\Design');
47+
$design->setDesignTheme($arguments['themeModel'], $arguments['area']);
48+
/** @var \Magento\Framework\Config\FileResolver $fileResolver */
49+
$fileResolver = $this->objectManager->create(
50+
'Magento\Framework\Config\FileResolver',
51+
[
52+
'designInterface' => $design,
53+
]
54+
);
55+
$viewConfigArguments['fileResolver'] = $fileResolver;
56+
}
57+
3358
return $this->objectManager->create(
34-
'Magento\Framework\Config\View'
59+
'Magento\Framework\Config\View',
60+
$viewConfigArguments
3561
);
3662
}
3763
}

lib/internal/Magento/Framework/View/Config.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,25 @@ public function __construct(
5757
public function getViewConfig(array $params = [])
5858
{
5959
$this->assetRepo->updateDesignParams($params);
60-
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
61-
$currentTheme = $params['themeModel'];
62-
$key = $currentTheme->getCode();
63-
if (isset($this->viewConfigs[$key])) {
64-
return $this->viewConfigs[$key];
60+
$viewConfigParams = [];
61+
62+
if (isset($params['themeModel'])) {
63+
/** @var \Magento\Framework\View\Design\ThemeInterface $currentTheme */
64+
$currentTheme = $params['themeModel'];
65+
$key = $currentTheme->getCode();
66+
if (isset($this->viewConfigs[$key])) {
67+
return $this->viewConfigs[$key];
68+
}
69+
$viewConfigParams['themeModel'] = $currentTheme;
6570
}
71+
$viewConfigParams['area'] = (isset($params['area'])) ? $params['area'] : null;
6672

67-
$config = $this->viewConfigFactory->create();
73+
/** @var \Magento\Framework\Config\View $config */
74+
$config = $this->viewConfigFactory->create($viewConfigParams);
6875

69-
$this->viewConfigs[$key] = $config;
76+
if (isset($key)) {
77+
$this->viewConfigs[$key] = $config;
78+
}
7079
return $config;
7180
}
7281
}

lib/internal/Magento/Framework/View/Test/Unit/ConfigTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Magento\Framework\View\Test\Unit;
88

9-
use Magento\Framework\App\Filesystem\DirectoryList;
109
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1110

1211
class ConfigTest extends \PHPUnit_Framework_TestCase
@@ -41,6 +40,8 @@ protected function setUp()
4140

4241
public function testGetViewConfig()
4342
{
43+
$themeCode = 2;
44+
4445
$themeMock = $this->getMock(
4546
'Magento\Theme\Model\Theme',
4647
['getCode'],
@@ -50,8 +51,11 @@ public function testGetViewConfig()
5051
);
5152
$themeMock->expects($this->atLeastOnce())
5253
->method('getCode')
53-
->will($this->returnValue(2));
54-
$params = ['themeModel' => $themeMock];
54+
->will($this->returnValue($themeCode));
55+
$params = [
56+
'themeModel' => $themeMock,
57+
'area' => 'frontend'
58+
];
5559
$this->repositoryMock->expects($this->atLeastOnce())
5660
->method('updateDesignParams')
5761
->with($this->equalTo($params))

lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ define([
1919
mediaBrowserTargetElementId: null,
2020

2121
initialize: function(htmlId, config) {
22+
if (config.baseStaticUrl && config.baseStaticDefaultUrl) {
23+
tinyMCE.baseURL = tinyMCE.baseURL.replace(config.baseStaticUrl, config.baseStaticDefaultUrl);
24+
}
25+
2226
this.id = htmlId;
2327
this.config = config;
2428

@@ -352,4 +356,4 @@ define([
352356
}
353357
};
354358

355-
});
359+
});

0 commit comments

Comments
 (0)