|
120 | 120 | $page->assertSee('Empty file: '); |
121 | 121 | }); |
122 | 122 |
|
| 123 | +it('validates multipart pdf upload metadata', function (): void { |
| 124 | + Route::get('favicon.ico', static fn (): string => ''); |
| 125 | + Route::get('/', static fn (): string => " |
| 126 | + <html> |
| 127 | + <head></head> |
| 128 | + <body> |
| 129 | + <form method='post' enctype='multipart/form-data' action='/form'> |
| 130 | + <label for='pdf-file'>PDF file</label> |
| 131 | + <input id='pdf-file' type='file' name='pdf_file'> |
| 132 | +
|
| 133 | + <button type='submit'>Send</button> |
| 134 | + </form> |
| 135 | + </body> |
| 136 | + </html> |
| 137 | + "); |
| 138 | + |
| 139 | + $expectedPdfSize = filesize(fixture('example.pdf')); |
| 140 | + assert($expectedPdfSize !== false); |
| 141 | + |
| 142 | + Route::post('/form', static function (Request $request) use ($expectedPdfSize): string { |
| 143 | + $pdf = $request->file('pdf_file'); |
| 144 | + $name = $pdf?->getClientOriginalName() ?? ''; |
| 145 | + $extension = $pdf?->getClientOriginalExtension() ?? ''; |
| 146 | + $valid = $pdf?->isValid() ? 'yes' : 'no'; |
| 147 | + $size = (string) ($pdf?->getSize() ?? ''); |
| 148 | + |
| 149 | + return " |
| 150 | + <html> |
| 151 | + <head></head> |
| 152 | + <body> |
| 153 | + <p>Name: $name</p> |
| 154 | + <p>Extension: $extension</p> |
| 155 | + <p>Valid: $valid</p> |
| 156 | + <p>Size: $size</p> |
| 157 | + <p>Expected size: $expectedPdfSize</p> |
| 158 | + </body> |
| 159 | + </html> |
| 160 | + "; |
| 161 | + }); |
| 162 | + |
| 163 | + $page = visit('/'); |
| 164 | + |
| 165 | + $page->attach('PDF file', fixture('example.pdf')); |
| 166 | + $page->submit(); |
| 167 | + |
| 168 | + $page->assertSee('Name: example.pdf') |
| 169 | + ->assertSee('Extension: pdf') |
| 170 | + ->assertSee('Valid: yes') |
| 171 | + ->assertSee('Expected size: '.$expectedPdfSize) |
| 172 | + ->assertSee('Size: '.$expectedPdfSize); |
| 173 | +}); |
| 174 | + |
123 | 175 | it('parse a multipart body with nested fields', function (): void { |
124 | 176 | Route::get('/', static fn (): string => " |
125 | 177 | <html> |
|
0 commit comments