TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
MimeTypeValidatorTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Mvc\Validation;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
27 {
28 
33  {
34  $this->expectException(InvalidValidationOptionsException::class);
35  $this->expectExceptionCode(1471713296);
36 
37  $options = ['allowedMimeTypes' => ''];
38  $validator = $this->getMockBuilder(MimeTypeValidator::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(1471713296);
53 
54  $options = ['allowedMimeTypes' => []];
55  $validator = $this->getMockBuilder(MimeTypeValidator::class)
56  ->setMethods(['translateErrorMessage'])
57  ->setConstructorArgs(['options' => $options])
58  ->getMock();
59 
60  $validator->validate(true);
61  }
62 
67  {
68  $options = ['allowedMimeTypes' => ['image/jpeg']];
69  $validator = $this->getMockBuilder(MimeTypeValidator::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', 'mime_type' => 'image/png'], $mockedStorage);
79  $this->assertTrue($validator->validate($file)->hasErrors());
80  }
81 
86  {
87  $options = ['allowedMimeTypes' => ['fake']];
88  $validator = $this->getMockBuilder(MimeTypeValidator::class)
89  ->setMethods(['translateErrorMessage'])
90  ->setConstructorArgs(['options' => $options])
91  ->getMock();
92 
93  $this->assertFalse($validator->validate('')->hasErrors());
94  }
95 
100  {
101  $options = ['allowedMimeTypes' => ['fake']];
102  $validator = $this->getMockBuilder(MimeTypeValidator::class)
103  ->setMethods(['translateErrorMessage'])
104  ->setConstructorArgs(['options' => $options])
105  ->getMock();
106 
107  $this->assertTrue($validator->validate('string')->hasErrors());
108  }
109 }