Skip to content

Commit

Permalink
merge magento/2.2-develop into magento-helix/MAGETWO-80811
Browse files Browse the repository at this point in the history
  • Loading branch information
Magento CICD authored Oct 9, 2017
2 parents 15d9280 + 9304040 commit 05c5ce7
Show file tree
Hide file tree
Showing 33 changed files with 921 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
$resultPage->setStatusHeader(404, '1.1', 'Forbidden');
$resultPage->setStatusHeader(404, '1.1', 'Not Found');
$resultPage->setHeader('Status', '404 File not found');
$resultPage->addHandle('adminhtml_noroute');
return $resultPage;
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Layout\Generator\Block">
<arguments>
<argument name="defaultClass" xsi:type="string">Magento\Backend\Block\Template</argument>
</arguments>
</type>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/Bundle/Model/OptionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function save(
}
} else {
if (!$existingOption->getOptionId()) {
throw new NoSuchEntityException('Requested option doesn\'t exist');
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
}

$option->setData(array_merge($existingOption->getData(), $option->getData()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ define([
regionInput.removeClass('required-entry');
}

regionList.removeClass('required-entry').hide();
regionList.removeClass('required-entry').prop('disabled', 'disabled').hide();
regionInput.show();
label.attr('for', regionInput.attr('id'));
}
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Review/Block/Product/ReviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function getReviewsSummaryHtml(
$templateType = self::DEFAULT_VIEW,
$displayIfNoReviews = false
) {
if (!$product->getRatingSummary()) {
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
}

if (!$product->getRatingSummary() && !$displayIfNoReviews) {
return '';
}
Expand All @@ -68,9 +72,6 @@ public function getReviewsSummaryHtml(

$this->setDisplayIfEmpty($displayIfNoReviews);

if (!$product->getRatingSummary()) {
$this->_reviewFactory->create()->getEntitySummary($product, $this->_storeManager->getStore()->getId());
}
$this->setProduct($product);

return $this->toHtml();
Expand Down
80 changes: 42 additions & 38 deletions app/code/Magento/Search/view/frontend/web/form-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,46 +286,50 @@ define([
$.getJSON(this.options.url, {
q: value
}, $.proxy(function (data) {
$.each(data, function (index, element) {
var html;

element.index = index;
html = template({
data: element
if (data.length) {
$.each(data, function (index, element) {
var html;

element.index = index;
html = template({
data: element
});
dropdown.append(html);
});
dropdown.append(html);
});
this.responseList.indexList = this.autoComplete.html(dropdown)
.css(clonePosition)
.show()
.find(this.options.responseFieldElements + ':visible');

this._resetResponseList(false);
this.element.removeAttr('aria-activedescendant');

if (this.responseList.indexList.length) {
this._updateAriaHasPopup(true);
} else {
this._updateAriaHasPopup(false);
}

this.responseList.indexList
.on('click', function (e) {
this.responseList.selected = $(e.currentTarget);
this.searchForm.trigger('submit');
}.bind(this))
.on('mouseenter mouseleave', function (e) {
this.responseList.indexList.removeClass(this.options.selectClass);
$(e.target).addClass(this.options.selectClass);
this.responseList.selected = $(e.target);
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
}.bind(this))
.on('mouseout', function (e) {
if (!this._getLastElement() && this._getLastElement().hasClass(this.options.selectClass)) {
$(e.target).removeClass(this.options.selectClass);
this._resetResponseList(false);
}
}.bind(this));
this.responseList.indexList = this.autoComplete.html(dropdown)
.css(clonePosition)
.show()
.find(this.options.responseFieldElements + ':visible');

this._resetResponseList(false);
this.element.removeAttr('aria-activedescendant');

if (this.responseList.indexList.length) {
this._updateAriaHasPopup(true);
} else {
this._updateAriaHasPopup(false);
}

this.responseList.indexList
.on('click', function (e) {
this.responseList.selected = $(e.currentTarget);
this.searchForm.trigger('submit');
}.bind(this))
.on('mouseenter mouseleave', function (e) {
this.responseList.indexList.removeClass(this.options.selectClass);
$(e.target).addClass(this.options.selectClass);
this.responseList.selected = $(e.target);
this.element.attr('aria-activedescendant', $(e.target).attr('id'));
}.bind(this))
.on('mouseout', function (e) {
if (!this._getLastElement() &&
this._getLastElement().hasClass(this.options.selectClass)) {
$(e.target).removeClass(this.options.selectClass);
this._resetResponseList(false);
}
}.bind(this));
}
}, this));
} else {
this._resetResponseList(true);
Expand Down
83 changes: 78 additions & 5 deletions app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,56 @@

use Magento\Ui\Controller\Adminhtml\AbstractAction;
use Magento\Framework\View\Element\UiComponentInterface;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Element\UiComponentFactory;
use Psr\Log\LoggerInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Controller\Result\JsonFactory;

class Render extends AbstractAction
{
/**
* @var JsonFactory
*/
private $resultJsonFactory;

/**
* @var Escaper
*/
private $escaper;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param Context $context
* @param UiComponentFactory $factory
* @param JsonFactory|null $resultJsonFactory
* @param Escaper|null $escaper
* @param LoggerInterface|null $logger
*/
public function __construct(
Context $context,
UiComponentFactory $factory,
JsonFactory $resultJsonFactory = null,
Escaper $escaper = null,
LoggerInterface $logger = null
) {
parent::__construct($context, $factory);
$this->resultJsonFactory = $resultJsonFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Controller\Result\JsonFactory::class);
$this->escaper = $escaper ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Escaper::class);
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Psr\Log\LoggerInterface::class);
}

/**
* Action for AJAX request
*
* @return void
* @return void|\Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
Expand All @@ -22,10 +65,40 @@ public function execute()
return;
}

$component = $this->factory->create($this->_request->getParam('namespace'));
if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) {
$this->prepareComponent($component);
$this->_response->appendBody((string) $component->render());
try {
$component = $this->factory->create($this->_request->getParam('namespace'));
if ($this->validateAclResource($component->getContext()->getDataProvider()->getConfigData())) {
$this->prepareComponent($component);
$this->_response->appendBody((string) $component->render());
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->logger->critical($e);
$result = [
'error' => $this->escaper->escapeHtml($e->getMessage()),
'errorcode' => $this->escaper->escapeHtml($e->getCode())
];
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();
$resultJson->setStatusHeader(
\Zend\Http\Response::STATUS_CODE_400,
\Zend\Http\AbstractMessage::VERSION_11,
'Bad Request'
);
return $resultJson->setData($result);
} catch (\Exception $e) {
$this->logger->critical($e);
$result = [
'error' => _('UI component could not be rendered because of system exception'),
'errorcode' => $this->escaper->escapeHtml($e->getCode())
];
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();
$resultJson->setStatusHeader(
\Zend\Http\Response::STATUS_CODE_400,
\Zend\Http\AbstractMessage::VERSION_11,
'Bad Request'
);
return $resultJson->setData($result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
namespace Magento\Ui\Test\Unit\Controller\Adminhtml\Index;

use \Magento\Ui\Controller\Adminhtml\Index\Render;
use Magento\Ui\Controller\Adminhtml\Index\Render;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand All @@ -17,6 +18,11 @@ class RenderTest extends \PHPUnit\Framework\TestCase
*/
private $render;

/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -73,6 +79,16 @@ class RenderTest extends \PHPUnit\Framework\TestCase
*/
private $uiComponentMock;

/**
* @var \Magento\Framework\Controller\Result\JsonFactory|\PHPUnit_Framework_MockObject_MockObject
*/
private $resultJsonFactoryMock;

/**
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;

protected function setUp()
{
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
Expand Down Expand Up @@ -114,6 +130,14 @@ protected function setUp()
['render']
);

$this->resultJsonFactoryMock = $this->getMockBuilder(
\Magento\Framework\Controller\Result\JsonFactory::class
)
->disableOriginalConstructor()
->getMock();

$this->loggerMock = $this->getMockForAbstractClass(\Psr\Log\LoggerInterface::class);

$this->contextMock->expects($this->any())
->method('getRequest')
->willReturn($this->requestMock);
Expand All @@ -136,7 +160,70 @@ protected function setUp()
->method('getDataProvider')
->willReturn($this->dataProviderMock);

$this->render = new Render($this->contextMock, $this->uiFactoryMock);
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->render = $this->objectManagerHelper->getObject(
\Magento\Ui\Controller\Adminhtml\Index\Render::class,
[
'context' => $this->contextMock,
'factory' => $this->uiFactoryMock,
'resultJsonFactory' => $this->resultJsonFactoryMock,
'logger' => $this->loggerMock
]
);
}

public function testExecuteAjaxRequestException()
{
$name = 'test-name';
$renderedData = '<html>data</html>';

$this->requestMock->expects($this->any())
->method('getParam')
->with('namespace')
->willReturn($name);
$this->requestMock->expects($this->any())
->method('getParams')
->willReturn([]);
$this->responseMock->expects($this->once())
->method('appendBody')
->willThrowException(new \Exception('exception'));

$jsonResultMock = $this->getMockBuilder(\Magento\Framework\Controller\Result\Json::class)
->disableOriginalConstructor()
->setMethods(['setData'])
->getMock();

$this->resultJsonFactoryMock->expects($this->once())
->method('create')
->willReturn($jsonResultMock);

$jsonResultMock->expects($this->once())
->method('setData')
->willReturnSelf();

$this->loggerMock->expects($this->once())
->method('critical')
->willReturnSelf();

$this->dataProviderMock->expects($this->once())
->method('getConfigData')
->willReturn([]);

$this->uiComponentMock->expects($this->once())
->method('render')
->willReturn($renderedData);
$this->uiComponentMock->expects($this->once())
->method('getChildComponents')
->willReturn([]);
$this->uiComponentMock->expects($this->once())
->method('getContext')
->willReturn($this->uiComponentContextMock);
$this->uiFactoryMock->expects($this->once())
->method('create')
->willReturn($this->uiComponentMock);

$this->render->executeAjaxRequest();
}

public function testExecuteAjaxRequest()
Expand Down
Loading

0 comments on commit 05c5ce7

Please sign in to comment.