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