Skip to content

Commit d50acad

Browse files
committed
fix file not found
1 parent 2e33796 commit d50acad

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/Entities/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected static function locateDefaultThumbnail(): string
4141
}
4242
}
4343

44-
return self::$defaultThumbnail;
44+
return (string) self::$defaultThumbnail;
4545
}
4646

4747
//--------------------------------------------------------------------

src/Views/Formats/cards.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="card-deck">
55
<?php foreach ($files as $file): ?>
66
<div class="card mb-4" style="min-width: 10rem; max-width: 200px;">
7-
<img src="<?= img_data($file->thumbnail) ?>" class="card-img-top img-thumbnail" alt="<?= $file->filename ?>">
7+
<img src="<?= img_data($file->getThumbnail()) ?>" class="card-img-top img-thumbnail" alt="<?= $file->filename ?>">
88
<div class="card-header">
99
<?= view('Tatter\Files\Views\Menus\single', ['file' => $file, 'access' => $access]) ?>
1010
</div>

src/Views/Formats/list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<tbody>
1616
<?php foreach ($files as $file): ?>
1717
<tr>
18-
<td><img src="<?= img_data($file->thumbnail) ?>" class="img-fluid rounded" alt="<?= $file->filename ?>" style="max-height:40px;"></td>
18+
<td><img src="<?= img_data($file->getThumbnail()) ?>" class="img-fluid rounded" alt="<?= $file->filename ?>" style="max-height:40px;"></td>
1919
<td class="align-middle"><?= $file->filename ?></td>
2020
<td class="align-middle"><?= $file->type ?></td>
2121
<td class="align-middle"><?= bytes2human($file->size) ?></td>

tests/unit/ControllerTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use CodeIgniter\Config\Config;
44
use CodeIgniter\Files\Exceptions\FileNotFoundException;
55
use Tatter\Files\Controllers\Files;
6+
use Tatter\Files\Entities\File;
67
use Tatter\Files\Exceptions\FilesException;
78
use Tests\Support\Fakers\FileFaker;
89
use Tests\Support\FilesTestCase;
@@ -180,7 +181,7 @@ public function testGetFormatIgnoresInvalid()
180181
$this->assertEquals('cards', $result);
181182
}
182183

183-
public function testDataUsesVar()
184+
public function testDataUsesVarWithFaker()
184185
{
185186
$file = fake(FileFaker::class);
186187

@@ -198,24 +199,33 @@ public function testDataUsesVar()
198199
$this->assertStringContainsString($file->filename, $result);
199200
}
200201

201-
public function testDataUsesVarGotFileNotFound()
202+
public function testDataUsesVarViaPassEntity()
202203
{
203-
$file = fake(FileFaker::class);
204-
205204
$controller = new Files();
206205
$controller->initController(service('request'), service('response'), service('logger'));
207206

207+
$file = new File;
208+
$file->filename ='foo.txt';
209+
$file->thumbnail = '';
210+
$file->type = '';
211+
$file->localname = '';
212+
$file->clientname = '';
213+
$file->size = 1;
214+
$file->created_at = new class {
215+
public function humanize()
216+
{
217+
return '';
218+
}
219+
};
220+
208221
$method = $this->getPrivateMethodInvoker($controller, 'setData');
209222
$method([
210223
'files' => [
211-
0 => (object) [
212-
'filename' => 'foo.txt',
213-
'thumbnail' => '',
214-
]
224+
0 => $file
215225
],
216226
]);
217227

218-
$this->expectException(FileNotFoundException::class);
219-
$controller->display();
228+
$result = $controller->display();
229+
$this->assertStringContainsString($file->filename, $result);
220230
}
221231
}

0 commit comments

Comments
 (0)