Merge pull request #18447 from mlutfy/inheritLocaleRegression
[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 public function setUp() {
19 parent::setUp();
20 }
21
22 /**
23 * Add() method (create and update modes)
24 */
25 public function testAdd() {
26 $contactId = $this->individualCreate();
27
28 $params = [];
29 $params = [
30 'phone' => '(415) 222-1011 x 221',
31 'is_primary' => 1,
32 'location_type_id' => 1,
33 'phone_type' => 'Mobile',
34 'contact_id' => $contactId,
35 ];
36
37 CRM_Core_BAO_Phone::create($params);
38
39 $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
40 'Database check for created phone record.'
41 );
42
43 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-1011 x 221',
44 "Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
45 );
46
47 // Now call create() to modify the existing phone number
48
49 $params = [
50 'id' => $phoneId,
51 'contact_id' => $contactId,
52 'phone' => '(415) 222-5432',
53 ];
54
55 CRM_Core_BAO_Phone::create($params);
56
57 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
58 "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
59 );
60
61 $this->contactDelete($contactId);
62 }
63
64 /**
65 * AllPhones() method - get all Phones for our contact, with primary Phone first.
66 */
67 public function testAllPhones() {
68 $contactParams = [
69 'first_name' => 'Alan',
70 'last_name' => 'Smith',
71 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'],
72 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'],
73 ];
74
75 $contactId = $this->individualCreate($contactParams);
76
77 $Phones = CRM_Core_BAO_Phone::allPhones($contactId);
78
79 $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.');
80
81 $firstPhoneValue = array_slice($Phones, 0, 1);
82
83 // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location
84 // type for first phone and sets that to primary.
85 $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} ).");
86 $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.');
87
88 $this->contactDelete($contactId);
89 }
90
91 /**
92 * AllEntityPhones() method - get all Phones for a location block, with primary Phone first
93 * @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
94 */
95 public function SKIPPED_testAllEntityPhones() {
96 }
97
98 }