Skip to content

Commit 07a296a

Browse files
committed
Fix #19872 - unit tests for fileInfo with pub/ and root Magento install dir
1 parent 8522a14 commit 07a296a

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Category/FileInfoTest.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function setUp()
6767
$this->baseDirectory->expects($this->any())
6868
->method('getAbsolutePath')
6969
->with(null)
70-
->willReturn('/a/b/c');
70+
->willReturn('/a/b/c/');
7171

7272
$this->model = new FileInfo(
7373
$this->filesystem,
@@ -85,12 +85,12 @@ public function testGetMimeType()
8585
$this->mediaDirectory->expects($this->at(0))
8686
->method('getAbsolutePath')
8787
->with(null)
88-
->willReturn('/a/b/c/pub/media');
88+
->willReturn('/a/b/c/pub/media/');
8989

9090
$this->mediaDirectory->expects($this->at(1))
9191
->method('getAbsolutePath')
9292
->with(null)
93-
->willReturn('/a/b/c/pub/media');
93+
->willReturn('/a/b/c/pub/media/');
9494

9595
$this->mediaDirectory->expects($this->at(2))
9696
->method('getAbsolutePath')
@@ -116,7 +116,7 @@ public function testGetStat()
116116
$this->mediaDirectory->expects($this->any())
117117
->method('getAbsolutePath')
118118
->with(null)
119-
->willReturn('/a/b/c/pub/media');
119+
->willReturn('/a/b/c/pub/media/');
120120

121121
$this->mediaDirectory->expects($this->once())
122122
->method('stat')
@@ -130,22 +130,55 @@ public function testGetStat()
130130
$this->assertEquals(1, $result['size']);
131131
}
132132

133-
public function testIsExist()
133+
/**
134+
* @param $fileName
135+
* @param $fileMediaPath
136+
* @dataProvider isExistProvider
137+
*/
138+
public function testIsExist($fileName, $fileMediaPath)
134139
{
135-
$mediaPath = '/catalog/category';
136-
137-
$fileName = '/filename.ext1';
138-
139140
$this->mediaDirectory->expects($this->any())
140141
->method('getAbsolutePath')
141-
->with(null)
142-
->willReturn('/a/b/c/pub/media');
142+
->willReturn('/a/b/c/pub/media/');
143143

144144
$this->mediaDirectory->expects($this->once())
145145
->method('isExist')
146-
->with($mediaPath . $fileName)
146+
->with($fileMediaPath)
147147
->willReturn(true);
148148

149149
$this->assertTrue($this->model->isExist($fileName));
150150
}
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+
}
151184
}

0 commit comments

Comments
 (0)