public function test_it_returns_a_415_for_type_mismatch() { $e = (new SampleExceptionHandler())->render(FileNotSupportedException::strictTypeMismatch('text/foo', 'bar')); $this->assertHttpException($e, 415); }
/** * Determine the aggregate type of the file based on the MIME type and the extension. * @param string $mime_type * @param string $extension * @return string * @throws \Plank\Mediable\Exceptions\MediaUpload\FileNotSupportedException If the file type is not recognized * @throws \Plank\Mediable\Exceptions\MediaUpload\FileNotSupportedException If the file type is restricted * @throws \Plank\Mediable\Exceptions\MediaUpload\FileNotSupportedException If the aggregate type is restricted */ public function inferAggregateType($mime_type, $extension) { $allowed_types = $this->config['allowed_aggregate_types']; $types_for_mime = $this->possibleAggregateTypesForMimeType($mime_type); $types_for_extension = $this->possibleAggregateTypesForExtension($extension); if (count($allowed_types)) { $intersection = array_intersect($types_for_mime, $types_for_extension, $allowed_types); } else { $intersection = array_intersect($types_for_mime, $types_for_extension); } if (count($intersection)) { $type = $intersection[0]; } elseif (empty($types_for_mime) && empty($types_for_extension)) { if (!$this->config['allow_unrecognized_types']) { throw FileNotSupportedException::unrecognizedFileType($mime_type, $extension); } $type = Media::TYPE_OTHER; } else { if ($this->config['strict_type_checking']) { throw FileNotSupportedException::strictTypeMismatch($mime_type, $extension); } $merged = array_merge($types_for_mime, $types_for_extension); $type = reset($merged); } if (count($allowed_types) && !in_array($type, $allowed_types)) { throw FileNotSupportedException::aggregateTypeRestricted($type, $allowed_types); } return $type; }