commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Utils / DeprecatedUtilsTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4 require_once 'CRM/Utils/DeprecatedUtils.php';
5
6 /**
7 * Class CRM_Utils_DeprecatedUtilsTest
8 */
9 class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase {
10
11 public function setUp() {
12 parent::setUp();
13 }
14
15 public function tearDown() {
16 // truncate a few tables
17 $tablesToTruncate = array(
18 'civicrm_contact',
19 'civicrm_email',
20 'civicrm_contribution',
21 'civicrm_website',
22 );
23
24 $this->quickCleanup($tablesToTruncate);
25 }
26
27 /**
28 * Test civicrm_contact_check_params with no contact type.
29 */
30 public function testCheckParamsWithNoContactType() {
31 $params = array('foo' => 'bar');
32 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
33 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__);
34 }
35
36
37 /**
38 * Test civicrm_contact_check_params with a duplicate.
39 */
40 public function testCheckParamsWithDuplicateContact() {
41 // Insert a row in civicrm_contact creating individual contact
42 $op = new PHPUnit_Extensions_Database_Operation_Insert();
43 $op->execute($this->_dbconn,
44 $this->createXMLDataSet(
45 dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml'
46 )
47 );
48 $op->execute($this->_dbconn,
49 $this->createXMLDataSet(
50 dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
51 )
52 );
53
54 $params = array(
55 'first_name' => 'Test',
56 'last_name' => 'Contact',
57 'email' => 'TestContact@example.com',
58 'contact_type' => 'Individual',
59 );
60 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE);
61 $this->assertEquals(1, $contact['is_error']);
62 $this->assertRegexp("/matching contacts.*17/s",
63 CRM_Utils_Array::value('error_message', $contact)
64 );
65 }
66
67
68 /**
69 * Test civicrm_contact_check_params with a duplicate.
70 * and request the error in array format
71 */
72 public function testCheckParamsWithDuplicateContact2() {
73 // Insert a row in civicrm_contact creating individual contact
74 $op = new PHPUnit_Extensions_Database_Operation_Insert();
75 $op->execute($this->_dbconn,
76 $this->createXMLDataSet(
77 dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml'
78 )
79 );
80 $op->execute($this->_dbconn,
81 $this->createXMLDataSet(
82 dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
83 )
84 );
85
86 $params = array(
87 'first_name' => 'Test',
88 'last_name' => 'Contact',
89 'email' => 'TestContact@example.com',
90 'contact_type' => 'Individual',
91 );
92 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE, TRUE);
93 $this->assertEquals(1, $contact['is_error']);
94 $this->assertRegexp("/matching contacts.*17/s",
95 $contact['error_message']['message']
96 );
97 }
98
99 /**
100 * Test civicrm_contact_check_params with check for required
101 * params and no params
102 */
103 public function testCheckParamsWithNoParams() {
104 $params = array();
105 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
106 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__);
107 }
108
109 }