Add a test for unknow mimetype and use finfo_file in this case. Inspired by At_Libitum. re #72
This commit is contained in:
parent
6717d92a97
commit
b4d3fe6b22
14
data.php
14
data.php
|
@ -64,11 +64,21 @@ class Data extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMimeType () {
|
public function getMimeType () {
|
||||||
|
$result = "application/octet-stream";
|
||||||
if ($this->isKnownType ()) {
|
if ($this->isKnownType ()) {
|
||||||
return self::$mimetypes [$this->extension];
|
return self::$mimetypes [$this->extension];
|
||||||
} else {
|
} elseif (function_exists('finfo_open') === true) {
|
||||||
return "application/octet-stream";
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
|
||||||
|
if (is_resource($finfo) === true)
|
||||||
|
{
|
||||||
|
$result = finfo_file($finfo, $this->getLocalPath ());
|
||||||
|
}
|
||||||
|
|
||||||
|
finfo_close($finfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilename () {
|
public function getFilename () {
|
||||||
|
|
|
@ -291,6 +291,29 @@ class BookTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->assertNull ($book->getDataFormat ("FB2"));
|
$this->assertNull ($book->getDataFormat ("FB2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetMimeType () {
|
||||||
|
$book = Book::getBookById(17);
|
||||||
|
|
||||||
|
// Get Alice MOBI=>17, PDF=>19, EPUB=>20
|
||||||
|
$data = $book->getDataFormat ("EPUB");
|
||||||
|
$this->assertEquals ("application/epub+zip", $data->getMimeType ());
|
||||||
|
$data = $book->getDataFormat ("MOBI");
|
||||||
|
$this->assertEquals ("application/x-mobipocket-ebook", $data->getMimeType ());
|
||||||
|
$data = $book->getDataFormat ("PDF");
|
||||||
|
$this->assertEquals ("application/pdf", $data->getMimeType ());
|
||||||
|
|
||||||
|
// Alter a data to make a test for finfo_file if enabled
|
||||||
|
$data->extension = "ico";
|
||||||
|
$data->format = "ICO";
|
||||||
|
$data->name = "favicon";
|
||||||
|
$data->book->path = realpath (dirname(__FILE__) . "/../");
|
||||||
|
if (function_exists('finfo_open') === true) {
|
||||||
|
$this->assertEquals ("image/x-icon", $data->getMimeType ());
|
||||||
|
} else {
|
||||||
|
$this->assertEquals ("application/octet-stream", $data->getMimeType ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testTypeaheadSearch ()
|
public function testTypeaheadSearch ()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue