Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | require_once 'CRM/Utils/DeprecatedUtils.php'; | |
5 | ||
aba1cd8b EM |
6 | /** |
7 | * Class CRM_Utils_DeprecatedUtilsTest | |
8 | */ | |
6a488035 TO |
9 | class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase { |
10 | ||
aba1cd8b EM |
11 | /** |
12 | * @return array | |
13 | */ | |
6a488035 TO |
14 | function get_info() { |
15 | return array( | |
16 | 'name' => 'Deprecated Utils Test', | |
17 | 'description' => 'Test functions that were copied from api v2 to support BAO code', | |
18 | 'group' => 'CiviCRM BAO Tests', | |
19 | ); | |
20 | } | |
21 | ||
22 | function setUp() { | |
23 | parent::setUp(); | |
24 | } | |
25 | function tearDown() { | |
26 | // truncate a few tables | |
27 | $tablesToTruncate = array( | |
28 | 'civicrm_contact', | |
29 | 'civicrm_email', | |
30 | 'civicrm_contribution', | |
31 | 'civicrm_website', | |
32 | ); | |
33 | ||
34 | $this->quickCleanup($tablesToTruncate); | |
6a488035 TO |
35 | } |
36 | /** | |
37 | * Test civicrm_contact_check_params with no contact type | |
38 | */ | |
39 | function testCheckParamsWithNoContactType() { | |
40 | $params = array('foo' => 'bar'); | |
41 | $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); | |
42 | $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__); | |
43 | } | |
44 | ||
45 | ||
46 | /** | |
47 | * Test civicrm_contact_check_params with a duplicate | |
48 | */ | |
49 | function testCheckParamsWithDuplicateContact() { | |
50 | // Insert a row in civicrm_contact creating individual contact | |
51 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
52 | $op->execute($this->_dbconn, | |
53 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
54 | dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml' | |
55 | ) | |
56 | ); | |
57 | $op->execute($this->_dbconn, | |
58 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
59 | dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml' | |
60 | ) | |
61 | ); | |
62 | ||
63 | $params = array( | |
64 | 'first_name' => 'Test', | |
65 | 'last_name' => 'Contact', | |
66 | 'email' => 'TestContact@example.com', | |
67 | 'contact_type' => 'Individual', | |
68 | ); | |
69 | $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE); | |
70 | $this->assertEquals(1, $contact['is_error']); | |
71 | $this->assertRegexp("/matching contacts.*17/s", | |
72 | CRM_Utils_Array::value('error_message', $contact) | |
73 | ); | |
74 | } | |
75 | ||
76 | ||
77 | /** | |
78 | * Test civicrm_contact_check_params with a duplicate | |
79 | * and request the error in array format | |
80 | */ | |
81 | function testCheckParamsWithDuplicateContact2() { | |
82 | // Insert a row in civicrm_contact creating individual contact | |
83 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
84 | $op->execute($this->_dbconn, | |
85 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
86 | dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml' | |
87 | ) | |
88 | ); | |
89 | $op->execute($this->_dbconn, | |
90 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
91 | dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml' | |
92 | ) | |
93 | ); | |
94 | ||
95 | $params = array( | |
96 | 'first_name' => 'Test', | |
97 | 'last_name' => 'Contact', | |
98 | 'email' => 'TestContact@example.com', | |
99 | 'contact_type' => 'Individual', | |
100 | ); | |
101 | $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE, TRUE); | |
102 | $this->assertEquals(1, $contact['is_error']); | |
103 | $this->assertRegexp("/matching contacts.*17/s", | |
104 | $contact['error_message']['message'] | |
105 | ); | |
106 | } | |
107 | /** | |
108 | * Test civicrm_contact_check_params with check for required | |
109 | * params and no params | |
110 | */ | |
111 | function testCheckParamsWithNoParams() { | |
112 | $params = array(); | |
113 | $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); | |
114 | $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__); | |
115 | } | |
116 | ||
117 | } |