8
8
use Magento \CheckoutAgreements \Model \AgreementsProvider ;
9
9
use Magento \Store \Model \ScopeInterface ;
10
10
11
+ /**
12
+ * Tests for AgreementsConfigProvider.
13
+ */
11
14
class AgreementsConfigProviderTest extends \PHPUnit \Framework \TestCase
12
15
{
13
16
/**
@@ -30,6 +33,9 @@ class AgreementsConfigProviderTest extends \PHPUnit\Framework\TestCase
30
33
*/
31
34
protected $ escaperMock ;
32
35
36
+ /**
37
+ * @inheritdoc
38
+ */
33
39
protected function setUp ()
34
40
{
35
41
$ this ->scopeConfigMock = $ this ->createMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
@@ -45,10 +51,16 @@ protected function setUp()
45
51
);
46
52
}
47
53
54
+ /**
55
+ * Test for getConfig if content is HTML.
56
+ *
57
+ * @return void
58
+ */
48
59
public function testGetConfigIfContentIsHtml ()
49
60
{
50
61
$ content = 'content ' ;
51
62
$ checkboxText = 'checkbox_text ' ;
63
+ $ escapedCheckboxText = 'escaped_checkbox_text ' ;
52
64
$ mode = \Magento \CheckoutAgreements \Model \AgreementModeOptions::MODE_AUTO ;
53
65
$ agreementId = 100 ;
54
66
$ expectedResult = [
@@ -57,12 +69,12 @@ public function testGetConfigIfContentIsHtml()
57
69
'agreements ' => [
58
70
[
59
71
'content ' => $ content ,
60
- 'checkboxText ' => $ checkboxText ,
72
+ 'checkboxText ' => $ escapedCheckboxText ,
61
73
'mode ' => $ mode ,
62
- 'agreementId ' => $ agreementId
63
- ]
64
- ]
65
- ]
74
+ 'agreementId ' => $ agreementId,
75
+ ],
76
+ ],
77
+ ],
66
78
];
67
79
68
80
$ this ->scopeConfigMock ->expects ($ this ->once ())
@@ -71,8 +83,12 @@ public function testGetConfigIfContentIsHtml()
71
83
->willReturn (true );
72
84
73
85
$ agreement = $ this ->createMock (\Magento \CheckoutAgreements \Api \Data \AgreementInterface::class);
74
- $ this ->agreementsRepositoryMock ->expects ($ this ->any ())->method ('getList ' )->willReturn ([$ agreement ]);
86
+ $ this ->agreementsRepositoryMock ->expects ($ this ->once ())->method ('getList ' )->willReturn ([$ agreement ]);
75
87
88
+ $ this ->escaperMock ->expects ($ this ->once ())
89
+ ->method ('escapeHtml ' )
90
+ ->with ($ checkboxText )
91
+ ->willReturn ($ escapedCheckboxText );
76
92
$ agreement ->expects ($ this ->once ())->method ('getIsHtml ' )->willReturn (true );
77
93
$ agreement ->expects ($ this ->once ())->method ('getContent ' )->willReturn ($ content );
78
94
$ agreement ->expects ($ this ->once ())->method ('getCheckboxText ' )->willReturn ($ checkboxText );
@@ -82,11 +98,17 @@ public function testGetConfigIfContentIsHtml()
82
98
$ this ->assertEquals ($ expectedResult , $ this ->model ->getConfig ());
83
99
}
84
100
101
+ /**
102
+ * Test for getConfig if content is not HTML.
103
+ *
104
+ * @return void
105
+ */
85
106
public function testGetConfigIfContentIsNotHtml ()
86
107
{
87
108
$ content = 'content ' ;
88
109
$ escapedContent = 'escaped_content ' ;
89
110
$ checkboxText = 'checkbox_text ' ;
111
+ $ escapedCheckboxText = 'escaped_checkbox_text ' ;
90
112
$ mode = \Magento \CheckoutAgreements \Model \AgreementModeOptions::MODE_AUTO ;
91
113
$ agreementId = 100 ;
92
114
$ expectedResult = [
@@ -95,12 +117,12 @@ public function testGetConfigIfContentIsNotHtml()
95
117
'agreements ' => [
96
118
[
97
119
'content ' => $ escapedContent ,
98
- 'checkboxText ' => $ checkboxText ,
120
+ 'checkboxText ' => $ escapedCheckboxText ,
99
121
'mode ' => $ mode ,
100
- 'agreementId ' => $ agreementId
101
- ]
102
- ]
103
- ]
122
+ 'agreementId ' => $ agreementId,
123
+ ],
124
+ ],
125
+ ],
104
126
];
105
127
106
128
$ this ->scopeConfigMock ->expects ($ this ->once ())
@@ -109,9 +131,13 @@ public function testGetConfigIfContentIsNotHtml()
109
131
->willReturn (true );
110
132
111
133
$ agreement = $ this ->createMock (\Magento \CheckoutAgreements \Api \Data \AgreementInterface::class);
112
- $ this ->agreementsRepositoryMock ->expects ($ this ->any ())->method ('getList ' )->willReturn ([$ agreement ]);
113
- $ this ->escaperMock ->expects ($ this ->once ())->method ('escapeHtml ' )->with ($ content )->willReturn ($ escapedContent );
134
+ $ this ->agreementsRepositoryMock ->expects ($ this ->once ())->method ('getList ' )->willReturn ([$ agreement ]);
114
135
136
+ $ this ->escaperMock ->expects ($ this ->at (0 ))->method ('escapeHtml ' )->with ($ content )->willReturn ($ escapedContent );
137
+ $ this ->escaperMock ->expects ($ this ->at (1 ))
138
+ ->method ('escapeHtml ' )
139
+ ->with ($ checkboxText )
140
+ ->willReturn ($ escapedCheckboxText );
115
141
$ agreement ->expects ($ this ->once ())->method ('getIsHtml ' )->willReturn (false );
116
142
$ agreement ->expects ($ this ->once ())->method ('getContent ' )->willReturn ($ content );
117
143
$ agreement ->expects ($ this ->once ())->method ('getCheckboxText ' )->willReturn ($ checkboxText );
0 commit comments