Skip to content

Commit

Permalink
Merge pull request #252 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Bug fixes
  • Loading branch information
AndriyNasinnyk committed Apr 24, 2015
2 parents a3509e1 + 3d57de0 commit 385f475
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 28 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Customer/Model/Resource/GroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function getList(SearchCriteriaInterface $searchCriteria)

/** @var \Magento\Customer\Model\Resource\Group\Collection $collection */
$collection = $this->groupFactory->create()->getCollection();
$collection->addTaxClass();

//Add filters from root filter group to the collection
/** @var FilterGroup $group */
Expand Down Expand Up @@ -234,6 +235,8 @@ protected function translateField($field)
return 'customer_group_code';
case GroupInterface::ID:
return 'customer_group_id';
case GroupInterface::TAX_CLASS_NAME:
return 'class_name';
default:
return $field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function testGetCurrentStatus($status, $lastLoginAt, $lastVisitAt, $lastL
'customer/online_customers/online_minutes_interval',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
->willReturn(60); //TODO: it's value mocked because unit tests run data providers before all testsuite
->willReturn(240); //TODO: it's value mocked because unit tests run data providers before all testsuite

$this->customerLog->expects($this->any())->method('getLastLoginAt')->willReturn($lastLoginAt);
$this->customerLog->expects($this->any())->method('getLastVisitAt')->willReturn($lastVisitAt);
Expand Down
31 changes: 28 additions & 3 deletions app/code/Magento/Wishlist/Controller/Index/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class Cart extends Action\Action implements IndexInterface
*/
protected $cart;

/**
* @var \Magento\Checkout\Helper\Cart
*/
protected $cartHelper;

/**
* @var \Magento\Framework\Json\Helper\Data
*/
protected $jsonHelper;

/**
* @var \Magento\Wishlist\Model\Item\OptionFactory
*/
Expand Down Expand Up @@ -66,6 +76,10 @@ class Cart extends Action\Action implements IndexInterface
* @param \Magento\Catalog\Helper\Product $productHelper
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\Wishlist\Helper\Data $helper
* @param \Magento\Checkout\Helper\Cart $cartHelper
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Action\Context $context,
Expand All @@ -76,7 +90,9 @@ public function __construct(
\Magento\Wishlist\Model\Item\OptionFactory $optionFactory,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Framework\Escaper $escaper,
\Magento\Wishlist\Helper\Data $helper
\Magento\Wishlist\Helper\Data $helper,
\Magento\Checkout\Helper\Cart $cartHelper,
\Magento\Framework\Json\Helper\Data $jsonHelper
) {
$this->wishlistProvider = $wishlistProvider;
$this->quantityProcessor = $quantityProcessor;
Expand All @@ -86,6 +102,8 @@ public function __construct(
$this->productHelper = $productHelper;
$this->escaper = $escaper;
$this->helper = $helper;
$this->cartHelper = $cartHelper;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
}

Expand Down Expand Up @@ -159,8 +177,8 @@ public function execute()
$this->messageManager->addSuccess($message);
}

if ($this->cart->getShouldRedirectToCart()) {
$redirectUrl = $this->cart->getCartUrl();
if ($this->cartHelper->getShouldRedirectToCart()) {
$redirectUrl = $this->cartHelper->getCartUrl();
} else {
$refererUrl = $this->_redirect->getRefererUrl();
if ($refererUrl && $refererUrl != $configureUrl) {
Expand All @@ -178,6 +196,13 @@ public function execute()

$this->helper->calculate();

if ($this->getRequest()->isAjax()) {
$this->getResponse()->representJson(
$this->jsonHelper->jsonEncode(['backUrl' => $redirectUrl])
);
return;
}

return $this->getResponse()->setRedirect($redirectUrl);
}
}
62 changes: 55 additions & 7 deletions app/code/Magento/Wishlist/Test/Unit/Controller/Index/CartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ class CartTest extends \PHPUnit_Framework_TestCase
*/
protected $urlMock;

/**
* @var \Magento\Checkout\Helper\Cart|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cartHelperMock;

/**
* @var \Magento\Framework\Json\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
*/
protected $jsonHelperMock;

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
Expand Down Expand Up @@ -139,12 +149,12 @@ protected function setUp()

$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
->disableOriginalConstructor()
->setMethods(['getParams', 'getParam'])
->setMethods(['getParams', 'getParam', 'isAjax'])
->getMockForAbstractClass();

$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')
->disableOriginalConstructor()
->setMethods(['setRedirect'])
->setMethods(['setRedirect', 'representJson'])
->getMockForAbstractClass();

$this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface')
Expand Down Expand Up @@ -187,6 +197,14 @@ protected function setUp()
->method('getUrl')
->will($this->returnValue($this->urlMock));

$this->cartHelperMock = $this->getMockBuilder('Magento\Checkout\Helper\Cart')
->disableOriginalConstructor()
->getMock();

$this->jsonHelperMock = $this->getMockBuilder('Magento\Framework\Json\Helper\Data')
->disableOriginalConstructor()
->getMock();

$this->model = new Cart(
$this->contextMock,
$this->wishlistProviderMock,
Expand All @@ -196,7 +214,9 @@ protected function setUp()
$this->optionFactoryMock,
$this->productHelperMock,
$this->escaperMock,
$this->helperMock
$this->helperMock,
$this->cartHelperMock,
$this->jsonHelperMock
);
}

Expand Down Expand Up @@ -275,9 +295,13 @@ public function testExecuteWithNoWishlist()
}

/**
* @param bool $isAjax
*
* @dataProvider dataProviderExecuteWithQuantityArray
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testExecuteWithQuantityArray()
public function testExecuteWithQuantityArray($isAjax)
{
$itemId = 2;
$wishlistId = 1;
Expand Down Expand Up @@ -397,6 +421,9 @@ public function testExecuteWithQuantityArray()
$this->requestMock->expects($this->once())
->method('getParams')
->willReturn($params);
$this->requestMock->expects($this->once())
->method('isAjax')
->willReturn($isAjax);

$buyRequestMock = $this->getMockBuilder('Magento\Framework\Object')
->disableOriginalConstructor()
Expand Down Expand Up @@ -467,7 +494,7 @@ public function testExecuteWithQuantityArray()
->with('You added ' . $productName . ' to your shopping cart.', null)
->willReturnSelf();

$this->checkoutCartMock->expects($this->once())
$this->cartHelperMock->expects($this->once())
->method('getShouldRedirectToCart')
->willReturn(false);

Expand All @@ -479,12 +506,33 @@ public function testExecuteWithQuantityArray()
->method('calculate')
->willReturnSelf();

$this->responseMock->expects($this->once())
$this->jsonHelperMock->expects($this->any())
->method('jsonEncode')
->with(['backUrl' => $refererUrl])
->willReturn('{"backUrl":"' . $refererUrl . '"}');

$this->responseMock->expects($this->any())
->method('setRedirect')
->with($refererUrl)
->willReturn($this->responseMock);
$this->responseMock->expects($this->any())
->method('representJson')
->with('{"backUrl":"' . $refererUrl . '"}')
->willReturnSelf();

$this->assertEquals($this->responseMock, $this->model->execute());
$expectedResult = ($isAjax ? null : $this->responseMock);
$this->assertEquals($expectedResult, $this->model->execute());
}

/**
* @return array
*/
public function dataProviderExecuteWithQuantityArray()
{
return [
['isAjax' => false],
['isAjax' => true],
];
}

/**
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/Wishlist/view/frontend/templates/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
<?php echo($block->getChildHtml('wishlist.rss.link'));?>
<form class="form-wishlist-items" id="wishlist-view-form"
data-mage-init='{"wishlist":{
"dataAttribute":"item-id",
"nameFormat":"qty[{0}]",
"btnRemoveSelector":".action.delete",
"qtySelector":".qty",
"addToCartSelector":".action.tocart",
"addAllToCartSelector":".primary > .action.tocart",
"commentInputType":"textarea",
"infoList":false,
"addToCartUrl":"<?php echo $block->getItemAddToCartUrl("%item%");?>",
"confirmRemoveMessage":"<?php echo __("Are you sure you want to remove this product from your wishlist?") ?>",
"addAllToCartUrl":"<?php echo $block->getAddAllToCartUrl(); ?>",
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Wishlist/view/frontend/web/wishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ define([
var itemId = elem.data(this.options.dataAttribute),
url = this.options.addToCartUrl.replace('%item%', itemId),
inputName = $.validator.format(this.options.nameFormat, itemId),
inputValue = elem.parent().find('[name="' + inputName + '"]').val(),
inputValue = $('[name="' + inputName + '"]').val(),
separator = (url.indexOf('?') >= 0) ? '&' : '?';
url += separator + inputName + '=' + encodeURIComponent(inputValue);
this._validateAndRedirect(url);
}

},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ protected function getPreset($name)
'id' => '%id%',
'name' => '%item1_simple::getProductName%',
'position' => '%position%',
'qty' => 17,
'qty' => 3,
],
[
'id' => '%id%',
'name' => '%item1_simple::getProductName%',
'position' => '%position%',
'qty' => 36,
'qty' => 1,
],
[
'id' => '%id%',
'name' => '%item1_simple::getProductName%',
'position' => '%position%',
'qty' => 20,
'qty' => 2,
],
],
'products' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,24 @@
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
</variation>
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation5">
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
<data name="products" xsi:type="string">downloadableProduct::with_two_separately_links</data>
<data name="qty" xsi:type="string">-</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
</variation>
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation6">
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
<data name="products" xsi:type="string">configurableProduct::default</data>
<data name="qty" xsi:type="string">3</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
</variation>
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation7">
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
<data name="products" xsi:type="string">bundleProduct::bundle_dynamic_product</data>
<data name="qty" xsi:type="string">2</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
<constraint name="Magento\Wishlist\Test\Constraint\AssertProductsIsAbsentInWishlist" />
</variation>
<variation name="AddProductsToCartFromCustomerWishlistOnFrontendTestVariation8">
<data name="issue" xsi:type="string">Bug: MAGETWO-36224</data>
<data name="products" xsi:type="string">bundleProduct::bundle_fixed_product</data>
<data name="qty" xsi:type="string">2</data>
<constraint name="Magento\Checkout\Test\Constraint\AssertProductQtyInShoppingCart" />
Expand Down
Loading

0 comments on commit 385f475

Please sign in to comment.