Commit 7d995bb1 authored by catch's avatar catch

Issue #3070072 by mikelutz: Fix use of deprecated file_upload_max_size() in...

Issue #3070072 by mikelutz: Fix use of deprecated file_upload_max_size() in _file_save_upload_single() of file.module
parent d68cb076
......@@ -5,6 +5,7 @@
* Defines a "managed_file" Form API field and a "file" field for Field module.
*/
use Drupal\Component\Utility\Environment;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\File\Exception\FileException;
......@@ -962,7 +963,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
switch ($file_info->getError()) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
\Drupal::messenger()->addError(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_info->getFilename(), '%maxsize' => format_size(file_upload_max_size())]));
\Drupal::messenger()->addError(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_info->getFilename(), '%maxsize' => format_size(Environment::getUploadMaxSize())]));
return FALSE;
case UPLOAD_ERR_PARTIAL:
......
<?php
namespace Drupal\Tests\file\Kernel;
use Drupal\Component\Utility\Environment;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Tests file.module methods.
*
* @group file
*/
class FileModuleTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['file'];
/**
* Tests file size upload errors.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testFileSaveUploadSingleErrorFormSize() {
$file_name = $this->randomMachineName();
$file_info = $this->createMock(UploadedFile::class);
$file_info->expects($this->once())->method('getError')->willReturn(UPLOAD_ERR_FORM_SIZE);
$file_info->expects($this->once())->method('getFileName')->willReturn($file_name);
$this->assertFalse(\_file_save_upload_single($file_info, 'name'));
$expected_message = new TranslatableMarkup('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_name, '%maxsize' => format_size(Environment::getUploadMaxSize())]);
$this->assertEquals($expected_message, \Drupal::messenger()->all()['error'][0]);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment