@@ -62,17 +62,15 @@ protected function tearDown()
62
62
*
63
63
* @dataProvider subscriptionDataProvider
64
64
*
65
- * @param string $isSubscribed
65
+ * @param bool $isSubscribed
66
66
* @param string $expectedMessage
67
67
* @return void
68
68
*/
69
- public function testSaveAction (string $ isSubscribed , string $ expectedMessage ): void
69
+ public function testSaveAction (bool $ isSubscribed , string $ expectedMessage ): void
70
70
{
71
71
$ this ->loginCustomer ('new_customer@example.com ' );
72
- $ this ->getRequest ()->setParam ('form_key ' , $ this ->formKey ->getFormKey ())
73
- ->setParam ('is_subscribed ' , $ isSubscribed );
74
72
$ this ->_objectManager ->removeSharedInstance (CustomerPlugin::class);
75
- $ this ->dispatch ( ' newsletter/manage/save ' );
73
+ $ this ->dispatchSaveAction ( $ isSubscribed );
76
74
$ this ->assertSuccessSubscription ($ expectedMessage );
77
75
}
78
76
@@ -83,11 +81,11 @@ public function subscriptionDataProvider(): array
83
81
{
84
82
return [
85
83
'subscribe_customer ' => [
86
- 'is_subscribed ' => 1 ,
84
+ 'is_subscribed ' => true ,
87
85
'expected_message ' => 'We have saved your subscription. ' ,
88
86
],
89
87
'unsubscribe_customer ' => [
90
- 'is_subscribed ' => 0 ,
88
+ 'is_subscribed ' => false ,
91
89
'expected_message ' => 'We have updated your subscription. ' ,
92
90
],
93
91
];
@@ -102,8 +100,7 @@ public function subscriptionDataProvider(): array
102
100
public function testSubscribeWithEnabledConfirmation (): void
103
101
{
104
102
$ this ->loginCustomer ('new_customer@example.com ' );
105
- $ this ->getRequest ()->setParam ('form_key ' , $ this ->formKey ->getFormKey ())->setParam ('is_subscribed ' , '1 ' );
106
- $ this ->dispatch ('newsletter/manage/save ' );
103
+ $ this ->dispatchSaveAction (true );
107
104
$ this ->assertSuccessSubscription ('A confirmation request has been sent. ' );
108
105
}
109
106
@@ -115,12 +112,25 @@ public function testSubscribeWithEnabledConfirmation(): void
115
112
public function testUnsubscribeSubscribedCustomer (): void
116
113
{
117
114
$ this ->loginCustomer ('new_customer@example.com ' );
118
- $ this ->getRequest ()->setParam ('form_key ' , $ this ->formKey ->getFormKey ())->setParam ('is_subscribed ' , '0 ' );
119
115
$ this ->_objectManager ->removeSharedInstance (CustomerPlugin::class);
120
- $ this ->dispatch ( ' newsletter/manage/save ' );
116
+ $ this ->dispatchSaveAction ( false );
121
117
$ this ->assertSuccessSubscription ('We have removed your newsletter subscription. ' );
122
118
}
123
119
120
+ /**
121
+ * Dispatch save action with parameters
122
+ *
123
+ * @param string $isSubscribed
124
+ * @return void
125
+ */
126
+ private function dispatchSaveAction (bool $ isSubscribed ): void
127
+ {
128
+ $ this ->_objectManager ->removeSharedInstance (CustomerPlugin::class);
129
+ $ this ->getRequest ()->setParam ('form_key ' , $ this ->formKey ->getFormKey ())
130
+ ->setParam ('is_subscribed ' , $ isSubscribed );
131
+ $ this ->dispatch ('newsletter/manage/save ' );
132
+ }
133
+
124
134
/**
125
135
* Login customer by email
126
136
*
0 commit comments