Skip to content

Commit

Permalink
Merge remote-tracking branch 'mainline-ce/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
marcozheng committed Jun 3, 2015
2 parents d1f5b9f + 4372961 commit 4941412
Show file tree
Hide file tree
Showing 106 changed files with 2,578 additions and 677 deletions.
19 changes: 10 additions & 9 deletions app/code/Magento/Backend/App/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ abstract class AbstractAction extends \Magento\Framework\App\Action\Action
*/
const SESSION_NAMESPACE = 'adminhtml';

/**
* Authorization level of a basic admin session
*/
const ADMIN_RESOURCE = 'Magento_Backend::admin';

/**
* Array of actions which can be processed without secret key validation
*
Expand Down Expand Up @@ -97,7 +102,7 @@ public function __construct(Action\Context $context)
*/
protected function _isAllowed()
{
return true;
return $this->_authorization->isAllowed(self::ADMIN_RESOURCE);
}

/**
Expand Down Expand Up @@ -228,14 +233,10 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
*/
protected function _isUrlChecked()
{
return !$this->_actionFlag->get(
'',
self::FLAG_IS_URLS_CHECKED
) && !$this->getRequest()->getParam(
'forwarded'
) && !$this->_getSession()->getIsUrlNotice(
true
) && !$this->_canUseBaseUrl;
return !$this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED)
&& !$this->getRequest()->isForwarded()
&& !$this->_getSession()->getIsUrlNotice(true)
&& !$this->_canUseBaseUrl;
}

/**
Expand Down
53 changes: 16 additions & 37 deletions app/code/Magento/Backend/App/Action/Plugin/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,46 +147,25 @@ protected function _processNotLoggedInUser(\Magento\Framework\App\RequestInterfa
if ($request->getPost('login') && $this->_performLogin($request)) {
$isRedirectNeeded = $this->_redirectIfNeededAfterLogin($request);
}
if (!$isRedirectNeeded && !$request->getParam('forwarded')) {
if (!$isRedirectNeeded && !$request->isForwarded()) {
if ($request->getParam('isIframe')) {
$request->setParam(
'forwarded',
true
)->setRouteName(
'adminhtml'
)->setControllerName(
'auth'
)->setActionName(
'deniedIframe'
)->setDispatched(
false
);
$request->setForwarded(true)
->setRouteName('adminhtml')
->setControllerName('auth')
->setActionName('deniedIframe')
->setDispatched(false);
} elseif ($request->getParam('isAjax')) {
$request->setParam(
'forwarded',
true
)->setRouteName(
'adminhtml'
)->setControllerName(
'auth'
)->setActionName(
'deniedJson'
)->setDispatched(
false
);
$request->setForwarded(true)
->setRouteName('adminhtml')
->setControllerName('auth')
->setActionName('deniedJson')
->setDispatched(false);
} else {
$request->setParam(
'forwarded',
true
)->setRouteName(
'adminhtml'
)->setControllerName(
'auth'
)->setActionName(
'login'
)->setDispatched(
false
);
$request->setForwarded(true)
->setRouteName('adminhtml')
->setControllerName('auth')
->setActionName('login')
->setDispatched(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,78 @@ public function testAroundDispatchProlongStorage()

$this->assertEquals($expectedResult, $this->plugin->aroundDispatch($subject, $proceed, $request));
}

/**
* Calls aroundDispatch to access protected method _processNotLoggedInUser
*
* Data provider supplies different possibilities of request parameters and properties
* @dataProvider processNotLoggedInUserDataProvider
*/
public function testProcessNotLoggedInUser($isIFrameParam, $isAjaxParam, $isForwardedFlag)
{
$subject = $this->getMockBuilder('Magento\Backend\Controller\Adminhtml\Index')
->disableOriginalConstructor()
->getMock();
$request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
->disableOriginalConstructor()
->getMock();
$storage = $this->getMockBuilder('Magento\Backend\Model\Auth\Session')
->disableOriginalConstructor()
->getMock();

// Stubs to control the flow of execution in aroundDispatch
$this->auth->expects($this->any())->method('getAuthStorage')->will($this->returnValue($storage));
$request->expects($this->once())->method('getActionName')->will($this->returnValue('non/open/action/name'));
$this->auth->expects($this->any())->method('getUser')->willReturn(false);
$this->auth->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
$request->expects($this->any())->method('getPost')->willReturn(false);

// Test cases and expectations based on provided data
$request->expects($this->once())->method('isForwarded')->willReturn($isForwardedFlag);
$getParamCalls = 0;
$actionName = '';

// If forwarded flag is set, getParam never gets called
if (!$isForwardedFlag) {
if ($isIFrameParam) {
$getParamCalls = 1;
$actionName = 'deniedIframe';
} else if ($isAjaxParam) {
$getParamCalls = 2;
$actionName = 'deniedJson';
} else {
$getParamCalls = 2;
$actionName = 'login';
}
}

$requestParams = [
['isIframe', null, $isIFrameParam],
['isAjax', null, $isAjaxParam]
];

$setterCalls = $isForwardedFlag ? 0 : 1;
$request->expects($this->exactly($getParamCalls))->method('getParam')->willReturnMap($requestParams);
$request->expects($this->exactly($setterCalls))->method('setForwarded')->with(true)->willReturnSelf();
$request->expects($this->exactly($setterCalls))->method('setRouteName')->with('adminhtml')->willReturnSelf();
$request->expects($this->exactly($setterCalls))->method('setControllerName')->with('auth')->willReturnSelf();
$request->expects($this->exactly($setterCalls))->method('setActionName')->with($actionName)->willReturnSelf();
$request->expects($this->exactly($setterCalls))->method('setDispatched')->with(false)->willReturnSelf();

$expectedResult = 'expectedResult';
$proceed = function ($request) use ($expectedResult) {
return $expectedResult;
};
$this->assertEquals($expectedResult, $this->plugin->aroundDispatch($subject, $proceed, $request));
}

public function processNotLoggedInUserDataProvider()
{
return [
'iFrame' => [true, false, false],
'Ajax' => [false, true, false],
'Neither iFrame nor Ajax' => [false, false, false],
'Forwarded request' => [true, true, true]
];
}
}
18 changes: 16 additions & 2 deletions app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\Pricing\Amount\AmountInterface;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
use Magento\Bundle\Model\Product\Price;

/**
* Bundle product regular price model
Expand Down Expand Up @@ -48,7 +50,13 @@ public function __construct(
public function getAmount()
{
if (null === $this->amount) {
$this->amount = $this->calculator->getMinRegularAmount($this->getValue(), $this->product);
$price = $this->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(true);
}
$this->amount = $this->calculator->getMinRegularAmount($price, $this->product);
}
return $this->amount;
}
Expand All @@ -61,7 +69,13 @@ public function getAmount()
public function getMaximalPrice()
{
if (null === $this->maximalPrice) {
$this->maximalPrice = $this->calculator->getMaxRegularAmount($this->getValue(), $this->product);
$price = $this->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(false);
}
$this->maximalPrice = $this->calculator->getMaxRegularAmount($price, $this->product);
}
return $this->maximalPrice;
}
Expand Down
18 changes: 16 additions & 2 deletions app/code/Magento/Bundle/Pricing/Price/FinalPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use Magento\Catalog\Model\Product;
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
use Magento\Bundle\Model\Product\Price;

/**
* Final price model
Expand Down Expand Up @@ -68,7 +70,13 @@ public function getValue()
public function getMaximalPrice()
{
if (!$this->maximalPrice) {
$this->maximalPrice = $this->calculator->getMaxAmount($this->getBasePrice()->getValue(), $this->product);
$price = $this->getBasePrice()->getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(false);
}
$this->maximalPrice = $this->calculator->getMaxAmount($price, $this->product);
}
return $this->maximalPrice;
}
Expand All @@ -91,7 +99,13 @@ public function getMinimalPrice()
public function getAmount()
{
if (!$this->minimalPrice) {
$this->minimalPrice = $this->calculator->getAmount(parent::getValue(), $this->product);
$price = parent::getValue();
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
$price += $customOptionPrice->getCustomOptionRange(true);
}
$this->minimalPrice = $this->calculator->getAmount($price, $this->product);
}
return $this->minimalPrice;
}
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Bundle/Pricing/Price/TierPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Bundle\Pricing\Price;

use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\Framework\Pricing\Amount\AmountInterface;

/**
* Bundle tier prices model
Expand Down Expand Up @@ -89,4 +90,13 @@ public function isPercentageDiscount()
{
return true;
}

/**
* @param AmountInterface $amount
* @return float
*/
public function getSavePercent(AmountInterface $amount)
{
return round($amount->getBaseAmount());
}
}
Loading

0 comments on commit 4941412

Please sign in to comment.