@@ -38,6 +38,11 @@ class EditorTest extends \PHPUnit_Framework_TestCase
38
38
*/
39
39
protected $ formMock ;
40
40
41
+ /**
42
+ * @var \Magento\Framework\Object|\PHPUnit_Framework_MockObject_MockObject
43
+ */
44
+ protected $ configMock ;
45
+
41
46
protected function setUp ()
42
47
{
43
48
$ this ->factoryMock = $ this ->getMock ('\Magento\Framework\Data\Form\Element\Factory ' , [], [], '' , false );
@@ -49,17 +54,23 @@ protected function setUp()
49
54
false
50
55
);
51
56
$ this ->escaperMock = $ this ->getMock ('\Magento\Framework\Escaper ' , [], [], '' , false );
57
+ $ this ->configMock = $ this ->getMock ('\Magento\Framework\Object ' , ['getData ' ], [], '' , false );
52
58
53
59
$ this ->model = new Editor (
54
60
$ this ->factoryMock ,
55
61
$ this ->collectionFactoryMock ,
56
- $ this ->escaperMock
62
+ $ this ->escaperMock ,
63
+ ['config ' => $ this ->configMock ]
57
64
);
58
65
59
- $ this ->formMock = new \Magento \Framework \Object ();
60
- $ this ->formMock ->getHtmlIdPrefix ('id_prefix ' );
61
- $ this ->formMock ->getHtmlIdPrefix ('id_suffix ' );
62
-
66
+ $ this ->formMock = $ this ->getMock (
67
+ 'Magento\Framework\Data\Form ' ,
68
+ ['getHtmlIdPrefix ' , 'getHtmlIdSuffix ' ],
69
+ [],
70
+ '' ,
71
+ false ,
72
+ false
73
+ );
63
74
$ this ->model ->setForm ($ this ->formMock );
64
75
}
65
76
@@ -70,15 +81,14 @@ public function testConstruct()
70
81
$ this ->assertEquals (Editor::DEFAULT_ROWS , $ this ->model ->getRows ());
71
82
$ this ->assertEquals (Editor::DEFAULT_COLS , $ this ->model ->getCols ());
72
83
73
- $ config = new \ Magento \ Framework \ Object ( );
74
- $ config -> setData ( ' enabled ' , true );
84
+ $ this -> configMock -> expects ( $ this -> once ())-> method ( ' getData ' )-> with ( ' enabled ' )-> willReturn ( true );
85
+
75
86
$ model = new Editor (
76
87
$ this ->factoryMock ,
77
88
$ this ->collectionFactoryMock ,
78
89
$ this ->escaperMock ,
79
- ['config ' => $ config ]
90
+ ['config ' => $ this -> configMock ]
80
91
);
81
- $ model ->setForm ($ this ->formMock );
82
92
83
93
$ this ->assertEquals ('wysiwyg ' , $ model ->getType ());
84
94
$ this ->assertEquals ('wysiwyg ' , $ model ->getExtType ());
@@ -93,13 +103,25 @@ public function testGetElementHtml()
93
103
$ this ->assertRegExp ('/class=\".*textarea.*\"/i ' , $ html );
94
104
$ this ->assertNotRegExp ('/.*mage\/adminhtml\/wysiwyg\/widget.*/i ' , $ html );
95
105
96
- $ this ->model ->getConfig ()->setData ('enabled ' , true );
106
+ $ this ->configMock ->expects ($ this ->any ())->method ('getData ' )
107
+ ->willReturnMap (
108
+ [
109
+ ['enabled ' , null , true ],
110
+ ['hidden ' , null , null ]
111
+ ]
112
+ );
97
113
$ html = $ this ->model ->getElementHtml ();
98
114
$ this ->assertRegExp ('/.*mage\/adminhtml\/wysiwyg\/widget.*/i ' , $ html );
99
115
100
- $ this ->model ->getConfig ()->setData ('widget_window_url ' , 'localhost ' );
101
- $ this ->model ->getConfig ()->unsetData ('enabled ' );
102
- $ this ->model ->getConfig ()->setData ('add_widgets ' , true );
116
+ $ this ->configMock ->expects ($ this ->any ())->method ('getData ' )
117
+ ->willReturnMap (
118
+ [
119
+ ['enabled ' , null , null ],
120
+ ['widget_window_url ' , null , 'localhost ' ],
121
+ ['add_widgets ' , null , true ],
122
+ ['hidden ' , null , null ]
123
+ ]
124
+ );
103
125
$ html = $ this ->model ->getElementHtml ();
104
126
$ this ->assertRegExp ('/.*mage\/adminhtml\/wysiwyg\/widget.*/i ' , $ html );
105
127
}
@@ -112,15 +134,15 @@ public function testIsEnabled()
112
134
$ this ->assertTrue ($ this ->model ->isEnabled ());
113
135
114
136
$ this ->model ->unsetData ('wysiwyg ' );
115
- $ this ->model -> getConfig ()-> setData ( ' enabled ', true );
137
+ $ this ->configMock -> expects ( $ this -> once ())-> method ( ' getData ' )-> with ( ' enabled ')-> willReturn ( true );
116
138
$ this ->assertTrue ($ this ->model ->isEnabled ());
117
139
}
118
140
119
141
public function testIsHidden ()
120
142
{
121
143
$ this ->assertEmpty ($ this ->model ->isHidden ());
122
144
123
- $ this ->model -> getConfig ()-> setData ( ' hidden ', true );
145
+ $ this ->configMock -> expects ( $ this -> once ())-> method ( ' getData ' )-> with ( ' hidden ')-> willReturn ( true );
124
146
$ this ->assertTrue ($ this ->model ->isHidden ());
125
147
}
126
148
@@ -131,10 +153,10 @@ public function testTranslate()
131
153
132
154
public function testGetConfig ()
133
155
{
134
- $ config = new \Magento \Framework \Object ( );
156
+ $ config = $ this -> getMock ( ' \Magento\Framework\Object ' , [ ' getData ' ], [], '' , false );
135
157
$ this ->assertEquals ($ config , $ this ->model ->getConfig ());
136
158
137
- $ this ->model -> getConfig ()-> setData ( ' test ', 'test ' );
159
+ $ this ->configMock -> expects ( $ this -> once ())-> method ( ' getData ' )-> with ( ' test ')-> willReturn ( 'test ' );
138
160
$ this ->assertEquals ('test ' , $ this ->model ->getConfig ('test ' ));
139
161
}
140
162
@@ -143,7 +165,7 @@ public function testGetConfig()
143
165
*/
144
166
public function testGetTranslatedString ()
145
167
{
146
- $ this ->model -> getConfig ()-> setData ( ' enabled ', true );
168
+ $ this ->configMock -> expects ( $ this -> any ())-> method ( ' getData ' )-> withConsecutive ([ ' enabled '])-> willReturn ( true );
147
169
$ html = $ this ->model ->getElementHtml ();
148
170
$ this ->assertRegExp ('/.*"Insert Image...":"Insert Image...".*/i ' , $ html );
149
171
}
0 commit comments