Skip to content

Commit 28cd092

Browse files
committed
#12582: Can't remove item description from wishlist
1 parent 0db6052 commit 28cd092

File tree

1 file changed

+27
-18
lines changed
  • dev/tests/integration/testsuite/Magento/Wishlist/Controller

1 file changed

+27
-18
lines changed

dev/tests/integration/testsuite/Magento/Wishlist/Controller/UpdateTest.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66

77
namespace Magento\Wishlist\Controller;
88

9+
use Magento\Customer\Api\AccountManagementInterface;
910
use Magento\Customer\Helper\View;
11+
use Magento\Customer\Model\Customer;
1012
use Magento\Customer\Model\Session;
1113
use Magento\Framework\Data\Form\FormKey;
1214
use Magento\Framework\Message\ManagerInterface;
1315
use Magento\Wishlist\Model\Item;
16+
use Magento\Wishlist\Model\Wishlist;
1417
use Psr\Log\LoggerInterface;
1518
use Zend\Http\Request;
1619

1720
/**
1821
* Tests updating wishlist item comment.
1922
*
2023
* @magentoAppIsolation enabled
21-
* @magentoDbIsolation disabled
24+
* @magentoDbIsolation enabled
2225
* @magentoAppArea frontend
2326
*/
2427
class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
@@ -50,31 +53,39 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
5053
*
5154
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
5255
* @dataProvider commentDataProvider
56+
* @param string|null $postDescription
57+
* @param string $expectedResult
58+
* @param boolean $presetComment
5359
*/
54-
public function testUpdateComment($postDescription, $postQty, $expectedResult, $presetComment)
60+
public function testUpdateComment($postDescription, $expectedResult, $presetComment)
5561
{
56-
$itemId = 1;
57-
$wishlistId = 1;
62+
/** @var Customer $customer */
63+
$customer = $this->customerSession->getCustomer();
64+
/** @var Wishlist $wishlist */
65+
$wishlist = $this->_objectManager
66+
->get(Wishlist::class)
67+
->loadByCustomerId($customer->getId(), true);
68+
/** @var Item $item */
69+
$item = $wishlist->getItemCollection()->getFirstItem();
5870

5971
if ($presetComment) {
60-
$item = $this->_objectManager->create(Item::class)->load($itemId);
6172
$item->setDescription($this->description);
6273
$item->save();
6374
}
6475

6576
$formKey = $this->_objectManager->get(FormKey::class);
6677
$this->getRequest()->setPostValue(
6778
[
68-
'description' => $postDescription,
69-
'qty' => $postQty,
79+
'description' => isset($postDescription) ? [$item->getId() => $postDescription] : [],
80+
'qty' => isset($postDescription) ? [$item->getId() => 1] : [],
7081
'do' => '',
7182
'form_key' => $formKey->getFormKey()
7283
]
7384
)->setMethod(Request::METHOD_POST);
74-
$this->dispatch('wishlist/index/update/wishlist_id/' . $wishlistId);
75-
76-
$item = $this->_objectManager->create(Item::class)->load($itemId);
85+
$this->dispatch('wishlist/index/update/wishlist_id/' . $wishlist->getId());
7786

87+
// Reload item
88+
$item = $this->_objectManager->get(Item::class)->load($item->getId());
7889
self::assertEquals(
7990
$expectedResult,
8091
$item->getDescription()
@@ -88,22 +99,20 @@ public function testUpdateComment($postDescription, $postQty, $expectedResult, $
8899
*/
89100
public function commentDataProvider()
90101
{
102+
91103
return [
92104
'test adding comment' => [
93-
'postDescription' => [1 => $this->description],
94-
'postQty' => [1 => '1'],
105+
'postDescription' => $this->description,
95106
'expectedResult' => $this->description,
96107
'presetComment' => false
97108
],
98109
'test removing comment' => [
99-
'postDescription' => [1 => ''],
100-
'postQty' => [1 => '1'],
110+
'postDescription' => '',
101111
'expectedResult' => '',
102112
'presetComment' => true
103113
],
104114
'test not changing comment' => [
105-
'postDescription' => [],
106-
'postQty' => [1 => '1'],
115+
'postDescription' => null,
107116
'expectedResult' => $this->description,
108117
'presetComment' => true
109118
],
@@ -118,9 +127,9 @@ protected function setUp()
118127
Session::class,
119128
[$logger]
120129
);
121-
/** @var \Magento\Customer\Api\AccountManagementInterface $service */
130+
/** @var AccountManagementInterface $service */
122131
$service = $this->_objectManager->create(
123-
\Magento\Customer\Api\AccountManagementInterface::class
132+
AccountManagementInterface::class
124133
);
125134
$customer = $service->authenticate('[email protected]', 'password');
126135
$this->customerSession->setCustomerDataAsLoggedIn($customer);

0 commit comments

Comments
 (0)