These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | class MimeUploadValidatorTest extends SapphireTest |
||
0 ignored issues
–
show
|
|||
3 | { |
||
4 | public function testInvalidFileExtensionValidatingMimeType() |
||
5 | { |
||
6 | // setup plaintext file with invalid extension |
||
7 | $tmpFileName = 'UploadTest-testUpload.jpg'; |
||
8 | $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
||
9 | $tmpFileContent = ''; |
||
10 | for ($i=0; $i<10000; $i++) { |
||
11 | $tmpFileContent .= '0'; |
||
12 | } |
||
13 | file_put_contents($tmpFilePath, $tmpFileContent); |
||
14 | |||
15 | // emulates the $_FILES array |
||
16 | $tmpFile = array( |
||
17 | 'name' => $tmpFileName, |
||
18 | 'size' => filesize($tmpFilePath), |
||
19 | 'tmp_name' => $tmpFilePath, |
||
20 | 'extension' => 'jpg', |
||
21 | 'error' => UPLOAD_ERR_OK, |
||
22 | ); |
||
23 | |||
24 | $u = new Upload(); |
||
25 | $u->setValidator(new MimeUploadValidator()); |
||
26 | $result = $u->load($tmpFile); |
||
27 | $errors = $u->getErrors(); |
||
28 | $this->assertFalse($result, 'Load failed because file extension does not match excepted MIME type'); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
29 | $this->assertEquals('File extension does not match known MIME type', $errors[0]); |
||
0 ignored issues
–
show
The method
assertEquals() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
30 | |||
31 | unlink($tmpFilePath); |
||
32 | } |
||
33 | |||
34 | |||
35 | public function testGetExpectedMimeTypes() |
||
36 | { |
||
37 | // Setup a file with a capitalised extension and try to match it against a lowercase file. |
||
38 | $tmpFileName = 'text.TXT'; |
||
39 | $tmpFilePath = TEMP_FOLDER . '/' . $tmpFileName; |
||
40 | $tmpFileContent = ''; |
||
41 | for ($i=0; $i<10000; $i++) { |
||
42 | $tmpFileContent .= '0'; |
||
43 | } |
||
44 | file_put_contents($tmpFilePath, $tmpFileContent); |
||
45 | |||
46 | $validator = new MimeUploadValidator(); |
||
47 | $tmpFile = array( |
||
48 | 'name' => $tmpFileName, |
||
49 | 'tmp_name' => $tmpFilePath, |
||
50 | ); |
||
51 | $expected = $validator->getExpectedMimeTypes($tmpFile); |
||
52 | $this->assertCount(1, $expected); |
||
0 ignored issues
–
show
The method
assertCount() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
53 | $this->assertContains('text/plain', $expected); |
||
54 | |||
55 | unlink($tmpFilePath); |
||
56 | |||
57 | // Test a physical ico file with capitalised extension |
||
58 | $tmpFile = array( |
||
59 | 'name' => 'favicon.ICO', |
||
60 | 'tmp_name' => 'assets/favicon.ICO', |
||
61 | ); |
||
62 | $expected = $validator->getExpectedMimeTypes($tmpFile); |
||
63 | $this->assertCount(3, $expected); |
||
0 ignored issues
–
show
The method
assertCount() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
64 | } |
||
65 | |||
66 | public function testMimeComparison() |
||
67 | { |
||
68 | $validator = new MimeUploadValidator(); |
||
69 | |||
70 | $this->assertTrue($validator->compareMime('application/xhtml+xml', 'application/xml')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
71 | $this->assertTrue($validator->compareMime('application/vnd.text', 'application/text')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
72 | $this->assertTrue($validator->compareMime('application/vnd.vnd.text', 'application/text')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
73 | $this->assertTrue($validator->compareMime('application/x-text', 'application/text')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
74 | $this->assertTrue($validator->compareMime('application/gzip', 'application/gzip')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
75 | $this->assertTrue($validator->compareMime('application/x-gzip', 'application/gzip')); |
||
0 ignored issues
–
show
The method
assertTrue() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
76 | $this->assertFalse($validator->compareMime('application/png', 'application/json')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
77 | $this->assertFalse($validator->compareMime('text/plain', 'text/json')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<MimeUploadValidatorTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
78 | } |
||
79 | } |
||
80 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.