Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
6a488035 TO |
3 | require_once 'CRM/Utils/DeprecatedUtils.php'; |
4 | ||
aba1cd8b EM |
5 | /** |
6 | * Class CRM_Utils_DeprecatedUtilsTest | |
acb109b7 | 7 | * @group headless |
aba1cd8b | 8 | */ |
6a488035 TO |
9 | class 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 | 16 | // truncate a few tables |
9099cab3 | 17 | $tablesToTruncate = [ |
92915c55 TO |
18 | 'civicrm_contact', |
19 | 'civicrm_email', | |
20 | 'civicrm_contribution', | |
21 | 'civicrm_website', | |
9099cab3 | 22 | ]; |
6a488035 TO |
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() { |
9099cab3 | 31 | $params = ['foo' => 'bar']; |
6a488035 | 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() { |
ae2103ea | 41 | $this->individualCreate(['first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'TestContact@example.com']); |
6a488035 | 42 | |
ae2103ea | 43 | $params = [ |
92915c55 TO |
44 | 'first_name' => 'Test', |
45 | 'last_name' => 'Contact', | |
46 | 'email' => 'TestContact@example.com', | |
47 | 'contact_type' => 'Individual', | |
ae2103ea | 48 | ]; |
ffec8e23 | 49 | $contact = _civicrm_api3_deprecated_contact_check_params($params, TRUE); |
6a488035 | 50 | $this->assertEquals(1, $contact['is_error']); |
ae2103ea | 51 | $this->assertRegexp("/matching contacts.*1/s", |
92915c55 | 52 | $contact['error_message']['message'] |
6a488035 TO |
53 | ); |
54 | } | |
92915c55 | 55 | |
6a488035 TO |
56 | /** |
57 | * Test civicrm_contact_check_params with check for required | |
58 | * params and no params | |
59 | */ | |
00be9182 | 60 | public function testCheckParamsWithNoParams() { |
9099cab3 | 61 | $params = []; |
6a488035 | 62 | $contact = _civicrm_api3_deprecated_contact_check_params($params, FALSE); |
ffec8e23 | 63 | $this->assertEquals(1, $contact['is_error']); |
6a488035 TO |
64 | } |
65 | ||
66 | } |