5
5
*/
6
6
namespace Magento \Sales \Test \Unit \Model \Order \Pdf ;
7
7
8
+ use Magento \MediaStorage \Helper \File \Storage \Database ;
9
+ use Magento \Sales \Model \Order \Invoice ;
10
+ use Magento \Sales \Model \Order ;
11
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
12
+ use Magento \Sales \Model \Order \Address ;
13
+ use Magento \Sales \Model \Order \Address \Renderer ;
14
+
15
+ /**
16
+ * Class InvoiceTest
17
+ *
18
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19
+ */
8
20
class InvoiceTest extends \PHPUnit \Framework \TestCase
9
21
{
10
22
/**
@@ -17,29 +29,68 @@ class InvoiceTest extends \PHPUnit\Framework\TestCase
17
29
*/
18
30
protected $ _pdfConfigMock ;
19
31
32
+ /**
33
+ * @var Database|\PHPUnit_Framework_MockObject_MockObject
34
+ */
35
+ protected $ databaseMock ;
36
+
37
+ /**
38
+ * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
39
+ */
40
+ protected $ scopeConfigMock ;
41
+
42
+ /**
43
+ * @var \Magento\Framework\Filesystem\Directory\Write|\PHPUnit_Framework_MockObject_MockObject
44
+ */
45
+ protected $ directoryMock ;
46
+
47
+ /**
48
+ * @var Renderer|\PHPUnit_Framework_MockObject_MockObject
49
+ */
50
+ protected $ addressRendererMock ;
51
+
52
+ /**
53
+ * @var \Magento\Payment\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
54
+ */
55
+ protected $ paymentDataMock ;
56
+
20
57
protected function setUp ()
21
58
{
22
59
$ this ->_pdfConfigMock = $ this ->getMockBuilder (\Magento \Sales \Model \Order \Pdf \Config::class)
23
60
->disableOriginalConstructor ()
24
61
->getMock ();
25
- $ directoryMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \Write::class);
26
- $ directoryMock ->expects ($ this ->any ())->method ('getAbsolutePath ' )->will (
62
+ $ this -> directoryMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \Write::class);
63
+ $ this -> directoryMock ->expects ($ this ->any ())->method ('getAbsolutePath ' )->will (
27
64
$ this ->returnCallback (
28
65
function ($ argument ) {
29
66
return BP . '/ ' . $ argument ;
30
67
}
31
68
)
32
69
);
33
70
$ filesystemMock = $ this ->createMock (\Magento \Framework \Filesystem::class);
34
- $ filesystemMock ->expects ($ this ->any ())->method ('getDirectoryRead ' )->will ($ this ->returnValue ($ directoryMock ));
35
- $ filesystemMock ->expects ($ this ->any ())->method ('getDirectoryWrite ' )->will ($ this ->returnValue ($ directoryMock ));
71
+ $ filesystemMock ->expects ($ this ->any ())
72
+ ->method ('getDirectoryRead ' )
73
+ ->will ($ this ->returnValue ($ this ->directoryMock ));
74
+ $ filesystemMock ->expects ($ this ->any ())
75
+ ->method ('getDirectoryWrite ' )
76
+ ->will ($ this ->returnValue ($ this ->directoryMock ));
77
+
78
+ $ this ->databaseMock = $ this ->createMock (Database::class);
79
+ $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
80
+ $ this ->addressRendererMock = $ this ->createMock (Renderer::class);
81
+ $ this ->paymentDataMock = $ this ->createMock (\Magento \Payment \Helper \Data::class);
36
82
37
83
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
38
84
$ this ->_model = $ helper ->getObject (
39
85
\Magento \Sales \Model \Order \Pdf \Invoice::class,
40
86
[
41
87
'filesystem ' => $ filesystemMock ,
42
88
'pdfConfig ' => $ this ->_pdfConfigMock ,
89
+ 'fileStorageDatabase ' => $ this ->databaseMock ,
90
+ 'scopeConfig ' => $ this ->scopeConfigMock ,
91
+ 'addressRenderer ' => $ this ->addressRendererMock ,
92
+ 'string ' => new \Magento \Framework \Stdlib \StringUtils (),
93
+ 'paymentData ' => $ this ->paymentDataMock
43
94
]
44
95
);
45
96
}
@@ -72,4 +123,83 @@ public function testGetPdfInitRenderer()
72
123
$ renderers ->getValue ($ this ->_model )
73
124
);
74
125
}
126
+
127
+ public function testInsertLogoDatabaseMediaStorage ()
128
+ {
129
+ $ filename = 'image.jpg ' ;
130
+ $ path = '/sales/store/logo/ ' ;
131
+
132
+ $ this ->_pdfConfigMock ->expects ($ this ->once ())
133
+ ->method ('getRenderersPerProduct ' )
134
+ ->with ('invoice ' )
135
+ ->will ($ this ->returnValue (['product_type_one ' => 'Renderer_Type_One_Product_One ' ]));
136
+ $ this ->_pdfConfigMock ->expects ($ this ->any ())
137
+ ->method ('getTotals ' )
138
+ ->will ($ this ->returnValue ([]));
139
+
140
+ $ block = $ this ->getMockBuilder (\Magento \Framework \View \Element \Template::class)
141
+ ->disableOriginalConstructor ()
142
+ ->setMethods (['setIsSecureMode ' ,'toPdf ' ])
143
+ ->getMock ();
144
+ $ block ->expects ($ this ->any ())
145
+ ->method ('setIsSecureMode ' )
146
+ ->willReturn ($ block );
147
+ $ block ->expects ($ this ->any ())
148
+ ->method ('toPdf ' )
149
+ ->will ($ this ->returnValue ('' ));
150
+ $ this ->paymentDataMock ->expects ($ this ->any ())
151
+ ->method ('getInfoBlock ' )
152
+ ->willReturn ($ block );
153
+
154
+ $ this ->addressRendererMock ->expects ($ this ->any ())
155
+ ->method ('format ' )
156
+ ->will ($ this ->returnValue ('' ));
157
+
158
+ $ this ->databaseMock ->expects ($ this ->any ())
159
+ ->method ('checkDbUsage ' )
160
+ ->will ($ this ->returnValue (true ));
161
+
162
+ $ invoiceMock = $ this ->createMock (Invoice::class);
163
+ $ orderMock = $ this ->createMock (Order::class);
164
+ $ addressMock = $ this ->createMock (Address::class);
165
+ $ orderMock ->expects ($ this ->any ())
166
+ ->method ('getBillingAddress ' )
167
+ ->willReturn ($ addressMock );
168
+ $ orderMock ->expects ($ this ->any ())
169
+ ->method ('getIsVirtual ' )
170
+ ->will ($ this ->returnValue (true ));
171
+ $ infoMock = $ this ->createMock (\Magento \Payment \Model \InfoInterface::class);
172
+ $ orderMock ->expects ($ this ->any ())
173
+ ->method ('getPayment ' )
174
+ ->willReturn ($ infoMock );
175
+ $ invoiceMock ->expects ($ this ->any ())
176
+ ->method ('getOrder ' )
177
+ ->willReturn ($ orderMock );
178
+ $ invoiceMock ->expects ($ this ->any ())
179
+ ->method ('getAllItems ' )
180
+ ->willReturn ([]);
181
+
182
+ $ this ->scopeConfigMock ->expects ($ this ->at (0 ))
183
+ ->method ('getValue ' )
184
+ ->with ('sales/identity/logo ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , null )
185
+ ->will ($ this ->returnValue ($ filename ));
186
+ $ this ->scopeConfigMock ->expects ($ this ->at (1 ))
187
+ ->method ('getValue ' )
188
+ ->with ('sales/identity/address ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , null )
189
+ ->will ($ this ->returnValue ('' ));
190
+
191
+ $ this ->directoryMock ->expects ($ this ->any ())
192
+ ->method ('isFile ' )
193
+ ->with ($ path . $ filename )
194
+ ->willReturnOnConsecutiveCalls (
195
+ $ this ->returnValue (false ),
196
+ $ this ->returnValue (false )
197
+ );
198
+
199
+ $ this ->databaseMock ->expects ($ this ->once ())
200
+ ->method ('saveFileToFilesystem ' )
201
+ ->with ($ path . $ filename );
202
+
203
+ $ this ->_model ->getPdf ([$ invoiceMock ]);
204
+ }
75
205
}
0 commit comments