6
6
7
7
namespace Magento \Wishlist \Controller ;
8
8
9
+ use Magento \Customer \Api \AccountManagementInterface ;
9
10
use Magento \Customer \Helper \View ;
11
+ use Magento \Customer \Model \Customer ;
10
12
use Magento \Customer \Model \Session ;
11
13
use Magento \Framework \Data \Form \FormKey ;
12
14
use Magento \Framework \Message \ManagerInterface ;
13
15
use Magento \Wishlist \Model \Item ;
16
+ use Magento \Wishlist \Model \Wishlist ;
14
17
use Psr \Log \LoggerInterface ;
15
18
use Zend \Http \Request ;
16
19
17
20
/**
18
21
* Tests updating wishlist item comment.
19
22
*
20
23
* @magentoAppIsolation enabled
21
- * @magentoDbIsolation disabled
24
+ * @magentoDbIsolation enabled
22
25
* @magentoAppArea frontend
23
26
*/
24
27
class UpdateTest extends \Magento \TestFramework \TestCase \AbstractController
@@ -50,31 +53,39 @@ class UpdateTest extends \Magento\TestFramework\TestCase\AbstractController
50
53
*
51
54
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
52
55
* @dataProvider commentDataProvider
56
+ * @param string|null $postDescription
57
+ * @param string $expectedResult
58
+ * @param boolean $presetComment
53
59
*/
54
- public function testUpdateComment ($ postDescription , $ postQty , $ expectedResult , $ presetComment )
60
+ public function testUpdateComment ($ postDescription , $ expectedResult , $ presetComment )
55
61
{
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 ();
58
70
59
71
if ($ presetComment ) {
60
- $ item = $ this ->_objectManager ->create (Item::class)->load ($ itemId );
61
72
$ item ->setDescription ($ this ->description );
62
73
$ item ->save ();
63
74
}
64
75
65
76
$ formKey = $ this ->_objectManager ->get (FormKey::class);
66
77
$ this ->getRequest ()->setPostValue (
67
78
[
68
- 'description ' => $ postDescription ,
69
- 'qty ' => $ postQty ,
79
+ 'description ' => isset ( $ postDescription) ? [ $ item -> getId () => $ postDescription ] : [] ,
80
+ 'qty ' => isset ( $ postDescription ) ? [ $ item -> getId () => 1 ] : [] ,
70
81
'do ' => '' ,
71
82
'form_key ' => $ formKey ->getFormKey ()
72
83
]
73
84
)->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 ());
77
86
87
+ // Reload item
88
+ $ item = $ this ->_objectManager ->get (Item::class)->load ($ item ->getId ());
78
89
self ::assertEquals (
79
90
$ expectedResult ,
80
91
$ item ->getDescription ()
@@ -88,22 +99,20 @@ public function testUpdateComment($postDescription, $postQty, $expectedResult, $
88
99
*/
89
100
public function commentDataProvider ()
90
101
{
102
+
91
103
return [
92
104
'test adding comment ' => [
93
- 'postDescription ' => [1 => $ this ->description ],
94
- 'postQty ' => [1 => '1 ' ],
105
+ 'postDescription ' => $ this ->description ,
95
106
'expectedResult ' => $ this ->description ,
96
107
'presetComment ' => false
97
108
],
98
109
'test removing comment ' => [
99
- 'postDescription ' => [1 => '' ],
100
- 'postQty ' => [1 => '1 ' ],
110
+ 'postDescription ' => '' ,
101
111
'expectedResult ' => '' ,
102
112
'presetComment ' => true
103
113
],
104
114
'test not changing comment ' => [
105
- 'postDescription ' => [],
106
- 'postQty ' => [1 => '1 ' ],
115
+ 'postDescription ' => null ,
107
116
'expectedResult ' => $ this ->description ,
108
117
'presetComment ' => true
109
118
],
@@ -118,9 +127,9 @@ protected function setUp()
118
127
Session::class,
119
128
[$ logger ]
120
129
);
121
- /** @var \Magento\Customer\Api\ AccountManagementInterface $service */
130
+ /** @var AccountManagementInterface $service */
122
131
$ service = $ this ->_objectManager ->create (
123
- \ Magento \ Customer \ Api \ AccountManagementInterface::class
132
+ AccountManagementInterface::class
124
133
);
125
134
$ customer =
$ service->
authenticate (
'[email protected] ' ,
'password ' );
126
135
$ this ->customerSession ->setCustomerDataAsLoggedIn ($ customer );
0 commit comments