Skip to content

Commit 10c01d4

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'tango/BUGS2.0' into 2.0
2 parents 270f37c + c1b8e38 commit 10c01d4

File tree

16 files changed

+166
-140
lines changed

16 files changed

+166
-140
lines changed

app/code/Magento/Backend/view/adminhtml/templates/page/js/require_js.phtml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<script>
88
var BASE_URL = '<?php /* @escapeNotVerified */ echo $block->getUrl('*') ?>';
99
var FORM_KEY = '<?php /* @escapeNotVerified */ echo $block->getFormKey() ?>';
10+
var require = {
11+
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
12+
};
1013
</script>

app/code/Magento/RequireJs/Block/Html/Head/Config.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,4 @@ protected function _prepareLayout()
119119

120120
return parent::_prepareLayout();
121121
}
122-
123-
/**
124-
* Include base RequireJs configuration necessary for working with Magento application
125-
*
126-
* @return string|void
127-
*/
128-
protected function _toHtml()
129-
{
130-
return "<script type=\"text/javascript\">\n"
131-
. $this->config->getBaseConfig()
132-
. "</script>\n";
133-
}
134122
}

app/code/Magento/RequireJs/Test/Unit/Block/Html/Head/ConfigTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,35 +131,4 @@ public function testSetLayout()
131131
);
132132
$object->setLayout($layout);
133133
}
134-
135-
public function testToHtml()
136-
{
137-
$this->context->expects($this->once())
138-
->method('getEventManager')
139-
->will($this->returnValue($this->getMockForAbstractClass('\Magento\Framework\Event\ManagerInterface')));
140-
$this->context->expects($this->once())
141-
->method('getScopeConfig')
142-
->will($this->returnValue(
143-
$this->getMockForAbstractClass('\Magento\Framework\App\Config\ScopeConfigInterface')
144-
));
145-
$this->config->expects($this->once())->method('getBaseConfig')->will($this->returnValue('the config data'));
146-
$this->minificationMock = $this->getMockBuilder('Magento\Framework\View\Asset\Minification')
147-
->disableOriginalConstructor()
148-
->getMock();
149-
150-
$object = new Config(
151-
$this->context,
152-
$this->config,
153-
$this->fileManager,
154-
$this->pageConfig,
155-
$this->bundleConfig,
156-
$this->minificationMock
157-
);
158-
$html = $object->toHtml();
159-
$expectedFormat = <<<expected
160-
<script type="text/javascript">
161-
the config data</script>
162-
expected;
163-
$this->assertStringMatchesFormat($expectedFormat, $html);
164-
}
165134
}

app/code/Magento/Theme/view/frontend/layout/default.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<update handle="default_head_blocks"/>
1010
<body>
11+
<block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
1112
<referenceContainer name="after.body.start">
1213
<block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config"/>
1314
<block class="Magento\Translation\Block\Html\Head\Config" name="translate-config"/>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
<script>
8+
var require = {
9+
"baseUrl": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('/') ?>"
10+
};
11+
</script>

dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\View\Element;
77

8+
use Magento\Framework\View\Element\AbstractBlock;
9+
810
/**
911
* @magentoAppIsolation enabled
1012
*/
@@ -556,7 +558,7 @@ public function testGetCacheKey()
556558
$this->assertNotEquals($name, $key);
557559

558560
$block->setCacheKey('key');
559-
$this->assertEquals('key', $block->getCacheKey());
561+
$this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . 'key', $block->getCacheKey());
560562
}
561563

562564
/**

lib/internal/Magento/Framework/Event/Config/Converter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function convert($source)
3838
$config['name'] = $observerNameNode->nodeValue;
3939
$eventObservers[$observerNameNode->nodeValue] = $config;
4040
}
41-
$output[$eventName] = $eventObservers;
41+
$output[mb_strtolower($eventName)] = $eventObservers;
4242
}
4343
return $output;
4444
}

lib/internal/Magento/Framework/Event/Manager.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,28 @@
1010

1111
class Manager implements ManagerInterface
1212
{
13-
/**
14-
* Events cache
15-
*
16-
* @var array
17-
*/
18-
protected $_events = [];
19-
2013
/**
2114
* Event invoker
2215
*
2316
* @var InvokerInterface
2417
*/
25-
protected $_invoker;
18+
protected $invoker;
2619

2720
/**
2821
* Event config
2922
*
3023
* @var ConfigInterface
3124
*/
32-
protected $_eventConfig;
25+
protected $eventConfig;
3326

3427
/**
3528
* @param InvokerInterface $invoker
3629
* @param ConfigInterface $eventConfig
3730
*/
3831
public function __construct(InvokerInterface $invoker, ConfigInterface $eventConfig)
3932
{
40-
$this->_invoker = $invoker;
41-
$this->_eventConfig = $eventConfig;
33+
$this->invoker = $invoker;
34+
$this->eventConfig = $eventConfig;
4235
}
4336

4437
/**
@@ -53,16 +46,17 @@ public function __construct(InvokerInterface $invoker, ConfigInterface $eventCon
5346
*/
5447
public function dispatch($eventName, array $data = [])
5548
{
49+
$eventName = mb_strtolower($eventName);
5650
\Magento\Framework\Profiler::start('EVENT:' . $eventName, ['group' => 'EVENT', 'name' => $eventName]);
57-
foreach ($this->_eventConfig->getObservers($eventName) as $observerConfig) {
51+
foreach ($this->eventConfig->getObservers($eventName) as $observerConfig) {
5852
$event = new \Magento\Framework\Event($data);
5953
$event->setName($eventName);
6054

6155
$wrapper = new Observer();
6256
$wrapper->setData(array_merge(['event' => $event], $data));
6357

6458
\Magento\Framework\Profiler::start('OBSERVER:' . $observerConfig['name']);
65-
$this->_invoker->dispatch($observerConfig, $wrapper);
59+
$this->invoker->dispatch($observerConfig, $wrapper);
6660
\Magento\Framework\Profiler::stop('OBSERVER:' . $observerConfig['name']);
6761
}
6862
\Magento\Framework\Profiler::stop('EVENT:' . $eventName);

lib/internal/Magento/Framework/Event/Test/Unit/Config/ConverterTest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,44 @@
55
*/
66
namespace Magento\Framework\Event\Test\Unit\Config;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
use Magento\Framework\Event\Config\Converter;
10+
811
class ConverterTest extends \PHPUnit_Framework_TestCase
912
{
1013
/**
11-
* @var \Magento\Framework\Event\Config\Converter
14+
* @var Converter
1215
*/
13-
protected $_model;
16+
protected $model;
1417

1518
/**
1619
* @var string
1720
*/
18-
protected $_filePath;
21+
protected $filePath;
1922

2023
/**
2124
* @var \DOMDocument
2225
*/
23-
protected $_source;
26+
protected $source;
27+
28+
/**
29+
* @var ObjectManagerHelper
30+
*/
31+
protected $objectManagerHelper;
2432

2533
protected function setUp()
2634
{
27-
$this->_filePath = __DIR__ . '/_files/';
28-
$this->_source = new \DOMDocument();
29-
$this->_model = new \Magento\Framework\Event\Config\Converter();
35+
$this->objectManagerHelper = new ObjectManagerHelper($this);
36+
$this->filePath = __DIR__ . '/_files/';
37+
$this->source = new \DOMDocument();
38+
$this->model = $this->objectManagerHelper->getObject(Converter::class);
3039
}
3140

3241
public function testConvert()
3342
{
34-
$this->_source->loadXML(file_get_contents($this->_filePath . 'event_config.xml'));
35-
$convertedFile = include $this->_filePath . 'event_config.php';
36-
$this->assertEquals($convertedFile, $this->_model->convert($this->_source));
43+
$this->source->loadXML(file_get_contents($this->filePath . 'event_config.xml'));
44+
$convertedFile = include $this->filePath . 'event_config.php';
45+
$this->assertEquals($convertedFile, $this->model->convert($this->source));
3746
}
3847

3948
/**
@@ -42,7 +51,7 @@ public function testConvert()
4251
*/
4352
public function testConvertThrowsExceptionWhenDomIsInvalid()
4453
{
45-
$this->_source->loadXML(file_get_contents($this->_filePath . 'event_invalid_config.xml'));
46-
$this->_model->convert($this->_source);
54+
$this->source->loadXML(file_get_contents($this->filePath . 'event_invalid_config.xml'));
55+
$this->model->convert($this->source);
4756
}
4857
}

lib/internal/Magento/Framework/Event/Test/Unit/Config/_files/event_config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
'shared' => false,
1616
'name' => 'observer_2',
1717
],
18+
],
19+
'some_eventname' => [
20+
'observer_3' => ['instance' => 'instance_3', 'name' => 'observer_3'],
1821
]
1922
];

0 commit comments

Comments
 (0)