5
5
*/
6
6
namespace Magento \Translation \Test \Unit \Model \Inline ;
7
7
8
+ use Magento \Translation \Model \Inline \Parser ;
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Framework \Translate \InlineInterface ;
11
+ use Magento \Framework \App \Cache \TypeListInterface ;
12
+ use Magento \Store \Model \StoreManagerInterface ;
13
+ use Magento \Store \Api \Data \StoreInterface ;
14
+ use Magento \Translation \Model \ResourceModel \StringUtilsFactory ;
15
+ use Magento \Translation \Model \ResourceModel \StringUtils ;
16
+ use Magento \Translation \Model \Inline \CacheManager ;
17
+
8
18
/**
9
19
* Class ParserTest to test \Magento\Translation\Model\Inline\Parser
10
20
*/
11
21
class ParserTest extends \PHPUnit_Framework_TestCase
12
22
{
13
23
/**
14
- * @var \Magento\Translation\Model\Inline\ Parser|\PHPUnit_Framework_MockObject_MockObject
24
+ * @var Parser
15
25
*/
16
26
private $ model ;
17
27
18
28
/**
19
- * @var \Magento\Translation\Model\ResourceModel\StringUtilsFactory|\PHPUnit_Framework_MockObject_MockObject
29
+ * @var ObjectManager
20
30
*/
21
- private $ resourceMock ;
31
+ private $ objectManager ;
32
+
33
+ /**
34
+ * @var InlineInterface|\PHPUnit_Framework_MockObject_MockObject
35
+ */
36
+ private $ translateInlineMock ;
37
+
38
+ /**
39
+ * @var TypeListInterface|\PHPUnit_Framework_MockObject_MockObject
40
+ */
41
+ private $ appCacheMock ;
22
42
23
43
/**
24
- * @var \Magento\Store\Model\ StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
44
+ * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
25
45
*/
26
46
private $ storeManagerMock ;
27
47
48
+ /**
49
+ * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ storeMock ;
52
+
28
53
/**
29
54
* @var \Zend_Filter_Interface|\PHPUnit_Framework_MockObject_MockObject
30
55
*/
31
56
private $ inputFilterMock ;
32
57
58
+ /**
59
+ * @var StringUtilsFactory|\PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ private $ resourceFactoryMock ;
62
+
33
63
/**
34
64
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
35
65
*/
36
66
private $ appStateMock ;
37
67
38
68
/**
39
- * @var \Magento\Framework\App\Cache\TypeListInterface |\PHPUnit_Framework_MockObject_MockObject
69
+ * @var StringUtils |\PHPUnit_Framework_MockObject_MockObject
40
70
*/
41
- private $ appCacheMock ;
71
+ private $ resourceMock ;
42
72
43
73
/**
44
- * @var \Magento\Framework\Translate\InlineInterface |\PHPUnit_Framework_MockObject_MockObject
74
+ * @var CacheManager |\PHPUnit_Framework_MockObject_MockObject
45
75
*/
46
- private $ translateInlineMock ;
76
+ private $ cacheManagerMock ;
47
77
48
78
protected function setUp ()
49
79
{
50
- $ this ->resourceMock = $ this ->getMockBuilder ('Magento\Translation\Model\ResourceModel\StringUtilsFactory ' )
51
- ->disableOriginalConstructor ()
52
- ->setMethods ([])
80
+ $ this ->objectManager = new ObjectManager ($ this );
81
+ $ this ->translateInlineMock = $ this ->getMockForAbstractClass ('Magento\Framework\Translate\InlineInterface ' );
82
+ $ this ->appCacheMock = $ this ->getMockForAbstractClass ('Magento\Framework\App\Cache\TypeListInterface ' );
83
+ $ this ->storeManagerMock = $ this ->getMockForAbstractClass ('Magento\Store\Model\StoreManagerInterface ' );
84
+ $ this ->storeMock = $ this ->getMockForAbstractClass ('Magento\Store\Api\Data\StoreInterface ' );
85
+ $ this ->storeManagerMock ->expects ($ this ->any ())
86
+ ->method ('getStore ' )
87
+ ->willReturn ($ this ->storeMock );
88
+ $ this ->resourceFactoryMock = $ this ->getMockBuilder ('Magento\Translation\Model\ResourceModel\StringUtilsFactory ' )
89
+ ->setMethods (['create ' ])
53
90
->getMock ();
54
-
55
- $ this ->storeManagerMock = $ this ->getMockBuilder ('Magento\Store\Model\StoreManagerInterface ' )
91
+ $ this ->resourceMock = $ this ->getMockBuilder ('Magento\Translation\Model\ResourceModel\StringUtils ' )
56
92
->disableOriginalConstructor ()
57
93
->setMethods ([])
58
94
->getMock ();
59
95
60
- $ this ->inputFilterMock = $ this ->getMockBuilder ('Zend_Filter_Interface ' )
61
- ->disableOriginalConstructor ()
62
- ->setMethods ([])
63
- ->getMock ();
96
+ $ this ->inputFilterMock = $ this ->getMockBuilder ('Zend_Filter_Interface ' );
64
97
65
- $ this ->appStateMock = $ this ->getMockBuilder ('Magento\Framework\App\State ' )
98
+ $ this ->resourceFactoryMock ->expects ($ this ->any ())
99
+ ->method ('create ' )
100
+ ->willReturn ($ this ->resourceMock );
101
+ $ this ->cacheManagerMock = $ this ->getMockBuilder ('Magento\Translation\Model\Inline\CacheManager ' )
66
102
->disableOriginalConstructor ()
67
103
->setMethods ([])
68
104
->getMock ();
69
105
70
- $ this ->appCacheMock = $ this ->getMockBuilder ('Magento\Framework\App\Cache\TypeListInterface ' )
106
+ $ this ->appStateMock = $ this ->getMockBuilder ('Magento\Framework\App\State ' )
71
107
->disableOriginalConstructor ()
72
108
->setMethods ([])
73
109
->getMock ();
110
+ }
74
111
75
- $ this ->translateInlineMock = $ this ->getMockBuilder ('Magento\Framework\Translate\InlineInterface ' )
76
- ->disableOriginalConstructor ()
77
- ->setMethods ([])
78
- ->getMock ();
112
+ public function testProcessAjaxPostNotAllowed ()
113
+ {
114
+ $ expected = ['inline ' => 'not allowed ' ];
115
+ $ this ->translateInlineMock ->expects ($ this ->once ())
116
+ ->method ('isAllowed ' )
117
+ ->willReturn (false );
118
+ $ this ->model = $ this ->objectManager ->getObject (
119
+ Parser::class,
120
+ ['translateInline ' => $ this ->translateInlineMock ]
121
+ );
122
+ $ this ->assertEquals ($ expected , $ this ->model ->processAjaxPost ([]));
123
+ }
79
124
80
- $ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
81
- $ this ->model = $ objectManagerHelper ->getObject (
82
- 'Magento\Translation\Model\Inline\Parser ' ,
125
+ public function testProcessAjaxPost ()
126
+ {
127
+ $ this ->translateInlineMock ->expects ($ this ->once ())
128
+ ->method ('isAllowed ' )
129
+ ->willReturn (true );
130
+ $ this ->model = $ this ->objectManager ->getObject (
131
+ Parser::class,
83
132
[
84
- "_resourceFactory " => $ this ->resourceMock ,
85
- "_storeManager " => $ this ->storeManagerMock ,
86
- "_inputFilter " => $ this ->inputFilterMock ,
87
- "_appState " => $ this ->appStateMock ,
88
- "_appCache " => $ this ->appCacheMock ,
89
- "_translateInline " => $ this ->translateInlineMock
133
+ 'cacheManager ' => $ this ->cacheManagerMock ,
134
+ 'resource ' => $ this ->resourceFactoryMock ,
135
+ 'storeManager ' => $ this ->storeManagerMock ,
136
+ 'translateInline ' => $ this ->translateInlineMock
90
137
]
91
138
);
139
+ $ this ->model ->processAjaxPost ([]);
92
140
}
93
141
94
142
public function testProcessResponseBodyStringProcessingAttributesCorrectly ()
@@ -104,6 +152,21 @@ public function testProcessResponseBodyStringProcessingAttributesCorrectly()
104
152
];
105
153
$ this ->translateInlineMock ->expects ($ this ->any ())->method ('getAdditionalHtmlAttribute ' )->willReturn (null );
106
154
155
+ $ this ->model = $ this ->objectManager ->getObject (
156
+ Parser::class,
157
+ [
158
+ 'cacheManager ' => $ this ->cacheManagerMock ,
159
+ 'resource ' => $ this ->resourceFactoryMock ,
160
+ 'storeManager ' => $ this ->storeManagerMock ,
161
+ 'translateInline ' => $ this ->translateInlineMock ,
162
+ '_resourceFactory ' => $ this ->resourceMock ,
163
+ '_inputFilter ' => $ this ->inputFilterMock ,
164
+ '_appState ' => $ this ->appStateMock ,
165
+ '_appCache ' => $ this ->appCacheMock ,
166
+ '_translateInline ' => $ this ->translateInlineMock
167
+ ]
168
+ );
169
+
107
170
$ processedContent = $ this ->model ->processResponseBodyString ($ testContent );
108
171
foreach ($ processedAttributes as $ attribute ) {
109
172
$ this ->assertContains ($ attribute , $ processedContent , "data-translate attribute not processed correctly " );
0 commit comments