Merge pull request #15503 from magnolia61/Generalize_Thank_You_in_Message_Templates
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / PhoneTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035 27
4cbe18b8
EM
28/**
29 * Class CRM_Core_BAO_PhoneTest
acb109b7 30 * @group headless
4cbe18b8 31 */
6a488035 32class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
6a488035 33
00be9182 34 public function setUp() {
6a488035
TO
35 parent::setUp();
36 }
37
38 /**
100fef9d 39 * Add() method (create and update modes)
6a488035 40 */
00be9182 41 public function testAdd() {
6ae19242 42 $contactId = $this->individualCreate();
6a488035 43
9099cab3
CW
44 $params = [];
45 $params = [
6a488035
TO
46 'phone' => '(415) 222-1011 x 221',
47 'is_primary' => 1,
48 'location_type_id' => 1,
49 'phone_type' => 'Mobile',
50 'contact_id' => $contactId,
9099cab3 51 ];
6a488035
TO
52
53 CRM_Core_BAO_Phone::add($params);
54
55 $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
56 'Database check for created phone record.'
57 );
58
59 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-1011 x 221',
60 "Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
61 );
62
63 // Now call add() to modify the existing phone number
64
9099cab3
CW
65 $params = [];
66 $params = [
6a488035
TO
67 'id' => $phoneId,
68 'contact_id' => $contactId,
69 'phone' => '(415) 222-5432',
9099cab3 70 ];
6a488035
TO
71
72 CRM_Core_BAO_Phone::add($params);
73
74 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
75 "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
76 );
77
93ac19cd 78 $this->contactDelete($contactId);
6a488035
TO
79 }
80
81 /**
6ae19242 82 * AllPhones() method - get all Phones for our contact, with primary Phone first.
6a488035 83 */
00be9182 84 public function testAllPhones() {
9099cab3 85 $contactParams = [
6a488035
TO
86 'first_name' => 'Alan',
87 'last_name' => 'Smith',
9099cab3
CW
88 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'],
89 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'],
90 ];
6a488035 91
6ae19242 92 $contactId = $this->individualCreate($contactParams);
6a488035
TO
93
94 $Phones = CRM_Core_BAO_Phone::allPhones($contactId);
95
96 $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.');
97
98 $firstPhoneValue = array_slice($Phones, 0, 1);
99
100 // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location
101 // type for first phone and sets that to primary.
102 $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} ).");
103 $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.');
104
93ac19cd 105 $this->contactDelete($contactId);
6a488035
TO
106 }
107
108 /**
100fef9d 109 * AllEntityPhones() method - get all Phones for a location block, with primary Phone first
6a488035
TO
110 * @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
111 */
6c6e6187
TO
112 public function SKIPPED_testAllEntityPhones() {
113 }
96025800 114
6a488035 115}