]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/DynamicFields/Bug24095Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / DynamicFields / Bug24095Test.php
1 <?php
2 require_once 'PHPUnit/Framework/MockObject/Mock.php';
3 require_once("modules/Accounts/Account.php");
4
5 /**
6  * Test cases for Bug 24095
7  */
8 class Bug24095Test extends Sugar_PHPUnit_Framework_TestCase
9 {
10     private $_tablename;
11     private $_old_installing;
12     
13     public function setUp()
14     {
15         $this->accountMockBean = PHPUnit_Framework_MockObject_Mock::generate('Account' , array('hasCustomFields'));
16         $this->_tablename = 'test' . date("YmdHis");
17         if ( isset($GLOBALS['installing']) )
18             $this->_old_installing = $GLOBALS['installing'];
19         $GLOBALS['installing'] = true;
20         
21         $GLOBALS['db']->createTableParams($this->_tablename . '_cstm',
22             array(
23                 'id_c' => array (
24                     'name' => 'id_c',
25                     'type' => 'id',
26                     ),
27                 'foo_c' => array (
28                     'name' => 'foo_c',
29                     'type' => 'varchar',
30                     'len' => '255',
31                     ),
32                 ),
33             array()
34             );
35         $GLOBALS['db']->query("INSERT INTO {$this->_tablename}_cstm (id_c,foo_c) VALUES ('12345','67890')");
36     }
37     
38     public function tearDown()
39     {
40         $GLOBALS['db']->dropTableName($this->_tablename . '_cstm');
41         if ( isset($this->_old_installing) )
42             $GLOBALS['installing'] = $this->_old_installing;
43     }
44     
45     public function testDynamicFieldsRetrieveWorks()
46     {
47         $bean =new $this->accountMockBean->mockClassName();
48         $bean->custom_fields = new DynamicField($bean->module_dir);
49         $bean->custom_fields->setup($bean);
50         $bean->expects($this->any())
51              ->method('hasCustomFields')
52              ->will($this->returnValue(true));
53         $bean->table_name = $this->_tablename;
54         $bean->id = '12345';
55         $bean->custom_fields->retrieve();
56         $this->assertEquals($bean->id_c, '12345');
57         $this->assertEquals($bean->foo_c, '67890');
58     }
59 }
60
61