Skip to content

Commit

Permalink
Adding test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
eduard13 committed May 15, 2020
1 parent a41e384 commit 1d799ab
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/code/Magento/Wishlist/Model/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class Wishlist extends AbstractModel implements IdentityInterface
* @param Json|null $serializer
* @param StockRegistryInterface|null $stockRegistry
* @param ScopeConfigInterface|null $scopeConfig
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -226,6 +227,7 @@ public function __construct(
*
* @param int $customerId
* @param bool $create Create wishlist if don't exists
*
* @return $this
*/
public function loadByCustomerId($customerId, $create = false)
Expand Down Expand Up @@ -274,6 +276,7 @@ public function generateSharingCode()
* Load by sharing code
*
* @param string $code
*
* @return $this
*/
public function loadByCode($code)
Expand Down Expand Up @@ -370,6 +373,7 @@ protected function _addCatalogProduct(Product $product, $qty = 1, $forciblySetQt
* Retrieve wishlist item collection
*
* @return \Magento\Wishlist\Model\ResourceModel\Item\Collection
*
* @throws NoSuchEntityException
*/
public function getItemCollection()
Expand All @@ -389,6 +393,7 @@ public function getItemCollection()
* Retrieve wishlist item collection
*
* @param int $itemId
*
* @return false|Item
*/
public function getItem($itemId)
Expand All @@ -403,7 +408,9 @@ public function getItem($itemId)
* Adding item to wishlist
*
* @param Item $item
*
* @return $this
*
* @throws Exception
*/
public function addItem(Item $item)
Expand All @@ -424,9 +431,12 @@ public function addItem(Item $item)
* @param int|Product $product
* @param DataObject|array|string|null $buyRequest
* @param bool $forciblySetQty
*
* @return Item|string
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @throws LocalizedException
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -529,7 +539,9 @@ public function addNewItem($product, $buyRequest = null, $forciblySetQty = false
* Set customer id
*
* @param int $customerId
*
* @return $this
*
* @throws LocalizedException
*/
public function setCustomerId($customerId)
Expand All @@ -541,6 +553,7 @@ public function setCustomerId($customerId)
* Retrieve customer id
*
* @return int
*
* @throws LocalizedException
*/
public function getCustomerId()
Expand All @@ -552,6 +565,7 @@ public function getCustomerId()
* Retrieve data for save
*
* @return array
*
* @throws LocalizedException
*/
public function getDataForSave()
Expand All @@ -567,6 +581,7 @@ public function getDataForSave()
* Retrieve shared store ids for current website or all stores if $current is false
*
* @return array
*
* @throws NoSuchEntityException
*/
public function getSharedStoreIds()
Expand All @@ -590,6 +605,7 @@ public function getSharedStoreIds()
* Set shared store ids
*
* @param array $storeIds
*
* @return $this
*/
public function setSharedStoreIds($storeIds)
Expand All @@ -602,6 +618,7 @@ public function setSharedStoreIds($storeIds)
* Retrieve wishlist store object
*
* @return \Magento\Store\Model\Store
*
* @throws NoSuchEntityException
*/
public function getStore()
Expand All @@ -616,6 +633,7 @@ public function getStore()
* Set wishlist store
*
* @param Store $store
*
* @return $this
*/
public function setStore($store)
Expand Down Expand Up @@ -653,6 +671,7 @@ public function isSalable()
* Retrieve if product has stock or config is set for showing out of stock products
*
* @param int $productId
*
* @return bool
*/
private function isInStock($productId)
Expand All @@ -671,7 +690,9 @@ private function isInStock($productId)
* Check customer is owner this wishlist
*
* @param int $customerId
*
* @return bool
*
* @throws LocalizedException
*/
public function isOwner($customerId)
Expand All @@ -696,10 +717,13 @@ public function isOwner($customerId)
* @param int|Item $itemId
* @param DataObject $buyRequest
* @param null|array|DataObject $params
*
* @return $this
*
* @throws LocalizedException
*
* @see \Magento\Catalog\Helper\Product::addParamsToBuyRequest()
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ public function testUpdateItemQtyInWishList(): void
$this->assertEquals(55, $updatedItem->getQty());
}

/**
* Update description of wishlist item
*
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
*
* @return void
*/
public function testUpdateItemDescriptionInWishList(): void
{
$itemDescription = 'Test Description';
$wishlist = $this->getWishlistByCustomerId->execute(1);
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple');
$item->setDescription($itemDescription);
$this->assertNotNull($item);
$buyRequest = $this->dataObjectFactory->create(['data' => ['qty' => 55]]);
$wishlist->updateItem($item, $buyRequest);
$updatedItem = $this->getWishlistByCustomerId->getItemBySku(1, 'simple');
$this->assertEquals(55, $updatedItem->getQty());
$this->assertEquals($itemDescription, $updatedItem->getDescription());
}

/**
* @return void
*/
Expand Down

0 comments on commit 1d799ab

Please sign in to comment.