3 require_once 'CRM/Utils/DeprecatedUtils.php';
6 * Class CRM_Utils_DeprecatedUtilsTest
8 class CRM_Utils_DeprecatedUtilsTest
extends CiviUnitTestCase
{
10 public function setUp() {
14 public function tearDown() {
15 // truncate a few tables
16 $tablesToTruncate = array(
19 'civicrm_contribution',
23 $this->quickCleanup($tablesToTruncate);
27 * Test civicrm_contact_check_params with no contact type.
29 public function testCheckParamsWithNoContactType() {
30 $params = array('foo' => 'bar');
31 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
32 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__
);
37 * Test civicrm_contact_check_params with a duplicate.
39 public function testCheckParamsWithDuplicateContact() {
40 // Insert a row in civicrm_contact creating individual contact
41 $op = new PHPUnit_Extensions_Database_Operation_Insert();
42 $op->execute($this->_dbconn
,
43 $this->createXMLDataSet(
44 dirname(__FILE__
) . '/../../api/v3/dataset/contact_17.xml'
47 $op->execute($this->_dbconn
,
48 $this->createXMLDataSet(
49 dirname(__FILE__
) . '/../../api/v3/dataset/email_contact_17.xml'
54 'first_name' => 'Test',
55 'last_name' => 'Contact',
56 'email' => 'TestContact@example.com',
57 'contact_type' => 'Individual',
59 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE);
60 $this->assertEquals(1, $contact['is_error']);
61 $this->assertRegexp("/matching contacts.*17/s",
62 CRM_Utils_Array
::value('error_message', $contact)
68 * Test civicrm_contact_check_params with a duplicate.
69 * and request the error in array format
71 public function testCheckParamsWithDuplicateContact2() {
72 // Insert a row in civicrm_contact creating individual contact
73 $op = new PHPUnit_Extensions_Database_Operation_Insert();
74 $op->execute($this->_dbconn
,
75 $this->createXMLDataSet(
76 dirname(__FILE__
) . '/../../api/v3/dataset/contact_17.xml'
79 $op->execute($this->_dbconn
,
80 $this->createXMLDataSet(
81 dirname(__FILE__
) . '/../../api/v3/dataset/email_contact_17.xml'
86 'first_name' => 'Test',
87 'last_name' => 'Contact',
88 'email' => 'TestContact@example.com',
89 'contact_type' => 'Individual',
91 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE, TRUE);
92 $this->assertEquals(1, $contact['is_error']);
93 $this->assertRegexp("/matching contacts.*17/s",
94 $contact['error_message']['message']
99 * Test civicrm_contact_check_params with check for required
100 * params and no params
102 public function testCheckParamsWithNoParams() {
104 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
105 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__
);