Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
7d61e75f TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
4cbe18b8 EM |
12 | /** |
13 | * Class CRM_Core_BAO_PhoneTest | |
acb109b7 | 14 | * @group headless |
4cbe18b8 | 15 | */ |
6a488035 | 16 | class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase { |
6a488035 | 17 | |
00be9182 | 18 | public function setUp() { |
6a488035 TO |
19 | parent::setUp(); |
20 | } | |
21 | ||
22 | /** | |
100fef9d | 23 | * Add() method (create and update modes) |
6a488035 | 24 | */ |
00be9182 | 25 | public function testAdd() { |
6ae19242 | 26 | $contactId = $this->individualCreate(); |
6a488035 | 27 | |
9099cab3 CW |
28 | $params = []; |
29 | $params = [ | |
6a488035 TO |
30 | 'phone' => '(415) 222-1011 x 221', |
31 | 'is_primary' => 1, | |
32 | 'location_type_id' => 1, | |
33 | 'phone_type' => 'Mobile', | |
34 | 'contact_id' => $contactId, | |
9099cab3 | 35 | ]; |
6a488035 TO |
36 | |
37 | CRM_Core_BAO_Phone::add($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 add() to modify the existing phone number | |
48 | ||
9099cab3 CW |
49 | $params = []; |
50 | $params = [ | |
6a488035 TO |
51 | 'id' => $phoneId, |
52 | 'contact_id' => $contactId, | |
53 | 'phone' => '(415) 222-5432', | |
9099cab3 | 54 | ]; |
6a488035 TO |
55 | |
56 | CRM_Core_BAO_Phone::add($params); | |
57 | ||
58 | $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432', | |
59 | "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )." | |
60 | ); | |
61 | ||
93ac19cd | 62 | $this->contactDelete($contactId); |
6a488035 TO |
63 | } |
64 | ||
65 | /** | |
6ae19242 | 66 | * AllPhones() method - get all Phones for our contact, with primary Phone first. |
6a488035 | 67 | */ |
00be9182 | 68 | public function testAllPhones() { |
9099cab3 | 69 | $contactParams = [ |
6a488035 TO |
70 | 'first_name' => 'Alan', |
71 | 'last_name' => 'Smith', | |
9099cab3 CW |
72 | 'api.phone.create' => ['phone' => '(415) 222-1011 x 221', 'location_type_id' => 'Home'], |
73 | 'api.phone.create.1' => ['phone' => '(415) 222-5432', 'location_type_id' => 'Work'], | |
74 | ]; | |
6a488035 | 75 | |
6ae19242 | 76 | $contactId = $this->individualCreate($contactParams); |
6a488035 TO |
77 | |
78 | $Phones = CRM_Core_BAO_Phone::allPhones($contactId); | |
79 | ||
80 | $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.'); | |
81 | ||
82 | $firstPhoneValue = array_slice($Phones, 0, 1); | |
83 | ||
84 | // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location | |
85 | // type for first phone and sets that to primary. | |
86 | $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} )."); | |
87 | $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.'); | |
88 | ||
93ac19cd | 89 | $this->contactDelete($contactId); |
6a488035 TO |
90 | } |
91 | ||
92 | /** | |
100fef9d | 93 | * AllEntityPhones() method - get all Phones for a location block, with primary Phone first |
6a488035 TO |
94 | * @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 |
95 | */ | |
6c6e6187 TO |
96 | public function SKIPPED_testAllEntityPhones() { |
97 | } | |
96025800 | 98 | |
6a488035 | 99 | } |