Skip to content

Commit 82bbc1c

Browse files
committed
Update tests to expect media file paths are normalized on construct
1 parent 4e9ea80 commit 82bbc1c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

packages/framework/tests/Unit/Support/MediaFileTest.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testCanConstruct()
6868
$file = new MediaFile('foo');
6969

7070
$this->assertInstanceOf(MediaFile::class, $file);
71-
$this->assertSame('foo', $file->path);
71+
$this->assertSame('_media/foo', $file->path);
7272
}
7373

7474
public function testCanMake()
@@ -78,7 +78,7 @@ public function testCanMake()
7878

7979
public function testCanConstructWithNestedPaths()
8080
{
81-
$this->assertSame('path/to/file.txt', MediaFile::make('path/to/file.txt')->path);
81+
$this->assertSame('_media/path/to/file.txt', MediaFile::make('path/to/file.txt')->path);
8282
}
8383

8484
public function testPathIsNormalizedToRelativeMediaPath()
@@ -88,17 +88,17 @@ public function testPathIsNormalizedToRelativeMediaPath()
8888

8989
public function testAbsolutePathIsNormalizedToRelativeMediaPath()
9090
{
91-
$this->assertSame('foo', MediaFile::make(Hyde::path('foo'))->path);
91+
$this->assertSame('_media/foo', MediaFile::make(Hyde::path('foo'))->path);
9292
}
9393

9494
public function testMediaPathIsNormalizedToRelativeMediaPath()
9595
{
96-
$this->assertSame('foo', MediaFile::make('_media/foo')->path);
96+
$this->assertSame('_media/foo', MediaFile::make('_media/foo')->path);
9797
}
9898

9999
public function testAbsoluteMediaPathIsNormalizedToRelativeMediaPath()
100100
{
101-
$this->assertSame('foo', MediaFile::make(Hyde::path('_media/foo'))->path);
101+
$this->assertSame('_media/foo', MediaFile::make(Hyde::path('_media/foo'))->path);
102102
}
103103

104104
public function testGetNameReturnsNameOfFile()
@@ -109,122 +109,122 @@ public function testGetNameReturnsNameOfFile()
109109

110110
public function testGetPathReturnsPathOfFile()
111111
{
112-
$this->assertSame('foo.txt', MediaFile::make('foo.txt')->getPath());
113-
$this->assertSame('foo/bar.txt', MediaFile::make('foo/bar.txt')->getPath());
112+
$this->assertSame('_media/foo.txt', MediaFile::make('foo.txt')->getPath());
113+
$this->assertSame('_media/foo/bar.txt', MediaFile::make('foo/bar.txt')->getPath());
114114
}
115115

116116
public function testGetAbsolutePathReturnsAbsolutePathOfFile()
117117
{
118-
$this->assertSame(Hyde::path('foo.txt'), MediaFile::make('foo.txt')->getAbsolutePath());
119-
$this->assertSame(Hyde::path('foo/bar.txt'), MediaFile::make('foo/bar.txt')->getAbsolutePath());
118+
$this->assertSame(Hyde::path('_media/foo.txt'), MediaFile::make('foo.txt')->getAbsolutePath());
119+
$this->assertSame(Hyde::path('_media/foo/bar.txt'), MediaFile::make('foo/bar.txt')->getAbsolutePath());
120120
}
121121

122122
public function testGetContentsReturnsContentsOfFile()
123123
{
124-
$this->file('foo.txt', 'foo bar');
124+
$this->file('_media/foo.txt', 'foo bar');
125125
$this->assertSame('foo bar', MediaFile::make('foo.txt')->getContents());
126126
}
127127

128128
public function testGetExtensionReturnsExtensionOfFile()
129129
{
130-
$this->file('foo.txt', 'foo');
130+
$this->file('_media/foo.txt', 'foo');
131131
$this->assertSame('txt', MediaFile::make('foo.txt')->getExtension());
132132

133-
$this->file('foo.png', 'foo');
133+
$this->file('_media/foo.png', 'foo');
134134
$this->assertSame('png', MediaFile::make('foo.png')->getExtension());
135135
}
136136

137137
public function testToArrayReturnsArrayOfFileProperties()
138138
{
139-
$this->file('foo.txt', 'foo bar');
139+
$this->file('_media/foo.txt', 'foo bar');
140140

141141
$this->assertSame([
142142
'name' => 'foo.txt',
143-
'path' => 'foo.txt',
143+
'path' => '_media/foo.txt',
144144
'length' => 7,
145145
'mimeType' => 'text/plain',
146146
], MediaFile::make('foo.txt')->toArray());
147147
}
148148

149149
public function testToArrayWithEmptyFileWithNoExtension()
150150
{
151-
$this->file('foo', 'foo bar');
151+
$this->file('_media/foo', 'foo bar');
152152

153153
$this->assertSame([
154154
'name' => 'foo',
155-
'path' => 'foo',
155+
'path' => '_media/foo',
156156
'length' => 7,
157157
'mimeType' => 'text/plain',
158158
], MediaFile::make('foo')->toArray());
159159
}
160160

161161
public function testToArrayWithFileInSubdirectory()
162162
{
163-
mkdir(Hyde::path('foo'));
164-
touch(Hyde::path('foo/bar.txt'));
163+
mkdir(Hyde::path('_media/foo'));
164+
touch(Hyde::path('_media/foo/bar.txt'));
165165

166166
$this->assertSame([
167167
'name' => 'bar.txt',
168-
'path' => 'foo/bar.txt',
168+
'path' => '_media/foo/bar.txt',
169169
'length' => 0,
170170
'mimeType' => 'text/plain',
171171
], MediaFile::make('foo/bar.txt')->toArray());
172172

173-
Filesystem::unlink('foo/bar.txt');
174-
rmdir(Hyde::path('foo'));
173+
Filesystem::unlink('_media/foo/bar.txt');
174+
rmdir(Hyde::path('_media/foo'));
175175
}
176176

177177
public function testGetContentLength()
178178
{
179-
$this->file('foo', 'Hello World!');
179+
$this->file('_media/foo', 'Hello World!');
180180
$this->assertSame(12, MediaFile::make('foo')->getContentLength());
181181
}
182182

183183
public function testGetContentLengthWithEmptyFile()
184184
{
185-
$this->file('foo', '');
185+
$this->file('_media/foo', '');
186186
$this->assertSame(0, MediaFile::make('foo')->getContentLength());
187187
}
188188

189189
public function testGetContentLengthWithDirectory()
190190
{
191-
$this->directory('foo');
191+
$this->directory('_media/foo');
192192

193193
$this->expectException(FileNotFoundException::class);
194-
$this->expectExceptionMessage('File [foo] not found.');
194+
$this->expectExceptionMessage('File [_media/foo] not found.');
195195

196196
MediaFile::make('foo')->getContentLength();
197197
}
198198

199199
public function testGetContentLengthWithNonExistentFile()
200200
{
201201
$this->expectException(FileNotFoundException::class);
202-
$this->expectExceptionMessage('File [foo] not found.');
202+
$this->expectExceptionMessage('File [_media/foo] not found.');
203203

204204
MediaFile::make('foo')->getContentLength();
205205
}
206206

207207
public function testGetMimeType()
208208
{
209-
$this->file('foo.txt', 'Hello World!');
209+
$this->file('_media/foo.txt', 'Hello World!');
210210
$this->assertSame('text/plain', MediaFile::make('foo.txt')->getMimeType());
211211
}
212212

213213
public function testGetMimeTypeWithoutExtension()
214214
{
215-
$this->file('foo', 'Hello World!');
215+
$this->file('_media/foo', 'Hello World!');
216216
$this->assertSame('text/plain', MediaFile::make('foo')->getMimeType());
217217
}
218218

219219
public function testGetMimeTypeWithEmptyFile()
220220
{
221-
$this->file('foo', '');
221+
$this->file('_media/foo', '');
222222
$this->assertSame('application/x-empty', MediaFile::make('foo')->getMimeType());
223223
}
224224

225225
public function testGetMimeTypeWithDirectory()
226226
{
227-
$this->directory('foo');
227+
$this->directory('_media/foo');
228228
$this->assertSame('directory', MediaFile::make('foo')->getMimeType());
229229
}
230230

0 commit comments

Comments
 (0)