Merge pull request #19921 from eileenmcnaughton/tear
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / PhoneTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Core_BAO_PhoneTest
14 * @group headless
15 */
16 class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
17
18 /**
19 * Add() method (create and update modes)
20 */
21 public function testAdd() {
22 $contactId = $this->individualCreate();
23
24 $params = [];
25 $params = [
26 'phone' => '(415) 222-1011 x 221',
27 'is_primary' => 1,
28 'location_type_id' => 1,
29 'phone_type' => 'Mobile',
30 'contact_id' => $contactId,
31 ];
32
33 CRM_Core_BAO_Phone::create($params);
34
35 $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
36 'Database check for created phone record.'
37 );
38
39 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-1011 x 221',
40 "Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
41 );
42
43 // Now call create() to modify the existing phone number
44
45 $params = [
46 'id' => $phoneId,
47 'contact_id' => $contactId,
48 'phone' => '(415) 222-5432',
49 ];
50
51 CRM_Core_BAO_Phone::create($params);
52
53 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
54 "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
55 );
56
57 $this->contactDelete($contactId);
58 }
59
60 /**
61 * AllPhones() method - get all Phones for our contact, with primary Phone first.
62 */
63 public function testAllPhones() {
64 $contactParams = [
65 'first_name' => 'Alan',
66 'last_name' => 'Smith',
67 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'],
68 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'],
69 ];
70
71 $contactId = $this->individualCreate($contactParams);
72
73 $Phones = CRM_Core_BAO_Phone::allPhones($contactId);
74
75 $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.');
76
77 $firstPhoneValue = array_slice($Phones, 0, 1);
78
79 // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location
80 // type for first phone and sets that to primary.
81 $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} ).");
82 $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.');
83
84 $this->contactDelete($contactId);
85 }
86
87 /**
88 * AllEntityPhones() method - get all Phones for a location block, with primary Phone first
89 * @todo FIXME: Fixing this test requires add helper functions in CiviTest to create location block and phone and link them to an event. Punting to 3.1 cycle. DGG
90 */
91 public function SKIPPED_testAllEntityPhones() {
92 }
93
94 }