Skip to content

Commit 6b2630b

Browse files
author
Joan He
committed
Merge branch 'MAGETWO-64949-remaining-unserialize-ce' of https://github.com/magento-jackalopes/magento2ce into MAGETWO-64949-remaining-unserialize-ce
2 parents 946f404 + a0a9c97 commit 6b2630b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

app/code/Magento/Wishlist/Model/Wishlist.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @method string getUpdatedAt()
2626
* @method \Magento\Wishlist\Model\Wishlist setUpdatedAt(string $value)
2727
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
* @SuppressWarnings(PHPMD.TooManyFields)
2829
*/
2930
class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface
3031
{
@@ -126,6 +127,8 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent
126127
private $serializer;
127128

128129
/**
130+
* Constructor
131+
*
129132
* @param \Magento\Framework\Model\Context $context
130133
* @param \Magento\Framework\Registry $registry
131134
* @param \Magento\Catalog\Helper\Product $catalogProduct
@@ -413,9 +416,11 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
413416
if ($buyRequest instanceof \Magento\Framework\DataObject) {
414417
$_buyRequest = $buyRequest;
415418
} elseif (is_string($buyRequest)) {
416-
$_buyRequest = new \Magento\Framework\DataObject(
417-
$this->serializer->unserialize($buyRequest)
418-
);
419+
$buyRequestData = $this->serializer->unserialize($buyRequest);
420+
if (!is_array($buyRequestData)) {
421+
throw new \InvalidArgumentException('Invalid wishlist item configuration.');
422+
}
423+
$_buyRequest = new \Magento\Framework\DataObject($buyRequestData);
419424
} elseif (is_array($buyRequest)) {
420425
$_buyRequest = new \Magento\Framework\DataObject($buyRequest);
421426
} else {

dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,27 @@ public function testAddNewItem()
6363
$this->assertInstanceOf(Item::class, $wishlistItem);
6464
$this->assertEquals($wishlistItem->getQty(), 10);
6565
}
66+
67+
/**
68+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
69+
* @magentoDataFixture Magento/Customer/_files/customer.php
70+
* @magentoAppIsolation enabled
71+
* @magentoDbIsolation enabled
72+
* @expectedException \InvalidArgumentException
73+
* @expectedExceptionMessage Invalid wishlist item configuration.
74+
*/
75+
public function testAddNewItemInvalidWishlistItemConfiguration()
76+
{
77+
$productSku = 'simple';
78+
$customerId = 1;
79+
/** @var ProductRepositoryInterface $productRepository */
80+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
81+
$product = $productRepository->get($productSku);
82+
$this->wishlist->loadByCustomerId($customerId, true);
83+
$this->wishlist->addNewItem(
84+
$product,
85+
'{"qty":2'
86+
);
87+
$this->wishlist->addNewItem($product);
88+
}
6689
}

0 commit comments

Comments
 (0)