Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
6a488035 TO |
28 | |
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | class api_v3_LocBlockTest extends CiviUnitTestCase { | |
31 | protected $_apiversion = 3; | |
32 | protected $_entity = 'loc_block'; | |
33 | public $_eNoticeCompliant = TRUE; | |
34 | public function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function tearDown() { | |
39 | } | |
40 | ||
41 | public function testCreateLocBlock() { | |
70c906cf | 42 | $email = $this->callAPISuccess('email', 'create', array( |
6a488035 TO |
43 | 'contact_id' => 'null', |
44 | 'location_type_id' => 1, | |
45 | 'email' => 'test@loc.block', | |
46 | )); | |
70c906cf | 47 | $phone = $this->callAPISuccess('phone', 'create', array( |
6a488035 TO |
48 | 'contact_id' => 'null', |
49 | 'location_type_id' => 1, | |
50 | 'phone' => '1234567', | |
51 | )); | |
70c906cf | 52 | $address = $this->callAPISuccess('address', 'create', array( |
6a488035 TO |
53 | 'contact_id' => 'null', |
54 | 'location_type_id' => 1, | |
55 | 'street_address' => '1234567', | |
56 | )); | |
57 | $params = array( | |
6a488035 TO |
58 | 'address_id' => $address['id'], |
59 | 'phone_id' => $phone['id'], | |
60 | 'email_id' => $email['id'], | |
61 | ); | |
70c906cf | 62 | $result = $this->callAPISuccess($this->_entity, 'create', $params); |
6a488035 TO |
63 | $id = $result['id']; |
64 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
65 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
66 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
67 | $this->assertNotNull($result['values'][$id]['id'], 'In line ' . __LINE__); | |
68 | $this->getAndCheck($params, $id, $this->_entity); | |
69 | } | |
70 | ||
71 | public function testCreateLocBlockEntities() { | |
72 | $params = array( | |
6a488035 TO |
73 | 'email' => array( |
74 | 'location_type_id' => 1, | |
75 | 'email' => 'test2@loc.block', | |
76 | ), | |
77 | 'phone' => array( | |
78 | 'location_type_id' => 1, | |
79 | 'phone' => '987654321', | |
80 | ), | |
81 | 'phone_2' => array( | |
82 | 'location_type_id' => 1, | |
83 | 'phone' => '456-7890', | |
84 | ), | |
85 | 'address' => array( | |
86 | 'location_type_id' => 1, | |
87 | 'street_address' => '987654321', | |
88 | ), | |
89 | ); | |
70c906cf | 90 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, 'Create entities and location block in 1 api call', NULL, 'createEntities'); |
6a488035 | 91 | $id = $result['id']; |
6a488035 TO |
92 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
93 | ||
94 | // Now check our results using the return param 'all' | |
82adafa2 | 95 | $getParams = array( |
96 | 'version' => $this->_apiversion, | |
97 | 'id' => $id, | |
98 | 'return' => 'all' | |
99 | ); | |
70c906cf | 100 | // Can't use callAPISuccess with getsingle |
6a488035 TO |
101 | $result = civicrm_api($this->_entity, 'getsingle', $getParams); |
102 | $this->documentMe($getParams, $result, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', NULL, 'get'); | |
103 | $this->assertNotNull($result['email_id'], 'In line ' . __LINE__); | |
104 | $this->assertNotNull($result['phone_id'], 'In line ' . __LINE__); | |
105 | $this->assertNotNull($result['phone_2_id'], 'In line ' . __LINE__); | |
106 | $this->assertNotNull($result['address_id'], 'In line ' . __LINE__); | |
107 | $this->assertEquals($params['email']['email'], $result['email']['email'], 'In line ' . __LINE__); | |
108 | $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone'], 'In line ' . __LINE__); | |
109 | $this->assertEquals($params['address']['street_address'], $result['address']['street_address'], 'In line ' . __LINE__); | |
110 | // Delete block | |
70c906cf | 111 | $result = $this->callAPISuccess($this->_entity, 'delete', array('id' => $id)); |
6a488035 TO |
112 | } |
113 | ||
114 | public static function setUpBeforeClass() { | |
115 | // put stuff here that should happen before all tests in this unit | |
116 | } | |
117 | ||
118 | public static function tearDownAfterClass(){ | |
119 | } | |
120 | } | |
121 |