Skip to content

Commit 381e1c6

Browse files
committed
Merge pull request #98 from magento-extensibility/github
[Github] Merge public Github commits
2 parents 412f811 + 0d7e5a5 commit 381e1c6

File tree

6 files changed

+72
-23
lines changed

6 files changed

+72
-23
lines changed

app/code/Magento/Backend/etc/menu.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
</xs:documentation>
132132
</xs:annotation>
133133
<xs:restriction base="xs:string">
134-
<xs:pattern value="[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}" />
134+
<xs:pattern value="[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}" />
135135
</xs:restriction>
136136
</xs:simpleType>
137137

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/**
7+
* Tests for \Magento\Framework\Data\Form\Element\Image
8+
*/
9+
namespace Magento\Framework\Data\Form\Element;
10+
11+
class ImageTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Framework\Data\Form\Element\Image
15+
*/
16+
protected $imageElement;
17+
18+
protected function setUp()
19+
{
20+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
21+
/** @var $elementFactory \Magento\Framework\Data\Form\ElementFactory */
22+
$elementFactory = $objectManager->create('Magento\Framework\Data\Form\ElementFactory');
23+
$this->imageElement = $elementFactory->create('Magento\Framework\Data\Form\Element\Image', []);
24+
$form = $objectManager->create('Magento\Framework\Data\Form');
25+
$this->imageElement->setForm($form);
26+
}
27+
28+
public function testGetElementHtml()
29+
{
30+
$filePath = 'some/path/to/file.jpg';
31+
$this->imageElement->setValue($filePath);
32+
$html = $this->imageElement->getElementHtml();
33+
34+
$this->assertContains('media/' . $filePath, $html);
35+
}
36+
}

dev/tests/unit/testsuite/Magento/Backend/Model/Menu/Config/_files/invalidMenuXmlArray.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
'resource="test_Value::value"/></menu></config>',
210210
[
211211
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " .
212-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
212+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
213213
"Element 'add', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " .
214214
"type 'typeResource'."
215215
],
@@ -220,7 +220,7 @@
220220
'resource="Test_value::value"/></menu></config>',
221221
[
222222
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " .
223-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
223+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
224224
"Element 'add', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " .
225225
"type 'typeResource'."
226226
],
@@ -231,7 +231,7 @@
231231
'resource="M#$%23_value::value"/></menu></config>',
232232
[
233233
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " .
234-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
234+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
235235
"Element 'add', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " .
236236
"type 'typeResource'."
237237
],
@@ -242,7 +242,7 @@
242242
'resource="_value::value"/></menu></config>',
243243
[
244244
"Element 'add', attribute 'resource': [facet 'pattern'] The value '_value::value' is not accepted by " .
245-
"the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
245+
"the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
246246
"Element 'add', attribute 'resource': '_value::value' is not a valid value of the atomic " .
247247
"type 'typeResource'."
248248
],
@@ -253,7 +253,7 @@
253253
'</menu></config>',
254254
[
255255
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " .
256-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
256+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
257257
"Element 'add', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " .
258258
"type 'typeResource'."
259259
],
@@ -264,7 +264,7 @@
264264
'resource="Test_Value:value"/></menu></config>',
265265
[
266266
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " .
267-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
267+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
268268
"Element 'add', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " .
269269
"type 'typeResource'."
270270
],
@@ -275,7 +275,7 @@
275275
'resource="Test_Value::"/></menu></config>',
276276
[
277277
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " .
278-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
278+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
279279
"Element 'add', attribute 'resource': 'Test_Value::' " .
280280
"is not a valid value of the atomic type 'typeResource'."
281281
],
@@ -608,7 +608,7 @@
608608
'resource="test_Value::value"/></menu></config>',
609609
[
610610
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " .
611-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
611+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
612612
"Element 'update', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " .
613613
"type 'typeResource'."
614614
],
@@ -618,7 +618,7 @@
618618
'resource="Test_value::value"/></menu></config>',
619619
[
620620
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " .
621-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
621+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
622622
"Element 'update', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " .
623623
"type 'typeResource'."
624624
],
@@ -628,7 +628,7 @@
628628
'resource="M#$%23_value::value"/></menu></config>',
629629
[
630630
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " .
631-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
631+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
632632
"Element 'update', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " .
633633
"type 'typeResource'."
634634
],
@@ -638,7 +638,7 @@
638638
'resource="_value::value"/></menu></config>',
639639
[
640640
"Element 'update', attribute 'resource': [facet 'pattern'] The value '_value::value' is not " .
641-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
641+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
642642
"Element 'update', attribute 'resource': '_value::value' is not a valid value of the atomic " .
643643
"type 'typeResource'."
644644
],
@@ -648,7 +648,7 @@
648648
'resource="Magento_::value"/></menu></config>',
649649
[
650650
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " .
651-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
651+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
652652
"Element 'update', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " .
653653
"type 'typeResource'."
654654
],
@@ -658,7 +658,7 @@
658658
'resource="Test_Value:value"/></menu></config>',
659659
[
660660
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " .
661-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
661+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
662662
"Element 'update', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " .
663663
"type 'typeResource'."
664664
],
@@ -668,7 +668,7 @@
668668
'resource="Test_Value::"/></menu></config>',
669669
[
670670
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " .
671-
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
671+
"accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
672672
"Element 'update', attribute 'resource': 'Test_Value::' is not a valid value of the atomic " .
673673
"type 'typeResource'."
674674
],

dev/tests/unit/testsuite/Magento/Backend/Model/Menu/Config/_files/valid_menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../app/code/Magento/Backend/etc/menu.xsd">
99
<menu>
10-
<add id="Some_TestName::catalog_some_events" title="Events" module="Some_Value" sortOrder="10" parent="Some_Value::test_test" action="action/actions" resource="Some_Value::events" dependsOnModule="Some_Value" dependsOnConfig="catalog/Some_valuet/enabled" toolTip="some tool tip" />
10+
<add id="Some_TestName::catalog_some_events" title="Events" module="SomeTest_TestValue" sortOrder="10" parent="SomeTest_TestValue::someTest_testValue" action="action/actions" resource="SomeTest_TestValue::eventsTest_value" dependsOnModule="SomeTest_TestValue" dependsOnConfig="catalog/SomeTest_TestValue/enabled" toolTip="some tool tip" />
1111
<update id="Module_Name::system_config" title="some title" sortOrder="12" action="some_action" resource="Some_Test::events" dependsOnModule="Some_Test" dependsOnConfig="catalog/Some_value/enabled" module="Some_Module" parent="Some_Test::test_value" toolTip="some toolTip" />
1212
<remove id="Some_Adminhtml::system_currency" />
1313
</menu>

dev/tests/unit/testsuite/Magento/Framework/Data/Form/Element/ImageTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
*/
1010
namespace Magento\Framework\Data\Form\Element;
1111

12+
use Magento\Framework\UrlInterface;
13+
1214
class ImageTest extends \PHPUnit_Framework_TestCase
1315
{
1416
/**
1517
* @var \PHPUnit_Framework_MockObject_MockObject
1618
*/
1719
protected $_objectManagerMock;
1820

21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $urlBuilder;
25+
1926
/**
2027
* @var \Magento\Framework\Data\Form\Element\Image
2128
*/
@@ -32,12 +39,12 @@ protected function setUp()
3239
false
3340
);
3441
$escaperMock = $this->getMock('\Magento\Framework\Escaper', [], [], '', false);
35-
$urlBuilderMock = $this->getMock('\Magento\Framework\Url', [], [], '', false);
42+
$this->urlBuilder = $this->getMock('\Magento\Framework\Url', [], [], '', false);
3643
$this->_image = new \Magento\Framework\Data\Form\Element\Image(
3744
$factoryMock,
3845
$collectionFactoryMock,
3946
$escaperMock,
40-
$urlBuilderMock
47+
$this->urlBuilder
4148
);
4249
$formMock = new \Magento\Framework\Object();
4350
$formMock->getHtmlIdPrefix('id_prefix');
@@ -81,12 +88,16 @@ public function testGetElementHtmlWithoutValue()
8188
public function testGetElementHtmlWithValue()
8289
{
8390
$this->_image->setValue('test_value');
91+
$this->urlBuilder->expects($this->once())
92+
->method('getBaseUrl')
93+
->with(['_type' => UrlInterface::URL_TYPE_MEDIA])
94+
->willReturn('http://localhost/media/');
8495
$html = $this->_image->getElementHtml();
8596
$this->assertContains('class="input-file"', $html);
8697
$this->assertContains('<input', $html);
8798
$this->assertContains('type="file"', $html);
8899
$this->assertContains('value="test_value"', $html);
89-
$this->assertContains('<a href="test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
100+
$this->assertContains('<a href="http://localhost/media/test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
90101
$this->assertContains('<input type="checkbox"', $html);
91102
}
92103
}

lib/internal/Magento/Framework/Data/Form/Element/Image.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@
1111
*/
1212
namespace Magento\Framework\Data\Form\Element;
1313

14+
use Magento\Framework\UrlInterface;
15+
1416
class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
1517
{
1618
/**
17-
* @var \Magento\Framework\UrlInterface
19+
* @var UrlInterface
1820
*/
1921
protected $_urlBuilder;
2022

2123
/**
2224
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
2325
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
2426
* @param \Magento\Framework\Escaper $escaper
25-
* @param \Magento\Framework\UrlInterface $urlBuilder
27+
* @param UrlInterface $urlBuilder
2628
* @param array $data
2729
*/
2830
public function __construct(
2931
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
3032
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
3133
\Magento\Framework\Escaper $escaper,
32-
\Magento\Framework\UrlInterface $urlBuilder,
34+
UrlInterface $urlBuilder,
3335
$data = []
3436
) {
3537
$this->_urlBuilder = $urlBuilder;
@@ -50,7 +52,7 @@ public function getElementHtml()
5052
$url = $this->_getUrl();
5153

5254
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
53-
$url = $this->_urlBuilder->getBaseUrl('media') . $url;
55+
$url = $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $url;
5456
}
5557

5658
$html = '<a href="' .

0 commit comments

Comments
 (0)