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