‪TYPO3CMS  10.4
FileSizeValidatorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FileSizeValidatorTest extends UnitTestCase
30 {
35  {
36  $this->expectException(InvalidValidationOptionsException::class);
37  $this->expectExceptionCode(1505304205);
38 
39  $options = ['minimum' => '0', 'maximum' => '1B'];
40  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
41  ->setMethods(['translateErrorMessage'])
42  ->setConstructorArgs(['options' => $options])
43  ->getMock();
44 
45  ‪$validator->validate(true);
46  }
47 
52  {
53  $this->expectException(InvalidValidationOptionsException::class);
54  $this->expectExceptionCode(1505304206);
55 
56  $options = ['minimum' => '0B', 'maximum' => '1'];
57  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
58  ->setMethods(['translateErrorMessage'])
59  ->setConstructorArgs(['options' => $options])
60  ->getMock();
61 
62  ‪$validator->validate(true);
63  }
64 
69  {
70  $options = ['minimum' => '1M', 'maximum' => '10M'];
71  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
72  ->setMethods(['translateErrorMessage'])
73  ->setConstructorArgs(['options' => $options])
74  ->getMock();
75 
76  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $file = new ‪File(['identifier' => '/foo', 'name'=> 'bar.txt', 'size' => '1'], $mockedStorage);
81  self::assertTrue(‪$validator->validate($file)->hasErrors());
82  }
83 
88  {
89  $options = ['minimum' => '1M', 'maximum' => '1M'];
90  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
91  ->setMethods(['translateErrorMessage'])
92  ->setConstructorArgs(['options' => $options])
93  ->getMock();
94 
95  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
96  ->disableOriginalConstructor()
97  ->getMock();
98 
99  $file = new ‪File(['identifier' => '/foo', 'name' => 'bar.txt', 'size' => '1048577'], $mockedStorage);
100  self::assertTrue(‪$validator->validate($file)->hasErrors());
101  }
102 
107  {
108  $options = ['minimum' => '0B', 'maximum' => '1M'];
109  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
110  ->setMethods(['translateErrorMessage'])
111  ->setConstructorArgs(['options' => $options])
112  ->getMock();
113 
114  self::assertFalse(‪$validator->validate('')->hasErrors());
115  }
116 
121  {
122  $options = ['minimum' => '0B', 'maximum' => '1M'];
123  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
124  ->setMethods(['translateErrorMessage'])
125  ->setConstructorArgs(['options' => $options])
126  ->getMock();
127 
128  self::assertTrue(‪$validator->validate('string')->hasErrors());
129  }
130 }
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrorsIfFileResourceSizeIsToSmall
‪FileSizeValidatorHasErrorsIfFileResourceSizeIsToSmall()
Definition: FileSizeValidatorTest.php:68
‪TYPO3\CMS\Form\Mvc\Validation\Exception\InvalidValidationOptionsException
Definition: InvalidValidationOptionsException.php:23
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorThrowsExceptionIfMinimumOptionIsInvalid
‪FileSizeValidatorThrowsExceptionIfMinimumOptionIsInvalid()
Definition: FileSizeValidatorTest.php:34
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest
Definition: FileSizeValidatorTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation
Definition: CountValidatorTest.php:16
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasNoErrorsIfInputIsEmptyString
‪FileSizeValidatorHasNoErrorsIfInputIsEmptyString()
Definition: FileSizeValidatorTest.php:106
‪TYPO3\CMS\Form\Mvc\Validation\FileSizeValidator
Definition: FileSizeValidator.php:34
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrorsIfFileResourceSizeIsToBig
‪FileSizeValidatorHasErrorsIfFileResourceSizeIsToBig()
Definition: FileSizeValidatorTest.php:87
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:122
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorThrowsExceptionIfMaximumOptionIsInvalid
‪FileSizeValidatorThrowsExceptionIfMaximumOptionIsInvalid()
Definition: FileSizeValidatorTest.php:51
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrorsIfInputIsNoFileResource
‪FileSizeValidatorHasErrorsIfInputIsNoFileResource()
Definition: FileSizeValidatorTest.php:120