]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/SugarFields/Fields/Relate/SugarFieldRelateTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / include / SugarFields / Fields / Relate / SugarFieldRelateTest.php
1 <?php 
2 require_once('include/SugarFields/Fields/Relate/SugarFieldRelate.php');
3
4 class SugarFieldRelateTest extends Sugar_PHPUnit_Framework_TestCase
5 {
6         public function setUp()
7     {
8         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
9         }
10
11     public function tearDown()
12     {
13         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
14         unset($GLOBALS['current_user']);
15     }
16     
17         public function testFormatContactNameWithFirstName()
18         {
19         $GLOBALS['current_user']->setPreference('default_locale_name_format','l f');
20         
21             $vardef = array('name' => 'contact_name');
22             $value = 'John Mertic';
23             
24             $sfr = new SugarFieldRelate('relate');
25             
26             $this->assertEquals(
27             $sfr->formatField($value,$vardef),
28             'Mertic John'
29             );
30     }
31     
32     /**
33      * @group bug35265
34      */
35     public function testFormatContactNameWithoutFirstName()
36         {
37         $GLOBALS['current_user']->setPreference('default_locale_name_format','l f');
38         
39             $vardef = array('name' => 'contact_name');
40             $value = 'Mertic';
41             
42             $sfr = new SugarFieldRelate('relate');
43             
44             $this->assertEquals(
45             trim($sfr->formatField($value,$vardef)),
46             'Mertic'
47             );
48     }
49     
50     /**
51      * @group bug35265
52      */
53     public function testFormatContactNameThatIsEmpty()
54         {
55         $GLOBALS['current_user']->setPreference('default_locale_name_format','l f');
56         
57             $vardef = array('name' => 'contact_name');
58             $value = '';
59             
60             $sfr = new SugarFieldRelate('relate');
61             
62             $this->assertEquals(
63             trim($sfr->formatField($value,$vardef)),
64             ''
65             );
66     }
67     
68     public function testFormatOtherField()
69         {
70         $GLOBALS['current_user']->setPreference('default_locale_name_format','l f');
71         
72             $vardef = array('name' => 'account_name');
73             $value = 'John Mertic';
74             
75             $sfr = new SugarFieldRelate('relate');
76             
77             $this->assertEquals(
78             $sfr->formatField($value,$vardef),
79             'John Mertic'
80             );
81     }
82     
83     /**
84      * @group bug38548
85     */
86     public function testGetSearchViewSmarty(){
87         $vardef = array (
88                         'name' => 'assigned_user_id',
89                         'rname' => 'user_name',
90                         'id_name' => 'assigned_user_id',
91                         'vname' => 'LBL_ASSIGNED_TO_ID',
92                         'group'=>'assigned_user_name',
93                         'type' => 'relate',
94                         'table' => 'users',
95                         'module' => 'Users',
96                         'reportable'=>true,
97                         'isnull' => 'false',
98                         'dbType' => 'id',
99                         'audited'=>true,
100                         'comment' => 'User ID assigned to record',
101             'duplicate_merge'=>'disabled'           
102                 );
103                 $displayParams = array();
104                 $sfr = new SugarFieldRelate('relate');
105                 $output = $sfr->getSearchViewSmarty(array(), $vardef, $displayParams, 0);
106                 $this->assertContains('name="{$Array.assigned_user_id', $output, 'Testing that the name property is in the form for thr assigned_user_id field');
107                 
108                 $vardef =  array (
109                                     'name' => 'account_name',
110                                     'rname' => 'name',
111                                     'id_name' => 'account_id',
112                                     'vname' => 'LBL_ACCOUNT_NAME',
113                                     'type' => 'relate',
114                                     'table' => 'accounts',
115                                     'join_name'=>'accounts',
116                                     'isnull' => 'true',
117                                     'module' => 'Accounts',
118                                     'dbType' => 'varchar',
119                                     'link'=>'accounts',
120                                     'len' => '255',
121                                          'source'=>'non-db',
122                                          'unified_search' => true,
123                                          'required' => true,
124                                          'importable' => 'required',
125                                      'required' => true,
126                                   );
127                 $displayParams = array();
128                 $sfr = new SugarFieldRelate('relate');
129                 $output = $sfr->getSearchViewSmarty(array(), $vardef, $displayParams, 0);
130                 $this->assertNotContains('name="{$Array.account_id', $output, 'Testing that the name property for account_id is not in the form.');
131     }
132 }