Skip to content

Commit

Permalink
Merge pull request #714 from magento-tango/new_pr_bugs
Browse files Browse the repository at this point in the history
[Tango] Bug Fixes
  • Loading branch information
Korshenko, Olexii(okorshenko) committed Oct 12, 2015
2 parents 4d5990a + dcb8721 commit fa9c569
Show file tree
Hide file tree
Showing 25 changed files with 994 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public function getColumn()
public function render(DataObject $row)
{
if ($this->getColumn()->getEditable()) {
$value = $this->_getValue($row);
return '<div class="admin__grid-control">' .
'<span class="admin__grid-control-value">' . $value . '</span>' .
$this->_getInputValueElement($row) . '</div>' ;
$result = '<div class="admin__grid-control">';
$result .= $this->getColumn()->getEditOnly() ? ''
: '<span class="admin__grid-control-value">' . $this->_getValue($row) . '</span>';

return $result . $this->_getInputValueElement($row) . '</div>' ;
}
return $this->_getValue($row);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Renderer;

class AbstractRendererTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Backend\Block\Widget\Grid\Column|\PHPUnit_Framework_MockObject_MockObject
*/
protected $columnMock;

/**
* @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject
*/
protected $dataObjectMock;

/**
* @var \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
*/
protected $renderer;

/**
* @return void
*/
protected function setUp()
{
$this->dataObjectMock = $this->getMock('Magento\Framework\DataObject', ['getData'], [], '', false);
$this->columnMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column')
->disableOriginalConstructor()
->setMethods(['getEditable', 'getIndex', 'getEditOnly', 'getId'])
->getMock();
$this->renderer = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer')
->disableOriginalConstructor()
->setMethods(null)
->getMock();
}

/**
* @param bool $editable
* @param bool $onlyEdit
* @param string $expectedResult
* @return void
* @dataProvider renderDataProvider
*/
public function testRender($editable, $onlyEdit, $expectedResult)
{
$value = 'some value';
$keyValue = 'key';

$this->columnMock->expects($this->once())
->method('getEditable')
->willReturn($editable);
$this->columnMock->expects($this->any())
->method('getEditOnly')
->willReturn($onlyEdit);
$this->columnMock->expects($this->any())
->method('getIndex')
->willReturn($keyValue);
$this->columnMock->expects($this->any())
->method('getId')
->willReturn('test');
$this->dataObjectMock->expects($this->any())
->method('getData')
->with($keyValue)
->willReturn($value);
$this->renderer->setColumn($this->columnMock);

$this->assertEquals($expectedResult, $this->renderer->render($this->dataObjectMock));
}

/**
* @return array
*/
public function renderDataProvider()
{
return [
[
'editable' => false,
'onlyEdit' => false,
'expectedResult' => 'some value'
],
[
'editable' => false,
'onlyEdit' => true,
'expectedResult' => 'some value'
],
[
'editable' => true,
'onlyEdit' => false,
'expectedResult' => '<div class="admin__grid-control">'
. '<span class="admin__grid-control-value">some value</span>'
. '<input type="text" class="input-text " name="test" value="some value"/>'
. '</div>'
],
[
'editable' => true,
'onlyEdit' => true,
'expectedResult' => '<div class="admin__grid-control">'
. '<input type="text" class="input-text " name="test" value="some value"/>'
. '</div>'
],
];
}
}
22 changes: 21 additions & 1 deletion app/code/Magento/Cms/Controller/Adminhtml/Page/InlineEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Cms\Api\Data\PageInterface;

/**
* Cms page grid inline edit controller
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class InlineEdit extends \Magento\Backend\App\Action
{
/** @var PostDataProcessor */
Expand Down Expand Up @@ -63,7 +68,8 @@ public function execute()
try {
$pageData = $this->dataProcessor->filter($postItems[$pageId]);
$this->validatePost($pageData, $page, $error, $messages);
$page->setData(array_merge($page->getData(), $pageData));
$extendedPageData = $page->getData();
$this->setCmsPageData($page, $extendedPageData, $pageData);
$this->pageRepository->save($page);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$messages[] = $this->getErrorWithPageId($page, $e->getMessage());
Expand Down Expand Up @@ -116,4 +122,18 @@ protected function getErrorWithPageId(PageInterface $page, $errorText)
{
return '[Page ID: ' . $page->getId() . '] ' . $errorText;
}

/**
* Set cms page data
*
* @param \Magento\Cms\Model\Page $page
* @param array $extendedPageData
* @param array $pageData
* @return $this
*/
public function setCmsPageData(\Magento\Cms\Model\Page $page, array $extendedPageData, array $pageData)
{
$page->setData(array_merge($page->getData(), $extendedPageData, $pageData));
return $this;
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Cms/Model/Page/Source/IsActive.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(\Magento\Cms\Model\Page $cmsPage)
*/
public function toOptionArray()
{
$options[] = ['label' => '', 'value' => ''];
$availableOptions = $this->cmsPage->getAvailableStatuses();
$options = [];
foreach ($availableOptions as $key => $value) {
$options[] = [
'label' => $value,
Expand Down
20 changes: 20 additions & 0 deletions app/code/Magento/Cms/Model/Page/Source/IsActiveFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Page\Source;

/**
* Is active filter source
*/
class IsActiveFilter extends IsActive
{
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return array_merge([['label' => '', 'value' => '']], parent::toOptionArray());
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Cms/Model/Page/Source/PageLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public function toOptionArray()
if ($this->options !== null) {
return $this->options;
}
$options[] = ['label' => '', 'value' => ''];

$configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
$options = [];
foreach ($configOptions as $key => $value) {
$options[] = [
'label' => $value,
Expand Down
20 changes: 20 additions & 0 deletions app/code/Magento/Cms/Model/Page/Source/PageLayoutFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Page\Source;

/**
* Page layout filter source
*/
class PageLayoutFilter extends PageLayout
{
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return array_merge([['label' => '', 'value' => '']], parent::toOptionArray());
}
}
4 changes: 1 addition & 3 deletions app/code/Magento/Cms/Model/Page/Source/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function __construct(ListInterface $themeList)
*/
public function toOptionArray()
{
$options[] = ['label' => '', 'value' => ''];
return $options + $this->themeList->getLabels();

return $this->themeList->getLabels();
}
}
20 changes: 20 additions & 0 deletions app/code/Magento/Cms/Model/Page/Source/ThemeFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Page\Source;

/**
* Theme filter source
*/
class ThemeFilter extends Theme
{
/**
* {@inheritdoc}
*/
public function toOptionArray()
{
return array_merge([['label' => '', 'value' => '']], parent::toOptionArray());
}
}
Loading

0 comments on commit fa9c569

Please sign in to comment.