@@ -68,10 +68,11 @@ protected function setUp()
68
68
69
69
$ this ->readFactory = $ this ->getMockBuilder ('\Magento\Framework\Filesystem\File\ReadFactory ' )
70
70
->disableOriginalConstructor ()
71
+ ->setMethods (['create ' ])
71
72
->getMock ();
72
73
73
74
$ this ->directoryMock = $ this ->getMockBuilder ('\Magento\Framework\Filesystem\Directory\Writer ' )
74
- ->setMethods (['writeFile ' , 'getRelativePath ' ])
75
+ ->setMethods (['writeFile ' , 'getRelativePath ' , ' isWritable ' , ' getAbsolutePath ' ])
75
76
->disableOriginalConstructor ()
76
77
->getMock ();
77
78
@@ -92,6 +93,7 @@ protected function setUp()
92
93
$ this ->filesystem ,
93
94
$ this ->readFactory ,
94
95
])
96
+ ->setMethods (['_setUploadFile ' , 'save ' , 'getTmpDir ' ])
95
97
->getMock ();
96
98
}
97
99
@@ -100,10 +102,14 @@ protected function setUp()
100
102
*/
101
103
public function testMoveFileUrl ($ fileUrl , $ expectedHost , $ expectedFileName )
102
104
{
105
+ $ destDir = 'var/dest/dir ' ;
103
106
$ expectedRelativeFilePath = $ this ->uploader ->getTmpDir () . '/ ' . $ expectedFileName ;
107
+ $ this ->directoryMock ->expects ($ this ->once ())->method ('isWritable ' )->with ($ destDir )->willReturn (true );
104
108
$ this ->directoryMock ->expects ($ this ->any ())->method ('getRelativePath ' )->with ($ expectedRelativeFilePath );
109
+ $ this ->directoryMock ->expects ($ this ->once ())->method ('getAbsolutePath ' )->with ($ destDir )
110
+ ->willReturn ($ destDir . '/ ' . $ expectedFileName );
105
111
// Check writeFile() method invoking.
106
- $ this ->directoryMock ->expects ($ this ->any ())->method ('writeFile ' )->will ($ this ->returnValue (null ));
112
+ $ this ->directoryMock ->expects ($ this ->any ())->method ('writeFile ' )->will ($ this ->returnValue ($ expectedFileName ));
107
113
108
114
// Create adjusted reader which does not validate path.
109
115
$ readMock = $ this ->getMockBuilder ('Magento\Framework\Filesystem\File\Read ' )
@@ -113,59 +119,39 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
113
119
// Check readAll() method invoking.
114
120
$ readMock ->expects ($ this ->once ())->method ('readAll ' )->will ($ this ->returnValue (null ));
115
121
116
- $ this ->readFactory = $ this ->getMockBuilder ('\Magento\Framework\Filesystem\File\ReadFactory ' )
117
- ->disableOriginalConstructor ()
118
- ->setMethods (['create ' ])
119
- ->getMock ();
120
122
// Check create() method invoking with expected argument.
121
123
$ this ->readFactory ->expects ($ this ->once ())
122
- ->method ('create ' )
123
- ->will ($ this ->returnValue ($ readMock ))->with ($ expectedHost );
124
-
125
- $ uploaderMock = $ this ->getMockBuilder ('\Magento\CatalogImportExport\Model\Import\Uploader ' )
126
- ->setConstructorArgs ([
127
- $ this ->coreFileStorageDb ,
128
- $ this ->coreFileStorage ,
129
- $ this ->imageFactory ,
130
- $ this ->validator ,
131
- $ this ->filesystem ,
132
- $ this ->readFactory ,
133
- ])
134
- ->setMethods (['_setUploadFile ' , 'save ' , 'getTmpDir ' ])
135
- ->getMock ();
124
+ ->method ('create ' )
125
+ ->will ($ this ->returnValue ($ readMock ))->with ($ expectedHost );
136
126
137
127
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
138
- $ uploaderMock ->expects ($ this ->any ())->method ('getTmpDir ' )->will ($ this ->returnValue ('' ));
139
- $ uploaderMock ->expects ($ this ->once ())->method ('_setUploadFile ' )->will ($ this ->returnSelf ());
140
- $ uploaderMock ->expects ($ this ->once ())->method ('save ' )->will ($ this ->returnValue (['name ' => null ]));
128
+ $ this ->uploader ->expects ($ this ->any ())->method ('getTmpDir ' )->will ($ this ->returnValue ('' ));
129
+ $ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )->will ($ this ->returnSelf ());
130
+ $ this ->uploader ->expects ($ this ->once ())->method ('save ' )->with ($ destDir . '/ ' . $ expectedFileName )
131
+ ->willReturn (['name ' => $ expectedFileName ]);
141
132
142
- $ uploaderMock ->move ($ fileUrl );
133
+ $ this ->uploader ->setDestDir ($ destDir );
134
+ $ this ->assertEquals (['name ' => $ expectedFileName ], $ this ->uploader ->move ($ fileUrl ));
143
135
}
144
136
145
137
public function testMoveFileName ()
146
138
{
139
+ $ destDir = 'var/dest/dir ' ;
147
140
$ fileName = 'test_uploader_file ' ;
148
141
$ expectedRelativeFilePath = $ this ->uploader ->getTmpDir () . '/ ' . $ fileName ;
142
+ $ this ->directoryMock ->expects ($ this ->once ())->method ('isWritable ' )->with ($ destDir )->willReturn (true );
149
143
$ this ->directoryMock ->expects ($ this ->any ())->method ('getRelativePath ' )->with ($ expectedRelativeFilePath );
150
-
151
- $ uploaderMock = $ this ->getMockBuilder ('\Magento\CatalogImportExport\Model\Import\Uploader ' )
152
- ->setConstructorArgs ([
153
- $ this ->coreFileStorageDb ,
154
- $ this ->coreFileStorage ,
155
- $ this ->imageFactory ,
156
- $ this ->validator ,
157
- $ this ->filesystem ,
158
- $ this ->readFactory ,
159
- ])
160
- ->setMethods (['_setUploadFile ' , 'save ' , 'getTmpDir ' ])
161
- ->getMock ();
144
+ $ this ->directoryMock ->expects ($ this ->once ())->method ('getAbsolutePath ' )->with ($ destDir )
145
+ ->willReturn ($ destDir . '/ ' . $ fileName );
162
146
163
147
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
164
- $ uploaderMock ->expects ($ this ->once ())->method ('getTmpDir ' )->will ($ this ->returnValue ('' ));
165
- $ uploaderMock ->expects ($ this ->once ())->method ('_setUploadFile ' )->will ($ this ->returnSelf ());
166
- $ uploaderMock ->expects ($ this ->once ())->method ('save ' )->will ($ this ->returnValue (['name ' => null ]));
148
+ $ this ->uploader ->expects ($ this ->once ())->method ('getTmpDir ' )->will ($ this ->returnValue ('' ));
149
+ $ this ->uploader ->expects ($ this ->once ())->method ('_setUploadFile ' )->will ($ this ->returnSelf ());
150
+ $ this ->uploader ->expects ($ this ->once ())->method ('save ' )->with ($ destDir . '/ ' . $ fileName )
151
+ ->willReturn (['name ' => $ fileName ]);
167
152
168
- $ uploaderMock ->move ($ fileName );
153
+ $ this ->uploader ->setDestDir ($ destDir );
154
+ $ this ->assertEquals (['name ' => $ fileName ], $ this ->uploader ->move ($ fileName ));
169
155
}
170
156
171
157
public function moveFileUrlDataProvider ()
0 commit comments