TYPO3 CMS  TYPO3_7-6
ServerRequestFactoryTest.php
Go to the documentation of this file.
1 <?php
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 
20 
25 {
29  protected function setUp()
30  {
32  }
33 
38  {
39  $_SERVER['HTTP_HOST'] = 'localhost';
40  $_SERVER['REQUEST_URI'] = '/index.php';
41  $_FILES = [
42  'tx_uploadexample_piexample' => [
43  'name' => [
44  'newExample' => [
45  'image' => 'o51pb.jpg',
46  'imageCollection' => [
47  0 => 'composer.json',
48  ],
49  ],
50  ],
51  'type' => [
52  'newExample' => [
53  'image' => 'image/jpeg',
54  'imageCollection' => [
55  0 => 'application/json'
56  ]
57  ]
58  ],
59  'tmp_name' => [
60  'newExample' => [
61  'image' => '/Applications/MAMP/tmp/php/phphXdbcd',
62  'imageCollection' => [
63  0 => '/Applications/MAMP/tmp/php/phpgrZ4bb'
64  ]
65  ]
66  ],
67  'error' => [
68  'newExample' => [
69  'image' => 0,
70  'imageCollection' => [
71  0 => 0
72  ]
73  ]
74  ],
75  'size' => [
76  'newExample' => [
77  'image' => 59065,
78  'imageCollection' => [
79  0 => 683
80  ]
81  ]
82  ]
83  ]
84  ];
85 
86  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
87 
88  $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['image']);
89  $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['image'] instanceof UploadedFile);
90  $this->assertNotEmpty($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0]);
91  $this->assertTrue($uploadedFiles['tx_uploadexample_piexample']['newExample']['imageCollection'][0] instanceof UploadedFile);
92  }
93 
98  {
99  $_SERVER['HTTP_HOST'] = 'localhost';
100  $_SERVER['REQUEST_URI'] = '/index.php';
101  $_FILES = [];
102 
103  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
104 
105  $this->assertEmpty($uploadedFiles);
106  }
107 
112  {
113  $_SERVER['HTTP_HOST'] = 'localhost';
114  $_SERVER['REQUEST_URI'] = '/index.php';
115  $_FILES = [
116  'tx_uploadexample_piexample' => [
117  'name' => '',
118  'tmp_name' => '',
119  'error' => 4,
120  'size' => 0,
121  ],
122  ];
123 
124  $uploadedFiles = ServerRequestFactory::fromGlobals()->getUploadedFiles();
125 
126  $this->assertEmpty($uploadedFiles);
127  }
128 }