]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/ImportDuplicateCheckTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / modules / Import / ImportDuplicateCheckTest.php
1 <?php
2 require_once 'modules/Import/ImportDuplicateCheck.php';
3
4 class ImportDuplicateCheckTest extends Sugar_PHPUnit_Framework_TestCase
5 {
6     public function setUp() 
7     {
8         $beanList = array();
9         $beanFiles = array();
10         require('include/modules.php');
11         $GLOBALS['beanList'] = $beanList;
12         $GLOBALS['beanFiles'] = $beanFiles;
13         $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
14         $app_strings = array();
15         require('include/language/en_us.lang.php');
16         $GLOBALS['app_strings'] = $app_strings;
17     }
18     
19     public function tearDown() 
20     {
21         unset($GLOBALS['beanList']);
22         unset($GLOBALS['beanFiles']);
23         unset($GLOBALS['app_strings']);
24         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
25         unset($GLOBALS['current_user']);
26     }
27     
28     public function testGetDuplicateCheckIndexesWithEmail()
29     {
30         $focus = loadBean('Contacts');
31         
32         $idc     = new ImportDuplicateCheck($focus);
33         $indexes = $idc->getDuplicateCheckIndexes();
34         
35         foreach ( $focus->getIndices() as $key => $index ) {
36             if ($key != 'id') $this->assertTrue(isset($indexes[$index['name']]),"{$index['name']} should be in the list");
37         }
38         
39         $this->assertTrue(isset($indexes['special_idx_email1']));
40         $this->assertTrue(isset($indexes['special_idx_email2']));
41     }
42     
43     public function testGetDuplicateCheckIndexesNoEmail()
44     {
45         $focus = loadBean('Calls');
46         
47         $idc     = new ImportDuplicateCheck($focus);
48         $indexes = $idc->getDuplicateCheckIndexes();
49         
50         foreach ( $focus->getIndices() as $key => $index ) {
51             if ($key != 'id') $this->assertTrue(isset($indexes[$index['name']]));
52         }
53         
54         $this->assertFalse(isset($indexes['special_idx_email1']));
55         $this->assertFalse(isset($indexes['special_idx_email2']));
56     }
57     
58     public function testIsADuplicateRecord()
59     {
60         $last_name = 'FooBar'.date("YmdHis");
61         
62         $focus = loadBean('Contacts');
63         $focus->last_name = $last_name;
64         $id = $focus->save(false);
65         
66         $focus = loadBean('Contacts');
67         $focus->last_name = $last_name;
68         
69         $idc = new ImportDuplicateCheck($focus);
70         
71         $this->assertTrue($idc->isADuplicateRecord(array('idx_contacts_del_last')));
72         
73         $focus->mark_deleted($id);
74     }
75     
76     public function testIsADuplicateRecordEmail()
77     {
78         $email = date("YmdHis").'@foobar.com';
79         
80         $focus = loadBean('Contacts');
81         $focus->email1 = $email;
82         $id = $focus->save(false);
83         
84         $focus = loadBean('Contacts');
85         $focus->email1 = $email;
86         
87         $idc = new ImportDuplicateCheck($focus);
88         
89         $this->assertTrue($idc->isADuplicateRecord(array('special_idx_email1')));
90         
91         $focus->mark_deleted($id);
92     }
93     
94     public function testIsADuplicateRecordNotFound()
95     {
96         $last_name = 'BadFooBar'.date("YmdHis");
97         
98         $focus = loadBean('Contacts');
99         $focus->last_name = $last_name;
100         
101         $idc = new ImportDuplicateCheck($focus);
102         
103         $this->assertFalse($idc->isADuplicateRecord(array('idx_contacts_del_last')));
104     }
105     
106     public function testIsADuplicateRecordEmailNotFound()
107     {
108         $email = date("YmdHis").'@badfoobar.com';
109         
110         $focus = loadBean('Contacts');
111         $focus->email1 = $email;
112         
113         $idc = new ImportDuplicateCheck($focus);
114         
115         $this->assertFalse($idc->isADuplicateRecord(array('special_idx_email1')));
116     }
117 }