Skip to content

Commit

Permalink
[2.3-develop][Forwardport] #7822 Empty Checkout Agreement Edit Form w…
Browse files Browse the repository at this point in the history
…hen Single Store Mode is enabled

Forward port of #7822 Empty Checkout Agreement Edit Form when Single Store Mode is enabled to 2.3-develop
  • Loading branch information
gwharton committed May 8, 2018
1 parent b2eb795 commit d61fe1d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,13 @@ public function getElementHtml()
$html .= '<label class="addbefore" for="' . $htmlId . '">' . $beforeElementHtml . '</label>';
}

$html .= '<input id="' . $htmlId . '" name="' . $this->getName() . '" ' . $this->_getUiId() . ' value="' .
$this->getEscapedValue() . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>';
if (is_array($this->getValue())) {
foreach ($this->getValue() as $value) {
$html .= $this->getHtmlForInputByValue($this->_escape($value));
}
} else {
$html .= $this->getHtmlForInputByValue($this->getEscapedValue());
}

$afterElementJs = $this->getAfterElementJs();
if ($afterElementJs) {
Expand Down Expand Up @@ -574,4 +579,17 @@ public function isLocked()
{
return $this->getData($this->lockHtmlAttribute) == 1;
}

/**
* Get input html by sting value.
*
* @param string|null $value
*
* @return string
*/
private function getHtmlForInputByValue($value)
{
return '<input id="' . $this->getHtmlId() . '" name="' . $this->getName() . '" ' . $this->_getUiId()
. ' value="' . $value . '" ' . $this->serialize($this->getHtmlAttributes()) . '/>';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\Test\Unit\Data\Form\Element;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Test for \Magento\Framework\Data\Form\Element\Hidden.
*/
class HiddenTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\Data\Form\Element\Hidden
*/
private $element;

protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->element = $objectManager->getObject(\Magento\Framework\Data\Form\Element\Hidden::class);
}

/**
* @param mixed $value
*
* @dataProvider getElementHtmlDataProvider
*/
public function testGetElementHtml($value)
{
$form = $this->createMock(\Magento\Framework\Data\Form::class);
$this->element->setForm($form);
$this->element->setValue($value);
$html = $this->element->getElementHtml();

if (is_array($value)) {
foreach ($value as $item) {
$this->assertContains($item, $html);
}
} else {
$this->assertContains($value, $html);
}
}

public function getElementHtmlDataProvider()
{
return [
['some_value'],
['store_ids[]' => ['1', '2']],
];
}
}

0 comments on commit d61fe1d

Please sign in to comment.