WebformElementManagedFileLimitTest.php in Webform 8.5
File
tests/src/Functional/Element/WebformElementManagedFileLimitTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
class WebformElementManagedFileLimitTest extends WebformElementManagedFileTestBase {
public static $modules = [
'file',
'webform',
];
protected static $testWebforms = [
'test_element_managed_file_limit',
];
public function testLimits() {
$this
->drupalLogin($this->rootUser);
$files = $this
->getTestFiles('text', '1024');
$file = reset($files);
$bytes = filesize($file->uri);
$this
->debug($bytes);
$webform = Webform::load('test_element_managed_file_limit');
$this
->drupalGet('/webform/test_element_managed_file_limit');
$this
->assertRaw('1 MB limit per form.');
$webform
->setSetting('form_file_limit', '')
->save();
$this
->drupalGet('/webform/test_element_managed_file_limit');
$this
->assertNoRaw('1 MB limit per form.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_form_file_limit', '2 MB')
->save();
$this
->drupalGet('/webform/test_element_managed_file_limit');
$this
->assertRaw('2 MB limit per form.');
\Drupal::configFactory()
->getEditable('webform.settings')
->set('settings.default_form_file_limit', $bytes * 2 . ' bytes')
->save();
$this
->drupalGet('/webform/test_element_managed_file_limit');
$this
->assertRaw(format_size($bytes * 2) . ' limit per form.');
$edit = [
'files[managed_file_01]' => \Drupal::service('file_system')
->realpath($file->uri),
];
$sid = $this
->postSubmission($webform, $edit);
$this
->assertNotNull($sid);
$edit = [
'files[managed_file_01]' => \Drupal::service('file_system')
->realpath($file->uri),
'files[managed_file_02]' => \Drupal::service('file_system')
->realpath($file->uri),
'files[managed_file_03]' => \Drupal::service('file_system')
->realpath($file->uri),
];
$this
->postSubmission($webform, $edit);
$this
->assertRaw('This form\'s file upload quota of <em class="placeholder">2 KB</em> has been exceeded. Please remove some files.');
$edit = [
'files[managed_file_01]' => \Drupal::service('file_system')
->realpath($file->uri),
'files[custom_composite_managed_files_items_0_managed_file]' => \Drupal::service('file_system')
->realpath($file->uri),
'files[custom_composite_managed_files_items_1_managed_file]' => \Drupal::service('file_system')
->realpath($file->uri),
];
$this
->drupalPostForm('/webform/test_element_managed_file_limit', [], 'Add');
$this
->drupalPostForm(NULL, $edit, 'Submit');
$this
->assertRaw('This form\'s file upload quota of <em class="placeholder">2 KB</em> has been exceeded. Please remove some files.');
}
}