Skip to content
Snippets Groups Projects
Commit 381e1c65 authored by Vladimir Pelipenko's avatar Vladimir Pelipenko
Browse files

Merge pull request #98 from magento-extensibility/github

[Github] Merge public Github commits
parents 412f8113 0d7e5a5b
Branches
No related merge requests found
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
</xs:documentation> </xs:documentation>
</xs:annotation> </xs:annotation>
<xs:restriction base="xs:string"> <xs:restriction base="xs:string">
<xs:pattern value="[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}" /> <xs:pattern value="[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}" />
</xs:restriction> </xs:restriction>
</xs:simpleType> </xs:simpleType>
......
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Tests for \Magento\Framework\Data\Form\Element\Image
*/
namespace Magento\Framework\Data\Form\Element;
class ImageTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\Data\Form\Element\Image
*/
protected $imageElement;
protected function setUp()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $elementFactory \Magento\Framework\Data\Form\ElementFactory */
$elementFactory = $objectManager->create('Magento\Framework\Data\Form\ElementFactory');
$this->imageElement = $elementFactory->create('Magento\Framework\Data\Form\Element\Image', []);
$form = $objectManager->create('Magento\Framework\Data\Form');
$this->imageElement->setForm($form);
}
public function testGetElementHtml()
{
$filePath = 'some/path/to/file.jpg';
$this->imageElement->setValue($filePath);
$html = $this->imageElement->getElementHtml();
$this->assertContains('media/' . $filePath, $html);
}
}
...@@ -209,7 +209,7 @@ return [ ...@@ -209,7 +209,7 @@ return [
'resource="test_Value::value"/></menu></config>', 'resource="test_Value::value"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -220,7 +220,7 @@ return [ ...@@ -220,7 +220,7 @@ return [
'resource="Test_value::value"/></menu></config>', 'resource="Test_value::value"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -231,7 +231,7 @@ return [ ...@@ -231,7 +231,7 @@ return [
'resource="M#$%23_value::value"/></menu></config>', 'resource="M#$%23_value::value"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -242,7 +242,7 @@ return [ ...@@ -242,7 +242,7 @@ return [
'resource="_value::value"/></menu></config>', 'resource="_value::value"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value '_value::value' is not accepted by " . "Element 'add', attribute 'resource': [facet 'pattern'] The value '_value::value' is not accepted by " .
"the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': '_value::value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': '_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -253,7 +253,7 @@ return [ ...@@ -253,7 +253,7 @@ return [
'</menu></config>', '</menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -264,7 +264,7 @@ return [ ...@@ -264,7 +264,7 @@ return [
'resource="Test_Value:value"/></menu></config>', 'resource="Test_Value:value"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " . "Element 'add', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -275,7 +275,7 @@ return [ ...@@ -275,7 +275,7 @@ return [
'resource="Test_Value::"/></menu></config>', 'resource="Test_Value::"/></menu></config>',
[ [
"Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " . "Element 'add', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'add', attribute 'resource': 'Test_Value::' " . "Element 'add', attribute 'resource': 'Test_Value::' " .
"is not a valid value of the atomic type 'typeResource'." "is not a valid value of the atomic type 'typeResource'."
], ],
...@@ -608,7 +608,7 @@ return [ ...@@ -608,7 +608,7 @@ return [
'resource="test_Value::value"/></menu></config>', 'resource="test_Value::value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'test_Value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'test_Value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -618,7 +618,7 @@ return [ ...@@ -618,7 +618,7 @@ return [
'resource="Test_value::value"/></menu></config>', 'resource="Test_value::value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'Test_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -628,7 +628,7 @@ return [ ...@@ -628,7 +628,7 @@ return [
'resource="M#$%23_value::value"/></menu></config>', 'resource="M#$%23_value::value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'M#$%23_value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'M#$%23_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -638,7 +638,7 @@ return [ ...@@ -638,7 +638,7 @@ return [
'resource="_value::value"/></menu></config>', 'resource="_value::value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value '_value::value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value '_value::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': '_value::value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': '_value::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -648,7 +648,7 @@ return [ ...@@ -648,7 +648,7 @@ return [
'resource="Magento_::value"/></menu></config>', 'resource="Magento_::value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'Magento_::value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'Magento_::value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -658,7 +658,7 @@ return [ ...@@ -658,7 +658,7 @@ return [
'resource="Test_Value:value"/></menu></config>', 'resource="Test_Value:value"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value:value' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'Test_Value:value' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
...@@ -668,7 +668,7 @@ return [ ...@@ -668,7 +668,7 @@ return [
'resource="Test_Value::"/></menu></config>', 'resource="Test_Value::"/></menu></config>',
[ [
"Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " . "Element 'update', attribute 'resource': [facet 'pattern'] The value 'Test_Value::' is not " .
"accepted by the pattern '[A-Z]+[a-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.", "accepted by the pattern '[A-Z]+[A-Za-z0-9]{1,}_[A-Z]+[A-Z0-9a-z]{1,}::[A-Za-z_0-9]{1,}'.",
"Element 'update', attribute 'resource': 'Test_Value::' is not a valid value of the atomic " . "Element 'update', attribute 'resource': 'Test_Value::' is not a valid value of the atomic " .
"type 'typeResource'." "type 'typeResource'."
], ],
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
--> -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../app/code/Magento/Backend/etc/menu.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../app/code/Magento/Backend/etc/menu.xsd">
<menu> <menu>
<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" /> <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" />
<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" /> <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" />
<remove id="Some_Adminhtml::system_currency" /> <remove id="Some_Adminhtml::system_currency" />
</menu> </menu>
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
*/ */
namespace Magento\Framework\Data\Form\Element; namespace Magento\Framework\Data\Form\Element;
use Magento\Framework\UrlInterface;
class ImageTest extends \PHPUnit_Framework_TestCase class ImageTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
...@@ -16,6 +18,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase ...@@ -16,6 +18,11 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
protected $_objectManagerMock; protected $_objectManagerMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $urlBuilder;
/** /**
* @var \Magento\Framework\Data\Form\Element\Image * @var \Magento\Framework\Data\Form\Element\Image
*/ */
...@@ -32,12 +39,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase ...@@ -32,12 +39,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase
false false
); );
$escaperMock = $this->getMock('\Magento\Framework\Escaper', [], [], '', false); $escaperMock = $this->getMock('\Magento\Framework\Escaper', [], [], '', false);
$urlBuilderMock = $this->getMock('\Magento\Framework\Url', [], [], '', false); $this->urlBuilder = $this->getMock('\Magento\Framework\Url', [], [], '', false);
$this->_image = new \Magento\Framework\Data\Form\Element\Image( $this->_image = new \Magento\Framework\Data\Form\Element\Image(
$factoryMock, $factoryMock,
$collectionFactoryMock, $collectionFactoryMock,
$escaperMock, $escaperMock,
$urlBuilderMock $this->urlBuilder
); );
$formMock = new \Magento\Framework\Object(); $formMock = new \Magento\Framework\Object();
$formMock->getHtmlIdPrefix('id_prefix'); $formMock->getHtmlIdPrefix('id_prefix');
...@@ -81,12 +88,16 @@ class ImageTest extends \PHPUnit_Framework_TestCase ...@@ -81,12 +88,16 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testGetElementHtmlWithValue() public function testGetElementHtmlWithValue()
{ {
$this->_image->setValue('test_value'); $this->_image->setValue('test_value');
$this->urlBuilder->expects($this->once())
->method('getBaseUrl')
->with(['_type' => UrlInterface::URL_TYPE_MEDIA])
->willReturn('http://localhost/media/');
$html = $this->_image->getElementHtml(); $html = $this->_image->getElementHtml();
$this->assertContains('class="input-file"', $html); $this->assertContains('class="input-file"', $html);
$this->assertContains('<input', $html); $this->assertContains('<input', $html);
$this->assertContains('type="file"', $html); $this->assertContains('type="file"', $html);
$this->assertContains('value="test_value"', $html); $this->assertContains('value="test_value"', $html);
$this->assertContains('<a href="test_value" onclick="imagePreview(\'_image\'); return false;"', $html); $this->assertContains('<a href="http://localhost/media/test_value" onclick="imagePreview(\'_image\'); return false;"', $html);
$this->assertContains('<input type="checkbox"', $html); $this->assertContains('<input type="checkbox"', $html);
} }
} }
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
*/ */
namespace Magento\Framework\Data\Form\Element; namespace Magento\Framework\Data\Form\Element;
use Magento\Framework\UrlInterface;
class Image extends \Magento\Framework\Data\Form\Element\AbstractElement class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
{ {
/** /**
* @var \Magento\Framework\UrlInterface * @var UrlInterface
*/ */
protected $_urlBuilder; protected $_urlBuilder;
...@@ -22,14 +24,14 @@ class Image extends \Magento\Framework\Data\Form\Element\AbstractElement ...@@ -22,14 +24,14 @@ class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
* @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Escaper $escaper
* @param \Magento\Framework\UrlInterface $urlBuilder * @param UrlInterface $urlBuilder
* @param array $data * @param array $data
*/ */
public function __construct( public function __construct(
\Magento\Framework\Data\Form\Element\Factory $factoryElement, \Magento\Framework\Data\Form\Element\Factory $factoryElement,
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
\Magento\Framework\Escaper $escaper, \Magento\Framework\Escaper $escaper,
\Magento\Framework\UrlInterface $urlBuilder, UrlInterface $urlBuilder,
$data = [] $data = []
) { ) {
$this->_urlBuilder = $urlBuilder; $this->_urlBuilder = $urlBuilder;
...@@ -50,7 +52,7 @@ class Image extends \Magento\Framework\Data\Form\Element\AbstractElement ...@@ -50,7 +52,7 @@ class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
$url = $this->_getUrl(); $url = $this->_getUrl();
if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) { if (!preg_match("/^http\:\/\/|https\:\/\//", $url)) {
$url = $this->_urlBuilder->getBaseUrl('media') . $url; $url = $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $url;
} }
$html = '<a href="' . $html = '<a href="' .
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment