6
6
7
7
namespace Magento \Tax \Test \Unit \Model \System \Message ;
8
8
9
+ use Magento \Framework \Escaper ;
9
10
use Magento \Tax \Model \Config as TaxConfig ;
10
11
use Magento \Tax \Model \System \Message \Notifications ;
11
12
use Magento \Store \Model \StoreManagerInterface ;
14
15
use Magento \Tax \Model \System \Message \NotificationInterface ;
15
16
16
17
/**
17
- * Test class for @see \Magento\Tax\Model\System\Message\Notifications
18
+ * Test class for @see \Magento\Tax\Model\System\Message\Notifications.
18
19
*/
19
20
class NotificationsTest extends \PHPUnit_Framework_TestCase
20
21
{
@@ -43,21 +44,29 @@ class NotificationsTest extends \PHPUnit_Framework_TestCase
43
44
*/
44
45
private $ notificationMock ;
45
46
47
+ /**
48
+ * @var Escaper|\PHPUnit_Framework_MockObject_MockObject
49
+ */
50
+ private $ escaperMock ;
51
+
52
+ /**
53
+ * @inheritdoc
54
+ */
46
55
protected function setUp ()
47
56
{
48
- parent ::setUp ();
49
-
50
57
$ this ->storeManagerMock = $ this ->getMock (StoreManagerInterface::class, [], [], '' , false );
51
58
$ this ->urlBuilderMock = $ this ->getMock (UrlInterface::class, [], [], '' , false );
52
59
$ this ->taxConfigMock = $ this ->getMock (TaxConfig::class, [], [], '' , false );
53
60
$ this ->notificationMock = $ this ->getMock (NotificationInterface::class, [], [], '' , false );
61
+ $ this ->escaperMock = $ this ->getMock (Escaper::class);
54
62
$ this ->notifications = (new ObjectManager ($ this ))->getObject (
55
63
Notifications::class,
56
64
[
57
65
'storeManager ' => $ this ->storeManagerMock ,
58
66
'urlBuilder ' => $ this ->urlBuilderMock ,
59
67
'taxConfig ' => $ this ->taxConfigMock ,
60
- 'notifications ' => [$ this ->notificationMock ]
68
+ 'notifications ' => [$ this ->notificationMock ],
69
+ 'escaper ' => $ this ->escaperMock ,
61
70
]
62
71
);
63
72
}
@@ -84,17 +93,44 @@ public function dataProviderIsDisplayed()
84
93
];
85
94
}
86
95
96
+ /**
97
+ * Unit test for getText method.
98
+ *
99
+ * @return void
100
+ */
87
101
public function testGetText ()
88
102
{
103
+ $ url = 'http://info-url ' ;
89
104
$ this ->notificationMock ->expects ($ this ->once ())->method ('getText ' )->willReturn ('Notification Text. ' );
90
- $ this ->taxConfigMock ->expects ($ this ->once ())->method ('getInfoUrl ' )->willReturn (' http://info- url' );
105
+ $ this ->taxConfigMock ->expects ($ this ->once ())->method ('getInfoUrl ' )->willReturn ($ url );
91
106
$ this ->urlBuilderMock ->expects ($ this ->once ())->method ('getUrl ' )
92
107
->with ('adminhtml/system_config/edit/section/tax ' )->willReturn ('http://tax-config-url ' );
108
+ $ this ->escaperMock ->expects ($ this ->once ())
109
+ ->method ('escapeUrl ' )
110
+ ->with ($ url )
111
+ ->willReturn ($ url );
93
112
94
113
$ this ->assertEquals (
95
114
'Notification Text.<p>Please see <a href="http://info-url">documentation</a> for more details. '
96
115
. 'Click here to go to <a href="http://tax-config-url">Tax Configuration</a> and change your settings.</p> ' ,
97
116
$ this ->notifications ->getText ()
98
117
);
99
118
}
119
+
120
+ /**
121
+ * Unit test for getInfoUrl method.
122
+ *
123
+ * @return void
124
+ */
125
+ public function testGetInfoUrl ()
126
+ {
127
+ $ url = 'http://info-url ' ;
128
+ $ this ->taxConfigMock ->expects ($ this ->once ())->method ('getInfoUrl ' )->willReturn ($ url );
129
+ $ this ->escaperMock ->expects ($ this ->once ())
130
+ ->method ('escapeUrl ' )
131
+ ->with ($ url )
132
+ ->willReturn ($ url );
133
+
134
+ $ this ->assertEquals ($ url , $ this ->notifications ->getInfoUrl ());
135
+ }
100
136
}
0 commit comments