]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Bug43652.php
Release 6.2.0RC1
[Github/sugarcrm.git] / tests / include / Bug43652.php
1 <?php
2
3 require_once('include/externalAPI/Google/ExtAPIGoogle.php');
4
5
6 /**
7  * @ticket 43652
8  */
9 class Bug43652Test extends Sugar_PHPUnit_Framework_TestCase
10 {
11     private $fileData1;
12     private $extAPI;
13
14     public function setUp()
15     {
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");
20     }
21
22     public function tearDown()
23         {
24         unlink($this->fileData1);
25         }
26
27     function _fileMimeProvider()
28     {
29         return array(
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'),
34         );
35     }
36
37     /**
38      * Test the getMime function for the use case where the mime type is already provided.
39      *
40      * @dataProvider _fileMimeProvider
41      */
42     public function testUploadFileWithMimeType($file_info, $expectedMime)
43     {
44         $uf = new UploadFile('');
45         $mime = $uf->getMime($file_info);
46
47         $this->assertEquals($expectedMime, $mime);
48     }
49
50     /**
51      * Test file with no extension but with provided mime-type
52      *
53      * @return void
54      */
55     public function testUploadFileWithEmptyFileExtension()
56     {
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);
62     }
63
64
65     /**
66      * Test file with no extension and no provided mime-type
67      *
68      * @return void
69      */
70     public function testUploadFileWithEmptyFileExtenEmptyMime()
71     {
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);
77     }
78 }