3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class CRM_Core_BAO_PhoneTest
31 class CRM_Core_BAO_PhoneTest
extends CiviUnitTestCase
{
33 public function setUp() {
38 * Add() method (create and update modes)
40 public function testAdd() {
41 $contactId = Contact
::createIndividual();
45 'phone' => '(415) 222-1011 x 221',
47 'location_type_id' => 1,
48 'phone_type' => 'Mobile',
49 'contact_id' => $contactId,
52 CRM_Core_BAO_Phone
::add($params);
54 $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
55 'Database check for created phone record.'
58 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-1011 x 221',
59 "Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
62 // Now call add() to modify the existing phone number
67 'contact_id' => $contactId,
68 'phone' => '(415) 222-5432',
71 CRM_Core_BAO_Phone
::add($params);
73 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
74 "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
77 Contact
::delete($contactId);
81 * AllPhones() method - get all Phones for our contact, with primary Phone first
83 public function testAllPhones() {
84 $contactParams = array(
85 'first_name' => 'Alan',
86 'last_name' => 'Smith',
87 'phone-1' => '(415) 222-1011 x 221',
88 'phone-2' => '(415) 222-5432',
91 $contactId = Contact
::createIndividual($contactParams);
93 $Phones = CRM_Core_BAO_Phone
::allPhones($contactId);
95 $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.');
97 $firstPhoneValue = array_slice($Phones, 0, 1);
99 // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location
100 // type for first phone and sets that to primary.
101 $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} ).");
102 $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.');
104 Contact
::delete($contactId);
108 * AllEntityPhones() method - get all Phones for a location block, with primary Phone first
109 * @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 public function SKIPPED_testAllEntityPhones() {