3 require_once 'CiviTest/CiviUnitTestCase.php';
4 require_once 'CRM/Utils/DeprecatedUtils.php';
7 * Class CRM_Utils_DeprecatedUtilsTest
9 class CRM_Utils_DeprecatedUtilsTest
extends CiviUnitTestCase
{
16 'name' => 'Deprecated Utils Test',
17 'description' => 'Test functions that were copied from api v2 to support BAO code',
18 'group' => 'CiviCRM BAO Tests',
26 // truncate a few tables
27 $tablesToTruncate = array(
30 'civicrm_contribution',
34 $this->quickCleanup($tablesToTruncate);
37 * Test civicrm_contact_check_params with no contact type
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__
);
47 * Test civicrm_contact_check_params with a duplicate
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'
57 $op->execute($this->_dbconn
,
58 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
59 dirname(__FILE__
) . '/../../api/v3/dataset/email_contact_17.xml'
64 'first_name' => 'Test',
65 'last_name' => 'Contact',
66 'email' => 'TestContact@example.com',
67 'contact_type' => 'Individual',
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)
78 * Test civicrm_contact_check_params with a duplicate
79 * and request the error in array format
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'
89 $op->execute($this->_dbconn
,
90 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
91 dirname(__FILE__
) . '/../../api/v3/dataset/email_contact_17.xml'
96 'first_name' => 'Test',
97 'last_name' => 'Contact',
98 'email' => 'TestContact@example.com',
99 'contact_type' => 'Individual',
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']
108 * Test civicrm_contact_check_params with check for required
109 * params and no params
111 function testCheckParamsWithNoParams() {
113 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
114 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__
);