Skip to content

Commit acb837d

Browse files
Merge pull request #355 from magento-south/BUGS
[SOUTH] Bugs
2 parents 6037f50 + 4f4be19 commit acb837d

File tree

11 files changed

+263
-13
lines changed

11 files changed

+263
-13
lines changed

app/code/Magento/Backend/Block/Widget/Form.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ public function setForm(\Magento\Framework\Data\Form $form)
111111
$this->_form = $form;
112112
$this->_form->setParent($this);
113113
$this->_form->setBaseUrl($this->_urlBuilder->getBaseUrl());
114+
115+
$customAttributes = $this->getData('custom_attributes');
116+
if (is_array($customAttributes)) {
117+
foreach ($customAttributes as $key => $value) {
118+
$this->_form->addCustomAttribute($key, $value);
119+
}
120+
}
114121
return $this;
115122
}
116123

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Block\Widget;
7+
8+
use Magento\Backend\Block\Template\Context;
9+
use Magento\Backend\Block\Widget\Form;
10+
use Magento\Framework\Data\Form as DataForm;
11+
use Magento\Framework\UrlInterface;
12+
13+
class FormTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/** @var Form */
16+
protected $model;
17+
18+
/** @var Context |\PHPUnit_Framework_MockObject_MockObject */
19+
protected $context;
20+
21+
/** @var DataForm |\PHPUnit_Framework_MockObject_MockObject */
22+
protected $dataForm;
23+
24+
/** @var UrlInterface |\PHPUnit_Framework_MockObject_MockObject */
25+
protected $urlBuilder;
26+
27+
protected function setUp()
28+
{
29+
$this->prepareContext();
30+
31+
$this->dataForm = $this->getMockBuilder('Magento\Framework\Data\Form')
32+
->disableOriginalConstructor()
33+
->setMethods([
34+
'setParent',
35+
'setBaseUrl',
36+
'addCustomAttribute',
37+
])
38+
->getMock();
39+
40+
$this->model = new Form(
41+
$this->context
42+
);
43+
}
44+
45+
protected function prepareContext()
46+
{
47+
$this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface')
48+
->getMock();
49+
50+
$this->context = $this->getMockBuilder('Magento\Backend\Block\Template\Context')
51+
->disableOriginalConstructor()
52+
->getMock();
53+
$this->context->expects($this->any())
54+
->method('getUrlBuilder')
55+
->willReturn($this->urlBuilder);
56+
}
57+
58+
public function testSetForm()
59+
{
60+
$baseUrl = 'base_url';
61+
$attributeKey = 'attribute_key';
62+
$attributeValue = 'attribute_value';
63+
64+
$this->dataForm->expects($this->once())
65+
->method('setParent')
66+
->with($this->model)
67+
->willReturnSelf();
68+
$this->dataForm->expects($this->once())
69+
->method('setBaseUrl')
70+
->with($baseUrl)
71+
->willReturnSelf();
72+
$this->dataForm->expects($this->once())
73+
->method('addCustomAttribute')
74+
->with($attributeKey, $attributeValue)
75+
->willReturnSelf();
76+
77+
$this->urlBuilder->expects($this->once())
78+
->method('getBaseUrl')
79+
->willReturn($baseUrl);
80+
81+
$this->model->setData('custom_attributes', [$attributeKey => $attributeValue]);
82+
$this->assertEquals($this->model, $this->model->setForm($this->dataForm));
83+
}
84+
85+
public function testSetFormNoCustomAttributes()
86+
{
87+
$baseUrl = 'base_url';
88+
89+
$this->dataForm->expects($this->once())
90+
->method('setParent')
91+
->with($this->model)
92+
->willReturnSelf();
93+
$this->dataForm->expects($this->once())
94+
->method('setBaseUrl')
95+
->with($baseUrl)
96+
->willReturnSelf();
97+
98+
$this->urlBuilder->expects($this->once())
99+
->method('getBaseUrl')
100+
->willReturn($baseUrl);
101+
102+
$this->assertEquals($this->model, $this->model->setForm($this->dataForm));
103+
}
104+
}

app/code/Magento/Bundle/view/adminhtml/templates/product/composite/fieldset/options/type/checkbox.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class="change-container-classname admin__control-checkbox checkbox bundle-option-<?php echo $_option->getId() ?> <?php if ($_option->getRequired()) echo 'validate-one-required-by-name' ?>"
3535
id="bundle-option-<?php echo $_option->getId() ?>-<?php echo $_selection->getSelectionId() ?>"
3636
type="checkbox"
37-
name="bundle_option[<?php echo $_option->getId() ?>]"
37+
name="bundle_option[<?php echo $_option->getId() ?>][<?php echo $_selection->getId() ?>]"
3838
<?php if ($block->isSelected($_selection)):?>
3939
<?php echo ' checked="checked"'; ?>
4040
<?php endif;?>

app/code/Magento/Bundle/view/adminhtml/templates/product/composite/fieldset/options/type/multi.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
price="<?php echo $block->getSelectionPrice($_selections[0]) ?>" />
2222
<?php else: ?>
2323
<select multiple="multiple" size="5" id="bundle-option-<?php echo $_option->getId() ?>"
24-
name="bundle_option[<?php echo $_option->getId() ?>]"
24+
name="bundle_option[<?php echo $_option->getId() ?>][]"
2525
class="admin__control-multiselect bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> multiselect change-container-classname"
2626
onchange="ProductConfigure.bundleControl.changeSelection(this)">
2727
<?php if(!$_option->getRequired()): ?>

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/multi.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<select multiple="multiple"
2525
size="5"
2626
id="bundle-option-<?php echo $_option->getId() ?>"
27-
name="bundle_option[<?php echo $_option->getId() ?>]"
27+
name="bundle_option[<?php echo $_option->getId() ?>][]"
2828
class="bundle-option-<?php echo $_option->getId() ?> multiselect product bundle option change-container-classname"
2929
<?php if ($_option->getRequired()) echo 'data-validate={required:true}' ?>>
3030
<?php if(!$_option->getRequired()): ?>

app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ define([
8383
elementName = $(element).attr('name'),
8484
elementValue = $(element).val();
8585
if ($(element).is('select[multiple]') && elementValue !== null) {
86+
if (elementName.substr(elementName.length - 2) == '[]') {
87+
elementName = elementName.substring(0, elementName.length - 2);
88+
}
8689
$.each(elementValue, function (key, option) {
8790
data[elementName + '[' + option + ']'] = option;
8891
});

dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ abstract class Grid extends Block
144144
*
145145
* @var string
146146
*/
147-
protected $rowTemplate = 'td[contains(text(),normalize-space("%s"))]';
147+
protected $rowTemplate = 'td[contains(.,normalize-space("%s"))]';
148148

149149
/**
150150
* Secondary part of row locator template for getRow() method with strict option

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Adminhtml/Product/Composite/Configure.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
*/
1515
class Configure extends \Magento\Catalog\Test\Block\Adminhtml\Product\Composite\Configure
1616
{
17-
/**
18-
* Option selector
19-
*
20-
* @var string
21-
*/
22-
protected $option = '//div[@class="composite-bundle"]//label[.="%option_name%"]//following-sibling::*//%selector%';
23-
2417
/**
2518
* Fill options for the product
2619
*
@@ -43,6 +36,8 @@ protected function prepareData(array $fields)
4336
{
4437
$productOptions = [];
4538
$checkoutData = $fields['checkout_data']['options'];
39+
$optionLocator = '//fieldset[contains(@class,"composite-bundle")]//label[.="%option_name%"]'
40+
. '//following-sibling::*//%selector%';
4641

4742
if (!empty($checkoutData['bundle_options'])) {
4843
foreach ($checkoutData['bundle_options'] as $key => $option) {
@@ -52,7 +47,7 @@ protected function prepareData(array $fields)
5247
$optionMapping[$type]['selector'] = str_replace(
5348
'%selector%',
5449
str_replace('%product_name%', $option['value']['name'], $optionMapping[$type]['selector']),
55-
str_replace('%option_name%', $option['title'], $this->option)
50+
str_replace('%option_name%', $option['title'], $optionLocator)
5651
);
5752

5853
$optionMapping[$type]['value'] = ($type == 'checkbox' || $type == 'radiobutton')

dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Constraint/AssertGroupedProductInCustomerWishlistOnBackendGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function prepareFilter(FixtureInterface $product)
2626
{
2727
$options = $this->prepareOptions($product);
2828

29-
return ['product_name' => $product->getName(), 'qty_from' => 1, 'qty_to' => 1, 'options' => $options];
29+
return ['product_name' => $product->getName(), 'options' => $options];
3030
}
3131

3232
/**

lib/internal/Magento/Framework/Data/Form/AbstractForm.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class AbstractForm extends \Magento\Framework\Object
4343
*/
4444
protected $_factoryCollection;
4545

46+
/**
47+
* @var array
48+
*/
49+
protected $customAttributes = [];
50+
4651
/**
4752
* @param Factory $factoryElement
4853
* @param CollectionFactory $factoryCollection
@@ -203,6 +208,7 @@ public function addColumn($elementId, $config)
203208
*
204209
* @param array $arrAttributes
205210
* @return array
211+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
206212
*/
207213
public function convertToArray(array $arrAttributes = [])
208214
{
@@ -214,4 +220,49 @@ public function convertToArray(array $arrAttributes = [])
214220
}
215221
return $res;
216222
}
223+
224+
/**
225+
* Add custom attribute
226+
*
227+
* @param string $key
228+
* @param mixed $value
229+
* @return $this
230+
*/
231+
public function addCustomAttribute($key, $value)
232+
{
233+
$this->customAttributes[$key] = $value;
234+
return $this;
235+
}
236+
237+
/**
238+
* Convert data into string with defined keys and values
239+
*
240+
* @param array $keys
241+
* @param string $valueSeparator
242+
* @param string $fieldSeparator
243+
* @param string $quote
244+
* @return string
245+
*/
246+
public function serialize($keys = [], $valueSeparator = '=', $fieldSeparator = ' ', $quote = '"')
247+
{
248+
$data = [];
249+
if (empty($keys)) {
250+
$keys = array_keys($this->_data);
251+
}
252+
253+
$customAttributes = array_filter($this->customAttributes);
254+
$keys = array_merge($keys, array_keys(array_diff($this->customAttributes, $customAttributes)));
255+
256+
foreach ($this->_data as $key => $value) {
257+
if (in_array($key, $keys)) {
258+
$data[] = $key . $valueSeparator . $quote . $value . $quote;
259+
}
260+
}
261+
262+
foreach ($customAttributes as $key => $value) {
263+
$data[] = $key . $valueSeparator . $quote . $value . $quote;
264+
}
265+
266+
return implode($fieldSeparator, $data);
267+
}
217268
}

0 commit comments

Comments
 (0)