@@ -67,7 +67,7 @@ protected function setUp()
67
67
$ this ->baseDirectory ->expects ($ this ->any ())
68
68
->method ('getAbsolutePath ' )
69
69
->with (null )
70
- ->willReturn ('/a/b/c ' );
70
+ ->willReturn ('/a/b/c/ ' );
71
71
72
72
$ this ->model = new FileInfo (
73
73
$ this ->filesystem ,
@@ -85,12 +85,12 @@ public function testGetMimeType()
85
85
$ this ->mediaDirectory ->expects ($ this ->at (0 ))
86
86
->method ('getAbsolutePath ' )
87
87
->with (null )
88
- ->willReturn ('/a/b/c/pub/media ' );
88
+ ->willReturn ('/a/b/c/pub/media/ ' );
89
89
90
90
$ this ->mediaDirectory ->expects ($ this ->at (1 ))
91
91
->method ('getAbsolutePath ' )
92
92
->with (null )
93
- ->willReturn ('/a/b/c/pub/media ' );
93
+ ->willReturn ('/a/b/c/pub/media/ ' );
94
94
95
95
$ this ->mediaDirectory ->expects ($ this ->at (2 ))
96
96
->method ('getAbsolutePath ' )
@@ -116,7 +116,7 @@ public function testGetStat()
116
116
$ this ->mediaDirectory ->expects ($ this ->any ())
117
117
->method ('getAbsolutePath ' )
118
118
->with (null )
119
- ->willReturn ('/a/b/c/pub/media ' );
119
+ ->willReturn ('/a/b/c/pub/media/ ' );
120
120
121
121
$ this ->mediaDirectory ->expects ($ this ->once ())
122
122
->method ('stat ' )
@@ -130,22 +130,55 @@ public function testGetStat()
130
130
$ this ->assertEquals (1 , $ result ['size ' ]);
131
131
}
132
132
133
- public function testIsExist ()
133
+ /**
134
+ * @param $fileName
135
+ * @param $fileMediaPath
136
+ * @dataProvider isExistProvider
137
+ */
138
+ public function testIsExist ($ fileName , $ fileMediaPath )
134
139
{
135
- $ mediaPath = '/catalog/category ' ;
136
-
137
- $ fileName = '/filename.ext1 ' ;
138
-
139
140
$ this ->mediaDirectory ->expects ($ this ->any ())
140
141
->method ('getAbsolutePath ' )
141
- ->with (null )
142
- ->willReturn ('/a/b/c/pub/media ' );
142
+ ->willReturn ('/a/b/c/pub/media/ ' );
143
143
144
144
$ this ->mediaDirectory ->expects ($ this ->once ())
145
145
->method ('isExist ' )
146
- ->with ($ mediaPath . $ fileName )
146
+ ->with ($ fileMediaPath )
147
147
->willReturn (true );
148
148
149
149
$ this ->assertTrue ($ this ->model ->isExist ($ fileName ));
150
150
}
151
+
152
+ public function isExistProvider ()
153
+ {
154
+ return [
155
+ ['/filename.ext1 ' , '/catalog/category/filename.ext1 ' ],
156
+ ['/pub/media/filename.ext1 ' , 'filename.ext1 ' ],
157
+ ['/media/filename.ext1 ' , 'filename.ext1 ' ]
158
+ ];
159
+ }
160
+
161
+ /**
162
+ * @param $fileName
163
+ * @param $expected
164
+ * @dataProvider isBeginsWithMediaDirectoryPathProvider
165
+ */
166
+ public function testIsBeginsWithMediaDirectoryPath ($ fileName , $ expected )
167
+ {
168
+ $ this ->mediaDirectory ->expects ($ this ->any ())
169
+ ->method ('getAbsolutePath ' )
170
+ ->willReturn ('/a/b/c/pub/media/ ' );
171
+
172
+ $ this ->assertEquals ($ expected , $ this ->model ->isBeginsWithMediaDirectoryPath ($ fileName ));
173
+ }
174
+
175
+ public function isBeginsWithMediaDirectoryPathProvider ()
176
+ {
177
+ return [
178
+ ['/pub/media/test/filename.ext1 ' , true ],
179
+ ['/media/test/filename.ext1 ' , true ],
180
+ ['/test/filename.ext1 ' , false ],
181
+ ['test2/filename.ext1 ' , false ]
182
+ ];
183
+ }
151
184
}
0 commit comments