Skip to content

Commit

Permalink
Merge pull request #98 from magento-extensibility/github
Browse files Browse the repository at this point in the history
[Github] Merge public Github commits
  • Loading branch information
vpelipenko committed Feb 13, 2015
2 parents 412f811 + 0d7e5a5 commit 381e1c6
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/menu.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
</xs:documentation>
</xs:annotation>
<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:simpleType>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
'resource="test_Value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -220,7 +220,7 @@
'resource="Test_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -231,7 +231,7 @@
'resource="M#$%23_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -242,7 +242,7 @@
'resource="_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -253,7 +253,7 @@
'</menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -264,7 +264,7 @@
'resource="Test_Value:value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -275,7 +275,7 @@
'resource="Test_Value::"/></menu></config>',
[
"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::' " .
"is not a valid value of the atomic type 'typeResource'."
],
Expand Down Expand Up @@ -608,7 +608,7 @@
'resource="test_Value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -618,7 +618,7 @@
'resource="Test_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -628,7 +628,7 @@
'resource="M#$%23_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -638,7 +638,7 @@
'resource="_value::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -648,7 +648,7 @@
'resource="Magento_::value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -658,7 +658,7 @@
'resource="Test_Value:value"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand All @@ -668,7 +668,7 @@
'resource="Test_Value::"/></menu></config>',
[
"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 " .
"type 'typeResource'."
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../../../../app/code/Magento/Backend/etc/menu.xsd">
<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" />
<remove id="Some_Adminhtml::system_currency" />
</menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
*/
namespace Magento\Framework\Data\Form\Element;

use Magento\Framework\UrlInterface;

class ImageTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_objectManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $urlBuilder;

/**
* @var \Magento\Framework\Data\Form\Element\Image
*/
Expand All @@ -32,12 +39,12 @@ protected function setUp()
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(
$factoryMock,
$collectionFactoryMock,
$escaperMock,
$urlBuilderMock
$this->urlBuilder
);
$formMock = new \Magento\Framework\Object();
$formMock->getHtmlIdPrefix('id_prefix');
Expand Down Expand Up @@ -81,12 +88,16 @@ public function testGetElementHtmlWithoutValue()
public function testGetElementHtmlWithValue()
{
$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();
$this->assertContains('class="input-file"', $html);
$this->assertContains('<input', $html);
$this->assertContains('type="file"', $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);
}
}
10 changes: 6 additions & 4 deletions lib/internal/Magento/Framework/Data/Form/Element/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
*/
namespace Magento\Framework\Data\Form\Element;

use Magento\Framework\UrlInterface;

class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
{
/**
* @var \Magento\Framework\UrlInterface
* @var UrlInterface
*/
protected $_urlBuilder;

/**
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param UrlInterface $urlBuilder
* @param array $data
*/
public function __construct(
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
\Magento\Framework\Escaper $escaper,
\Magento\Framework\UrlInterface $urlBuilder,
UrlInterface $urlBuilder,
$data = []
) {
$this->_urlBuilder = $urlBuilder;
Expand All @@ -50,7 +52,7 @@ public function getElementHtml()
$url = $this->_getUrl();

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="' .
Expand Down

0 comments on commit 381e1c6

Please sign in to comment.