Merge pull request #9973 from lcdservices/CRM-19469
[civicrm-core.git] / tests / phpunit / CRM / Utils / DeprecatedUtilsTest.php
CommitLineData
6a488035
TO
1<?php
2
6a488035
TO
3require_once 'CRM/Utils/DeprecatedUtils.php';
4
aba1cd8b
EM
5/**
6 * Class CRM_Utils_DeprecatedUtilsTest
acb109b7 7 * @group headless
aba1cd8b 8 */
6a488035
TO
9class CRM_Utils_DeprecatedUtilsTest extends CiviUnitTestCase {
10
00be9182 11 public function setUp() {
6a488035
TO
12 parent::setUp();
13 }
92915c55 14
00be9182 15 public function tearDown() {
6a488035
TO
16 // truncate a few tables
17 $tablesToTruncate = array(
92915c55
TO
18 'civicrm_contact',
19 'civicrm_email',
20 'civicrm_contribution',
21 'civicrm_website',
6a488035
TO
22 );
23
24 $this->quickCleanup($tablesToTruncate);
6a488035 25 }
92915c55 26
6a488035 27 /**
fe482240 28 * Test civicrm_contact_check_params with no contact type.
6a488035 29 */
00be9182 30 public function testCheckParamsWithNoContactType() {
6a488035
TO
31 $params = array('foo' => 'bar');
32 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
6a488035 33 $this->assertEquals(1, $contact['is_error']);
6a488035
TO
34 }
35
6a488035 36 /**
fe482240 37 * Test civicrm_contact_check_params with a duplicate.
6a488035
TO
38 * and request the error in array format
39 */
00be9182 40 public function testCheckParamsWithDuplicateContact2() {
6a488035
TO
41 // Insert a row in civicrm_contact creating individual contact
42 $op = new PHPUnit_Extensions_Database_Operation_Insert();
43 $op->execute($this->_dbconn,
92915c55
TO
44 $this->createXMLDataSet(
45 dirname(__FILE__) . '/../../api/v3/dataset/contact_17.xml'
46 )
6a488035
TO
47 );
48 $op->execute($this->_dbconn,
92915c55
TO
49 $this->createXMLDataSet(
50 dirname(__FILE__) . '/../../api/v3/dataset/email_contact_17.xml'
51 )
6a488035
TO
52 );
53
54 $params = array(
92915c55
TO
55 'first_name' => 'Test',
56 'last_name' => 'Contact',
57 'email' => 'TestContact@example.com',
58 'contact_type' => 'Individual',
6a488035 59 );
ffec8e23 60 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE);
6a488035
TO
61 $this->assertEquals(1, $contact['is_error']);
62 $this->assertRegexp("/matching contacts.*17/s",
92915c55 63 $contact['error_message']['message']
6a488035
TO
64 );
65 }
92915c55 66
6a488035
TO
67 /**
68 * Test civicrm_contact_check_params with check for required
69 * params and no params
70 */
00be9182 71 public function testCheckParamsWithNoParams() {
6a488035
TO
72 $params = array();
73 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
ffec8e23 74 $this->assertEquals(1, $contact['is_error']);
6a488035
TO
75 }
76
77}