Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Feb 25, 2022
1 parent 826e282 commit 5b9a90e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -23,7 +23,6 @@
"php": "^7.4 || ^8.0",
"codeigniter4/authentication-implementation": "^1.0",
"enyo/dropzone": "^6.0",
"tatter/alerts": "^2.0",
"tatter/exports": "^3.0",
"tatter/frontend": "^1.0",
"tatter/permits": "^3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Models/FileModel.php
Expand Up @@ -93,7 +93,6 @@ public function createFromFile(CIFile $file, array $data = []): File
// Gather file info
$row = [
'filename' => $file->getFilename(),
'localname' => $file->getRandomName(),
'clientname' => $file->getFilename(),
'type' => Mimes::guessTypeFromExtension($file->getExtension()) ?? $file->getMimeType(),
'size' => $file->getSize(),
Expand All @@ -109,9 +108,10 @@ public function createFromFile(CIFile $file, array $data = []): File
// Determine if we need to move the file
if (strpos($filePath, $storage) === false) {
// Move the file
$file = $file->move($storage, $row['localname']);
$file = $file->move($storage, $file->getRandomName());
chmod((string) $file, 0664);
}
$row['localname'] = $file->getFilename();

// Record it in the database
$fileId = $this->insert($row);
Expand All @@ -133,7 +133,7 @@ public function createFromFile(CIFile $file, array $data = []): File

try {
$result = service('thumbnails')->create($entity->getPath());
rename($result, $output);
copy($result, $output);

// If it succeeds then update the database
$entity->thumbnail = $thumbnail;
Expand Down
5 changes: 1 addition & 4 deletions tests/_support/TestCase.php
Expand Up @@ -30,10 +30,7 @@ abstract class TestCase extends CIUnitTestCase
*/
protected string $testPath;

/**
* @var FileModel
*/
protected $model;
protected FileModel $model;

public static function setUpBeforeClass(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/feature/DisplayTest.php
Expand Up @@ -16,7 +16,7 @@ public function testNoFiles()
$result = $this->get('files');

$result->assertStatus(200);
$result->assertSee('You have no files');
$result->assertSee('No files to display');
}

public function testDefaultDisplaysCards()
Expand Down
4 changes: 2 additions & 2 deletions tests/feature/PermissionsTest.php
Expand Up @@ -65,7 +65,7 @@ public function testDenyListRedirects()
$result = $this->get('files');

$result->assertStatus(302);
$result->assertSessionHas('error', lang('Permits.notPermitted'));
$result->assertSessionHas('error', lang('Files.notPermitted'));
}

public function testDenyAjaxReturnsError()
Expand All @@ -76,7 +76,7 @@ public function testDenyAjaxReturnsError()
$result = $this->withHeaders(['X-Requested-With' => 'XMLHttpRequest'])->get('files');

$result->assertStatus(403);
$result->assertJSONFragment(['error' => lang('Permits.notPermitted')]);
$result->assertJSONFragment(['error' => lang('Files.notPermitted')]);
}

public function testUploadMissingFile()
Expand Down

0 comments on commit 5b9a90e

Please sign in to comment.