Skip to content
Snippets Groups Projects
Commit 28cd0926 authored by Pavel Bystritsky's avatar Pavel Bystritsky
Browse files

magento/magento2#12582: Can't remove item description from wishlist

parent 0db60528
No related merge requests found
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
namespace Magento\Wishlist\Controller; namespace Magento\Wishlist\Controller;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Helper\View; use Magento\Customer\Helper\View;
use Magento\Customer\Model\Customer;
use Magento\Customer\Model\Session; use Magento\Customer\Model\Session;
use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Data\Form\FormKey;
use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Message\ManagerInterface;
use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\Item;
use Magento\Wishlist\Model\Wishlist;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Zend\Http\Request; use Zend\Http\Request;
...@@ -18,7 +21,7 @@ use Zend\Http\Request; ...@@ -18,7 +21,7 @@ use Zend\Http\Request;
* Tests updating wishlist item comment. * Tests updating wishlist item comment.
* *
* @magentoAppIsolation enabled * @magentoAppIsolation enabled
* @magentoDbIsolation disabled * @magentoDbIsolation enabled
* @magentoAppArea frontend * @magentoAppArea frontend
*/ */
class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
...@@ -50,14 +53,22 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController ...@@ -50,14 +53,22 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
* *
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php * @magentoDataFixture Magento/Wishlist/_files/wishlist.php
* @dataProvider commentDataProvider * @dataProvider commentDataProvider
* @param string|null $postDescription
* @param string $expectedResult
* @param boolean $presetComment
*/ */
public function testUpdateComment($postDescription, $postQty, $expectedResult, $presetComment) public function testUpdateComment($postDescription, $expectedResult, $presetComment)
{ {
$itemId = 1; /** @var Customer $customer */
$wishlistId = 1; $customer = $this->customerSession->getCustomer();
/** @var Wishlist $wishlist */
$wishlist = $this->_objectManager
->get(Wishlist::class)
->loadByCustomerId($customer->getId(), true);
/** @var Item $item */
$item = $wishlist->getItemCollection()->getFirstItem();
if ($presetComment) { if ($presetComment) {
$item = $this->_objectManager->create(Item::class)->load($itemId);
$item->setDescription($this->description); $item->setDescription($this->description);
$item->save(); $item->save();
} }
...@@ -65,16 +76,16 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController ...@@ -65,16 +76,16 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
$formKey = $this->_objectManager->get(FormKey::class); $formKey = $this->_objectManager->get(FormKey::class);
$this->getRequest()->setPostValue( $this->getRequest()->setPostValue(
[ [
'description' => $postDescription, 'description' => isset($postDescription) ? [$item->getId() => $postDescription] : [],
'qty' => $postQty, 'qty' => isset($postDescription) ? [$item->getId() => 1] : [],
'do' => '', 'do' => '',
'form_key' => $formKey->getFormKey() 'form_key' => $formKey->getFormKey()
] ]
)->setMethod(Request::METHOD_POST); )->setMethod(Request::METHOD_POST);
$this->dispatch('wishlist/index/update/wishlist_id/' . $wishlistId); $this->dispatch('wishlist/index/update/wishlist_id/' . $wishlist->getId());
$item = $this->_objectManager->create(Item::class)->load($itemId);
// Reload item
$item = $this->_objectManager->get(Item::class)->load($item->getId());
self::assertEquals( self::assertEquals(
$expectedResult, $expectedResult,
$item->getDescription() $item->getDescription()
...@@ -88,22 +99,20 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController ...@@ -88,22 +99,20 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
*/ */
public function commentDataProvider() public function commentDataProvider()
{ {
return [ return [
'test adding comment' => [ 'test adding comment' => [
'postDescription' => [1 => $this->description], 'postDescription' => $this->description,
'postQty' => [1 => '1'],
'expectedResult' => $this->description, 'expectedResult' => $this->description,
'presetComment' => false 'presetComment' => false
], ],
'test removing comment' => [ 'test removing comment' => [
'postDescription' => [1 => ''], 'postDescription' => '',
'postQty' => [1 => '1'],
'expectedResult' => '', 'expectedResult' => '',
'presetComment' => true 'presetComment' => true
], ],
'test not changing comment' => [ 'test not changing comment' => [
'postDescription' => [], 'postDescription' => null,
'postQty' => [1 => '1'],
'expectedResult' => $this->description, 'expectedResult' => $this->description,
'presetComment' => true 'presetComment' => true
], ],
...@@ -118,9 +127,9 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController ...@@ -118,9 +127,9 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
Session::class, Session::class,
[$logger] [$logger]
); );
/** @var \Magento\Customer\Api\AccountManagementInterface $service */ /** @var AccountManagementInterface $service */
$service = $this->_objectManager->create( $service = $this->_objectManager->create(
\Magento\Customer\Api\AccountManagementInterface::class AccountManagementInterface::class
); );
$customer = $service->authenticate('customer@example.com', 'password'); $customer = $service->authenticate('customer@example.com', 'password');
$this->customerSession->setCustomerDataAsLoggedIn($customer); $this->customerSession->setCustomerDataAsLoggedIn($customer);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment