‪TYPO3CMS  9.5
FileSizeValidatorTest.php
Go to the documentation of this file.
1 <?php
2 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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪FileSizeValidatorTest extends UnitTestCase
28 {
33  {
34  $this->expectException(InvalidValidationOptionsException::class);
35  $this->expectExceptionCode(1505304205);
36 
37  $options = ['minimum' => '0', 'maximum' => '1B'];
38  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
39  ->setMethods(['translateErrorMessage'])
40  ->setConstructorArgs(['options' => $options])
41  ->getMock();
42 
43  ‪$validator->validate(true);
44  }
45 
50  {
51  $this->expectException(InvalidValidationOptionsException::class);
52  $this->expectExceptionCode(1505304206);
53 
54  $options = ['minimum' => '0B', 'maximum' => '1'];
55  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
56  ->setMethods(['translateErrorMessage'])
57  ->setConstructorArgs(['options' => $options])
58  ->getMock();
59 
60  ‪$validator->validate(true);
61  }
62 
67  {
68  $options = ['minimum' => '1M', 'maximum' => '10M'];
69  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
70  ->setMethods(['translateErrorMessage'])
71  ->setConstructorArgs(['options' => $options])
72  ->getMock();
73 
74  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77 
78  $file = new ‪File(['identifier' => '/foo', 'name'=> 'bar.txt', 'size' => '1'], $mockedStorage);
79  $this->assertTrue(‪$validator->validate($file)->hasErrors());
80  }
81 
86  {
87  $options = ['minimum' => '1M', 'maximum' => '1M'];
88  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
89  ->setMethods(['translateErrorMessage'])
90  ->setConstructorArgs(['options' => $options])
91  ->getMock();
92 
93  $mockedStorage = $this->getMockBuilder(ResourceStorage::class)
94  ->disableOriginalConstructor()
95  ->getMock();
96 
97  $file = new ‪File(['identifier' => '/foo', 'name' => 'bar.txt', 'size' => '1048577'], $mockedStorage);
98  $this->assertTrue(‪$validator->validate($file)->hasErrors());
99  }
100 
105  {
106  $options = ['minimum' => '0B', 'maximum' => '1M'];
107  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
108  ->setMethods(['translateErrorMessage'])
109  ->setConstructorArgs(['options' => $options])
110  ->getMock();
111 
112  $this->assertFalse(‪$validator->validate('')->hasErrors());
113  }
114 
119  {
120  $options = ['minimum' => '0B', 'maximum' => '1M'];
121  ‪$validator = $this->getMockBuilder(FileSizeValidator::class)
122  ->setMethods(['translateErrorMessage'])
123  ->setConstructorArgs(['options' => $options])
124  ->getMock();
125 
126  $this->assertTrue(‪$validator->validate('string')->hasErrors());
127  }
128 }
‪TYPO3\CMS\Form\Mvc\Validation\Exception\InvalidValidationOptionsException
Definition: InvalidValidationOptionsException.php:23
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorThrowsExceptionIfMinimumOptionIsInvalid
‪FileSizeValidatorThrowsExceptionIfMinimumOptionIsInvalid()
Definition: FileSizeValidatorTest.php:32
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest
Definition: FileSizeValidatorTest.php:28
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation
Definition: CountValidatorTest.php:2
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasNoErrorsIfInputIsEmptyString
‪FileSizeValidatorHasNoErrorsIfInputIsEmptyString()
Definition: FileSizeValidatorTest.php:104
‪TYPO3\CMS\Form\Mvc\Validation\FileSizeValidator
Definition: FileSizeValidator.php:32
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:74
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrosIfFileResourceSizeIsToSmall
‪FileSizeValidatorHasErrosIfFileResourceSizeIsToSmall()
Definition: FileSizeValidatorTest.php:66
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrosIfFileResourceSizeIsToBig
‪FileSizeValidatorHasErrosIfFileResourceSizeIsToBig()
Definition: FileSizeValidatorTest.php:85
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorThrowsExceptionIfMaximumOptionIsInvalid
‪FileSizeValidatorThrowsExceptionIfMaximumOptionIsInvalid()
Definition: FileSizeValidatorTest.php:49
‪TYPO3\CMS\Form\Tests\Unit\Mvc\Validation\FileSizeValidatorTest\FileSizeValidatorHasErrorsIfInputIsNoFileResource
‪FileSizeValidatorHasErrorsIfInputIsNoFileResource()
Definition: FileSizeValidatorTest.php:118