7
7
namespace Magento \Newsletter \Controller ;
8
8
9
9
use Magento \TestFramework \TestCase \AbstractController ;
10
+ use Magento \Framework \App \Config \Value ;
10
11
11
12
/**
12
- * Test Unsubscriber controller
13
+ * Test Unsubscriber controller.
13
14
*
14
15
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
15
16
* @magentoAppArea frontend
16
17
*/
17
18
class UnSubscriberTest extends AbstractController
18
19
{
19
-
20
20
/**
21
21
* @var Subscriber
22
22
*/
23
23
private $ model ;
24
24
25
+ /**
26
+ * @inheritdoc
27
+ */
25
28
protected function setUp ()
26
29
{
27
30
$ this ->model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -43,7 +46,7 @@ public function testSuccessUnsubscribeSubscribedUser()
43
46
$ this ->dispatch ('newsletter/subscriber/unsubscribe ' );
44
47
45
48
$ this ->assertSessionMessages ($ this ->equalTo (['You unsubscribed. ' ]));
46
- $ this ->assertRedirect ($ this ->anything ( ));
49
+ $ this ->assertRedirect ($ this ->stringStartsWith ( $ this -> getBaseUrl () ));
47
50
}
48
51
49
52
/**
@@ -59,6 +62,17 @@ public function testFailureUnsubscribeSubscribedUser()
59
62
$ this ->dispatch ('newsletter/subscriber/unsubscribe ' );
60
63
61
64
$ this ->assertSessionMessages ($ this ->equalTo (['This is an invalid subscription confirmation code. ' ]));
62
- $ this ->assertRedirect ($ this ->anything ());
65
+ $ this ->assertRedirect ($ this ->stringStartsWith ($ this ->getBaseUrl ()));
66
+ }
67
+
68
+ /**
69
+ * @return string
70
+ */
71
+ private function getBaseUrl ()
72
+ {
73
+ $ configValue = $ this ->_objectManager ->create (Value::class);
74
+ $ configValue ->load ('web/unsecure/base_url ' , 'path ' );
75
+
76
+ return $ configValue ->getValue () ?: 'http://localhost/ ' ;
63
77
}
64
78
}
0 commit comments