3 require_once('include/externalAPI/Google/ExtAPIGoogle.php');
9 class Bug43652Test extends Sugar_PHPUnit_Framework_TestCase
14 public function setUp()
16 //Just need base class but its abstract so we use the google implementation for this test.
17 $this->extAPI = new ExtAPIGoogle();
18 $this->fileData1 = $GLOBALS['sugar_config']['upload_dir'] . DIRECTORY_SEPARATOR . 'unittest';
19 file_put_contents($this->fileData1, "Unit test for mime type");
22 public function tearDown()
24 unlink($this->fileData1);
27 function _fileMimeProvider()
30 array( array('name' => 'te.st.png','type' => 'img/png'),'img/png'),
31 array( array('name' => 'test.jpg','type' => 'img/jpeg'),'img/jpeg'),
32 array( array('name' => 'test.out','type' => 'application/octet-stream'),'application/octet-stream'),
33 array( array('name' => 'test_again','type' => 'img/png'),'img/png'),
38 * Test the getMime function for the use case where the mime type is already provided.
40 * @dataProvider _fileMimeProvider
42 public function testUploadFileWithMimeType($file_info, $expectedMime)
44 $uf = new UploadFile('');
45 $mime = $uf->getMime($file_info);
47 $this->assertEquals($expectedMime, $mime);
51 * Test file with no extension but with provided mime-type
55 public function testUploadFileWithEmptyFileExtension()
57 $file_info = array('name' => 'test', 'type' => 'application/octet-stream', 'tmp_name' => $this->fileData1);
58 $expectedMime = $this->extAPI->isMimeDetectionAvailable() ? 'text/plain' : 'application/octet-stream';
59 $uf = new UploadFile('');
60 $mime = $uf->getMime($file_info);
61 $this->assertEquals($expectedMime, $mime);
66 * Test file with no extension and no provided mime-type
70 public function testUploadFileWithEmptyFileExtenEmptyMime()
72 $file_info = array('name' => 'test','tmp_name' => $this->fileData1);
73 $expectedMime = $this->extAPI->isMimeDetectionAvailable() ? 'text/plain' : 'application/octet-stream';
74 $uf = new UploadFile('');
75 $mime = $uf->getMime($file_info);
76 $this->assertEquals($expectedMime, $mime);