/** * Test that getSubTypeList() returns a list of mime types. */ public function testGetSubTypeList() { $this->assertEquals(12, count(MimeType::getSubTypeList('archive'))); $this->assertEquals(14, count(MimeType::getSubTypeList('spreadsheet'))); $this->assertEquals(9, count(MimeType::getSubTypeList('document'))); try { MimeType::getSubTypeList('foobar'); $this->assertTrue(false); } catch (Exception $e) { $this->assertTrue(true); } }
/** * Validate the top-level type of file, e.g., image. * * @uses Transit\MimeType * * @param string|array $mimeTypes * @return bool */ public function type($mimeTypes) { $types = array(); foreach ((array) $mimeTypes as $mimeType) { switch ($mimeType) { case 'application': $types += MimeType::getApplicationList(); break; case 'audio': $types += MimeType::getAudioList(); break; case 'image': $types += MimeType::getImageList(); break; case 'text': $types += MimeType::getTextList(); break; case 'video': $types += MimeType::getVideoList(); break; default: $types += MimeType::getSubTypeList($mimeType); break; } } return in_array($this->getFile()->type(), $types); }