Skip to content

Commit

Permalink
Use standard Nette error message for failed uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurk committed Jan 20, 2024
1 parent 7c23449 commit 053cfa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/FileUploadControl/FileUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function loadHttpData(): void
}
}
if ($uploadFailed) {
$this->addError('Upload error');
$this->addError(Nette\Forms\Validator::$messages[Nette\Forms\Controls\UploadControl::Valid]);
}
}

Expand Down Expand Up @@ -272,7 +272,7 @@ public function handleUpload(string $namespace): void
}

if ($fileUploadChunk instanceof FailedUpload) {
$responses[] = $this->createUploadErrorResponse($fileUploadChunk, $this->translate('Upload error'));
$responses[] = $this->createUploadErrorResponse($fileUploadChunk, $this->translate(Nette\Forms\Validator::$messages[Nette\Forms\Controls\UploadControl::Valid]));
continue;
}

Expand All @@ -296,7 +296,7 @@ public function handleUpload(string $namespace): void
$fileUploadItem = $this->getStorage()->save($fileUploadChunk);
$responses[] = $this->createUploadSuccessResponse($fileUploadItem);
} catch (StorageDoesNotExistException | UnableToSaveFileUploadException $exception) {
$responses[] = $this->createUploadErrorResponse($fileUploadChunk, $this->translate('Upload error'));
$responses[] = $this->createUploadErrorResponse($fileUploadChunk, $this->translate(Nette\Forms\Validator::$messages[Nette\Forms\Controls\UploadControl::Valid]));
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/FileUploadControl/FileUploadControlValidationTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use NepadaTests\FileUploadControl\Fixtures\TestPresenter;
use NepadaTests\FileUploadControl\Storage\InMemoryStorage;
use NepadaTests\FileUploadControl\Storage\InMemoryStorageManager;
use NepadaTests\TestCase;
use Nette;
use Nette\Application;
use Nette\Application\Responses\JsonResponse;
use Nette\Application\UI\Form;
Expand All @@ -32,6 +33,11 @@ require_once __DIR__ . '/../bootstrap.php';
class FileUploadControlValidationTest extends TestCase
{

protected function setUp(): void
{
Nette\Forms\Validator::$messages[Nette\Forms\Controls\UploadControl::Valid] = 'Upload error';
}

public function testSubmittedWithFailedUpload(): void
{
$storage = InMemoryStorage::createWithFiles();
Expand Down

0 comments on commit 053cfa9

Please sign in to comment.