Skip to content

Commit

Permalink
Merge pull request #1418 from magento-okapis/Okapis-PR-8-15
Browse files Browse the repository at this point in the history
[okapis] Bugfix PR
  • Loading branch information
pdohogne-magento authored Aug 16, 2017
2 parents e2473ec + 2cf6cc7 commit 6df4b3c
Show file tree
Hide file tree
Showing 29 changed files with 545 additions and 202 deletions.
16 changes: 13 additions & 3 deletions app/code/Magento/Backend/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,22 @@ public function getFormKey()
*
* @param string $moduleName Full module name
* @return boolean
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0
* version. Module output can still be enabled/disabled in configuration files. However, this functionality should
* not be used in future development. Module design should explicitly state dependencies to avoid requiring output
* disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity
* issues that will be addressed in future releases.
*/
public function isOutputEnabled($moduleName = null)
{
return true;
if ($moduleName === null) {
$moduleName = $this->getModuleName();
}

return !$this->_scopeConfig->isSetFlag(
'advanced/modules_disable_output/' . $moduleName,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public function testToHtml()
->getMock();
$eventManager->expects($this->exactly(2))->method('dispatch')->will($this->returnValue(true));

$scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
->setMethods(['getValue'])
->disableOriginalConstructor()->getMock();
$scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
->will($this->returnValue(false));

$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()
->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep'])
->getMock();
Expand Down Expand Up @@ -90,6 +96,8 @@ public function testToHtml()

$this->context->expects($this->once())->method('getEventManager')
->will($this->returnValue($eventManager));
$this->context->expects($this->once())->method('getScopeConfig')
->will($this->returnValue($scopeConfig));
$this->context->expects($this->once())->method('getLayout')
->will($this->returnValue($layout));
$this->context->expects($this->once())->method('getRequest')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ protected function generalGetProductCollection()
{
$this->eventManager->expects($this->exactly(2))->method('dispatch')
->will($this->returnValue(true));
$this->scopeConfig->expects($this->once())->method('getValue')->withAnyParameters()
->willReturn(false);
$this->cacheState->expects($this->atLeastOnce())->method('isEnabled')->withAnyParameters()
->willReturn(false);
$this->catalogConfig->expects($this->once())->method('getProductAttributes')
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public function getCurrencyRate()
*/
protected function _renderRangeLabel($fromPrice, $toPrice)
{
$fromPrice = empty($fromPrice) ? 0 : $fromPrice * $this->getCurrencyRate();
$toPrice = empty($toPrice) ? $toPrice : $toPrice * $this->getCurrencyRate();

$formattedFromPrice = $this->priceCurrency->format($fromPrice);
if ($toPrice === '') {
return __('%1 and above', $formattedFromPrice);
Expand Down Expand Up @@ -261,10 +264,7 @@ private function prepareData($key, $count)
if ($to == '*') {
$to = $this->getTo($to);
}
$label = $this->_renderRangeLabel(
empty($from) ? 0 : $from * $this->getCurrencyRate(),
empty($to) ? $to : $to * $this->getCurrencyRate()
);
$label = $this->_renderRangeLabel($from, $to);
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();

$data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ function ($field) use ($requestVar, $priceId) {
->with('price')
->will($this->returnSelf());

$this->target->setCurrencyRate(1);
$this->target->apply($this->request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function testToHtml()
$childNameTwo = 'child.2';
$childNames = [$childNameOne, $childNameTwo];

$this->scopeConfigMock->expects($this->once())
->method('getValue')
->willReturn(false);

/**
* @var Item|\PHPUnit_Framework_MockObject_MockObject $itemMock
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,37 @@
* on the store settings page.
*
* @method \Magento\Config\Block\System\Config\Form getForm()
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0
* version. Module output can still be enabled/disabled in configuration files. However, this functionality should
* not be used in future development. Module design should explicitly state dependencies to avoid requiring output
* disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity
* issues that will be addressed in future releases.
* @api
* @since 100.0.2
*/
class DisableOutput extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
* @var \Magento\Framework\DataObject
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
*/
protected $_dummyElement;

/**
* @var \Magento\Config\Block\System\Config\Form\Field
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
*/
protected $_fieldRenderer;

/**
* @var array
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
*/
protected $_values;

/**
* @var \Magento\Framework\Module\ModuleListInterface
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
*/
protected $_moduleList;

Expand All @@ -60,7 +64,11 @@ public function __construct(

/**
* {@inheritdoc}
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0 Magento does not support disabling/enabling modules output from the Admin Panel since 2.2.0
* version. Module output can still be enabled/disabled in configuration files. However, this functionality should
* not be used in future development. Module design should explicitly state dependencies to avoid requiring output
* disabling. This functionality will temporarily be kept in Magento core, as there are unresolved modularity
* issues that will be addressed in future releases.
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
Expand Down Expand Up @@ -89,7 +97,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
}

/**
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
* @return \Magento\Framework\DataObject
*/
protected function _getDummyElement()
Expand All @@ -101,7 +109,7 @@ protected function _getDummyElement()
}

/**
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
* @return \Magento\Config\Block\System\Config\Form\Field
*/
protected function _getFieldRenderer()
Expand All @@ -115,7 +123,7 @@ protected function _getFieldRenderer()
}

/**
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
* @return array
*/
protected function _getValues()
Expand All @@ -132,7 +140,7 @@ protected function _getValues()
/**
* @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
* @param string $moduleName
* @deprecated 100.2.0 Magento does not support custom disabling/enabling module output since 2.2.0 version
* @deprecated 100.2.0
* @return mixed
*/
protected function _getFieldHtml($fieldset, $moduleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated because \Magento\Config\Block\System\Config\Form\Fieldset\Modules\DisableOutput is deprecated
*/
class DisableOutputTest extends \PHPUnit\Framework\TestCase
{
Expand Down
162 changes: 110 additions & 52 deletions app/code/Magento/Payment/Test/Unit/Block/Info/SubstitutionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\Payment\Test\Unit\Block\Info;

/**
Expand Down Expand Up @@ -31,23 +34,71 @@ class SubstitutionTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$context = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
->disableOriginalConstructor()
->setMethods(['getLayout', 'getEventManager', 'getScopeConfig'])
->getMock();
$context->expects($this->any())
->method('getLayout')
->willReturn($this->layout);
$context->expects($this->any())->method('getEventManager')
->willReturn($eventManager);

$this->layout = $this->getMockBuilder(
\Magento\Framework\View\LayoutInterface::class
)->disableOriginalConstructor()->setMethods(
[]
)->getMock();

$eventManager = $this->getMockBuilder(
\Magento\Framework\Event\ManagerInterface::class
)->disableOriginalConstructor()->setMethods(
[]
)->getMock();

$scopeConfig = $this->getMockBuilder(
\Magento\Framework\App\Config\ScopeConfigInterface::class
)->disableOriginalConstructor()->setMethods(
[]
)->getMock();
$scopeConfig->expects(
$this->any()
)->method(
'getValue'
)->with(
$this->stringContains(
'advanced/modules_disable_output/'
),
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)->will(
$this->returnValue(
false
)
);

$context = $this->getMockBuilder(
\Magento\Framework\View\Element\Template\Context::class
)->disableOriginalConstructor()->setMethods(
['getLayout', 'getEventManager', 'getScopeConfig']
)->getMock();
$context->expects(
$this->any()
)->method(
'getLayout'
)->will(
$this->returnValue(
$this->layout
)
);
$context->expects(
$this->any()
)->method(
'getEventManager'
)->will(
$this->returnValue(
$eventManager
)
);
$context->expects(
$this->any()
)->method(
'getScopeConfig'
)->will(
$this->returnValue(
$scopeConfig
)
);

$this->block = $this->objectManager->getObject(
\Magento\Payment\Block\Info\Substitution::class,
Expand All @@ -62,45 +113,52 @@ protected function setUp()

public function testBeforeToHtml()
{
$abstractBlock = $this->getMockBuilder(\Magento\Framework\View\Element\AbstractBlock::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$childAbstractBlock = clone $abstractBlock;

$abstractBlock->expects($this->any())
->method('getParentBlock')
->willReturn($childAbstractBlock);
$this->layout->expects($this->any())
->method('getParentName')
->willReturn('parentName');
$this->layout->expects($this->any())
->method('getBlock')
->willReturn($abstractBlock);

$infoMock = $this->getMockBuilder(\Magento\Payment\Model\Info::class)
->disableOriginalConstructor()
->getMock();
$methodMock = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
->getMockForAbstractClass();
$infoMock->expects($this->once())
->method('getMethodInstance')
->willReturn($methodMock);
$abstractBlock = $this->getMockBuilder(
\Magento\Framework\View\Element\AbstractBlock::class
)->disableOriginalConstructor()->setMethods(
[]
)->getMock();
$childAbstractBlock = clone($abstractBlock);

$abstractBlock->expects($this->any())->method('getParentBlock')->will($this->returnValue($childAbstractBlock));

$this->layout->expects($this->any())->method('getParentName')->will($this->returnValue('parentName'));
$this->layout->expects($this->any())->method('getBlock')->will($this->returnValue($abstractBlock));

$infoMock = $this->getMockBuilder(
\Magento\Payment\Model\Info::class
)->disableOriginalConstructor()->setMethods(
[]
)->getMock();
$methodMock = $this->getMockBuilder(
\Magento\Payment\Model\MethodInterface::class
)->getMockForAbstractClass();
$infoMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodMock));
$this->block->setInfo($infoMock);

$fakeBlock = new \StdClass();
$this->layout->expects($this->any())
->method('createBlock')
->with(
\Magento\Framework\View\Element\Template::class,
'',
['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']]
)->willReturn($fakeBlock);

$childAbstractBlock->expects($this->any())
->method('setChild')
->with('order_payment_additional', $fakeBlock);
$this->layout->expects(
$this->any()
)->method(
'createBlock'
)->with(
\Magento\Framework\View\Element\Template::class,
'',
['data' => ['method' => $methodMock, 'template' => 'Magento_Payment::info/substitution.phtml']]
)->will(
$this->returnValue(
$fakeBlock
)
);

$childAbstractBlock->expects(
$this->any()
)->method(
'setChild'
)->with(
'order_payment_additional',
$fakeBlock
);

$this->block->toHtml();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ public function testToHtml()
->expects($this->at(1))
->method('dispatch')
->with('view_block_abstract_to_html_after', ['block' => $this->block, 'transport' => $transport]);
$this->scopeConfig
->expects($this->once())
->method('getValue')
->willReturn(false);
$this->urlBuilder->expects($this->once())->method('getUrl')->with('paypal/billing_agreement/startWizard', []);
$this->block->toHtml();
}
Expand Down
Loading

0 comments on commit 6df4b3c

Please sign in to comment.