tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Utils / DeprecatedUtilsTest.php
1 <?php
2
3 require_once 'CRM/Utils/DeprecatedUtils.php';
4
5 /**
6 * Class CRM_Utils_DeprecatedUtilsTest
7 */
8 class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase {
9
10 public function setUp() {
11 parent::setUp();
12 }
13
14 public function tearDown() {
15 // truncate a few tables
16 $tablesToTruncate = array(
17 'civicrm_contact',
18 'civicrm_email',
19 'civicrm_contribution',
20 'civicrm_website',
21 );
22
23 $this->quickCleanup($tablesToTruncate);
24 }
25
26 /**
27 * Test civicrm_contact_check_params with no contact type.
28 */
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__);
33 }
34
35
36 /**
37 * Test civicrm_contact_check_params with a duplicate.
38 */
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'
45 )
46 );
47 $op->execute($this->_dbconn,
48 $this->createXMLDataSet(
49 dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
50 )
51 );
52
53 $params = array(
54 'first_name' => 'Test',
55 'last_name' => 'Contact',
56 'email' => 'TestContact@example.com',
57 'contact_type' => 'Individual',
58 );
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)
63 );
64 }
65
66
67 /**
68 * Test civicrm_contact_check_params with a duplicate.
69 * and request the error in array format
70 */
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'
77 )
78 );
79 $op->execute($this->_dbconn,
80 $this->createXMLDataSet(
81 dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
82 )
83 );
84
85 $params = array(
86 'first_name' => 'Test',
87 'last_name' => 'Contact',
88 'email' => 'TestContact@example.com',
89 'contact_type' => 'Individual',
90 );
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']
95 );
96 }
97
98 /**
99 * Test civicrm_contact_check_params with check for required
100 * params and no params
101 */
102 public function testCheckParamsWithNoParams() {
103 $params = array();
104 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
105 $this->assertEquals(1, $contact['is_error'], "In line " . __LINE__);
106 }
107
108 }