Merge pull request #4627 from colemanw/docblocks
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / PhoneTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30require_once 'CiviTest/Contact.php';
31require_once 'CiviTest/Custom.php';
32require_once 'CiviTest/Event.php';
4cbe18b8
EM
33
34/**
35 * Class CRM_Core_BAO_PhoneTest
36 */
6a488035 37class CRM_Core_BAO_PhoneTest extends CiviUnitTestCase {
4cbe18b8
EM
38 /**
39 * @return array
40 */
6a488035
TO
41 function get_info() {
42 return array(
43 'name' => 'Phone BAOs',
44 'description' => 'Test all Core_BAO_Phone methods.',
45 'group' => 'CiviCRM BAO Tests',
46 );
47 }
48
49 function setUp() {
50 parent::setUp();
51 }
52
53 /**
54 * add() method (create and update modes)
55 */
56 function testAdd() {
57 $contactId = Contact::createIndividual();
58
59 $params = array();
60 $params = array(
61 'phone' => '(415) 222-1011 x 221',
62 'is_primary' => 1,
63 'location_type_id' => 1,
64 'phone_type' => 'Mobile',
65 'contact_id' => $contactId,
66 );
67
68 CRM_Core_BAO_Phone::add($params);
69
70 $phoneId = $this->assertDBNotNull('CRM_Core_DAO_Phone', $contactId, 'id', 'contact_id',
71 'Database check for created phone record.'
72 );
73
74 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-1011 x 221',
75 "Check if phone field has expected value in new record ( civicrm_phone.id={$phoneId} )."
76 );
77
78 // Now call add() to modify the existing phone number
79
80 $params = array();
81 $params = array(
82 'id' => $phoneId,
83 'contact_id' => $contactId,
84 'phone' => '(415) 222-5432',
85 );
86
87 CRM_Core_BAO_Phone::add($params);
88
89 $this->assertDBCompareValue('CRM_Core_DAO_Phone', $phoneId, 'phone', 'id', '(415) 222-5432',
90 "Check if phone field has expected value in updated record ( civicrm_phone.id={$phoneId} )."
91 );
92
93 Contact::delete($contactId);
94 }
95
96 /**
97 * allPhones() method - get all Phones for our contact, with primary Phone first
98 */
99 function testAllPhones() {
100 $contactParams = array(
101 'first_name' => 'Alan',
102 'last_name' => 'Smith',
103 'phone-1' => '(415) 222-1011 x 221',
104 'phone-2' => '(415) 222-5432',
105 );
106
107 $contactId = Contact::createIndividual($contactParams);
108
109 $Phones = CRM_Core_BAO_Phone::allPhones($contactId);
110
111 $this->assertEquals(count($Phones), 2, 'Checking number of returned Phones.');
112
113 $firstPhoneValue = array_slice($Phones, 0, 1);
114
115 // Since we're not passing in a location type to createIndividual above, CRM_Contact_BAO_Contact::createProfileContact uses default location
116 // type for first phone and sets that to primary.
117 $this->assertEquals('(415) 222-1011 x 221', $firstPhoneValue[0]['phone'], "Confirm primary Phone value ( {$firstPhoneValue[0]['phone']} ).");
118 $this->assertEquals(1, $firstPhoneValue[0]['is_primary'], 'Confirm first Phone is primary.');
119
120 Contact::delete($contactId);
121 }
122
123 /**
124 * allEntityPhones() method - get all Phones for a location block, with primary Phone first
125 * @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
126 */
127 function SKIPPED_testAllEntityPhones() {}
128}
129