Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-29-13-10-47
[civicrm-core.git] / tests / phpunit / api / v3 / LocBlockTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
06a1bc01 4| CiviCRM version 4.5 |
b6708aeb 5+--------------------------------------------------------------------+
06a1bc01 6| Copyright CiviCRM LLC (c) 2004-2014 |
b6708aeb 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*/
6a488035
TO
27
28require_once 'CiviTest/CiviUnitTestCase.php';
e9479dcf
EM
29
30/**
31 * Class api_v3_LocBlockTest
32 */
6a488035
TO
33class api_v3_LocBlockTest extends CiviUnitTestCase {
34 protected $_apiversion = 3;
35 protected $_entity = 'loc_block';
b7c9bc4c 36
6a488035
TO
37 public function setUp() {
38 parent::setUp();
39 }
40
41 function tearDown() {
42 }
43
44 public function testCreateLocBlock() {
70c906cf 45 $email = $this->callAPISuccess('email', 'create', array(
6a488035
TO
46 'contact_id' => 'null',
47 'location_type_id' => 1,
48 'email' => 'test@loc.block',
49 ));
70c906cf 50 $phone = $this->callAPISuccess('phone', 'create', array(
6a488035
TO
51 'contact_id' => 'null',
52 'location_type_id' => 1,
53 'phone' => '1234567',
54 ));
70c906cf 55 $address = $this->callAPISuccess('address', 'create', array(
6a488035
TO
56 'contact_id' => 'null',
57 'location_type_id' => 1,
58 'street_address' => '1234567',
59 ));
60 $params = array(
6a488035
TO
61 'address_id' => $address['id'],
62 'phone_id' => $phone['id'],
63 'email_id' => $email['id'],
64 );
69f028bc
CW
65 $description = 'Create locBlock with existing entities';
66 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'simpleCreate');
6a488035 67 $id = $result['id'];
6a488035
TO
68 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
69 $this->assertNotNull($result['values'][$id]['id'], 'In line ' . __LINE__);
70 $this->getAndCheck($params, $id, $this->_entity);
71 }
72
73 public function testCreateLocBlockEntities() {
74 $params = array(
6a488035
TO
75 'email' => array(
76 'location_type_id' => 1,
77 'email' => 'test2@loc.block',
78 ),
79 'phone' => array(
80 'location_type_id' => 1,
81 'phone' => '987654321',
82 ),
83 'phone_2' => array(
84 'location_type_id' => 1,
85 'phone' => '456-7890',
86 ),
87 'address' => array(
88 'location_type_id' => 1,
89 'street_address' => '987654321',
90 ),
91 );
69f028bc
CW
92 $description = "Create entities and locBlock in 1 api call";
93 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'createEntities');
6a488035 94 $id = $result['id'];
6a488035
TO
95 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
96
97 // Now check our results using the return param 'all'
69f028bc
CW
98 $getParams = array(
99 'id' => $id,
100 'return' => 'all',
82adafa2 101 );
70c906cf 102 // Can't use callAPISuccess with getsingle
69f028bc
CW
103 $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', 'getEntities', 'get');
104 $result = array_pop($result['values']);
6a488035
TO
105 $this->assertNotNull($result['email_id'], 'In line ' . __LINE__);
106 $this->assertNotNull($result['phone_id'], 'In line ' . __LINE__);
107 $this->assertNotNull($result['phone_2_id'], 'In line ' . __LINE__);
108 $this->assertNotNull($result['address_id'], 'In line ' . __LINE__);
109 $this->assertEquals($params['email']['email'], $result['email']['email'], 'In line ' . __LINE__);
110 $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone'], 'In line ' . __LINE__);
111 $this->assertEquals($params['address']['street_address'], $result['address']['street_address'], 'In line ' . __LINE__);
112 // Delete block
70c906cf 113 $result = $this->callAPISuccess($this->_entity, 'delete', array('id' => $id));
6a488035
TO
114 }
115
116 public static function setUpBeforeClass() {
117 // put stuff here that should happen before all tests in this unit
118 }
119
120 public static function tearDownAfterClass(){
121 }
122}
123