Merge pull request #15422 from artfulrobot/queue-parallel
[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 * @group headless
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 = [
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 = ['foo' => 'bar'];
32 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
33 $this->assertEquals(1, $contact['is_error']);
34 }
35
36 /**
37 * Test civicrm_contact_check_params with a duplicate.
38 * and request the error in array format
39 */
40 public function testCheckParamsWithDuplicateContact2() {
41 $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'TestContact@example.com']);
42
43 $params = [
44 'first_name' => 'Test',
45 'last_name' => 'Contact',
46 'email' => 'TestContact@example.com',
47 'contact_type' => 'Individual',
48 ];
49 $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE);
50 $this->assertEquals(1, $contact['is_error']);
51 $this->assertRegexp("/matching contacts.*1/s",
52 $contact['error_message']['message']
53 );
54 }
55
56 /**
57 * Test civicrm_contact_check_params with check for required
58 * params and no params
59 */
60 public function testCheckParamsWithNoParams() {
61 $params = [];
62 $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE);
63 $this->assertEquals(1, $contact['is_error']);
64 }
65
66 }