Merge pull request #16469 from civicrm/5.22
[civicrm-core.git] / tests / phpunit / api / v3 / LocBlockTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
7d61e75f
TO
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
e70a7fc0 10 */
6a488035 11
e9479dcf
EM
12/**
13 * Class api_v3_LocBlockTest
f78dbf0b 14 *
acb109b7 15 * @group headless
e9479dcf 16 */
6a488035 17class api_v3_LocBlockTest extends CiviUnitTestCase {
f78dbf0b 18
6a488035 19 protected $_apiversion = 3;
f78dbf0b 20
6a488035 21 protected $_entity = 'loc_block';
b7c9bc4c 22
11e974ee
EM
23 /**
24 * Set up.
25 */
6a488035
TO
26 public function setUp() {
27 parent::setUp();
1fde2cb2 28 $this->useTransaction(TRUE);
6a488035
TO
29 }
30
5e4f7f74
EM
31 /**
32 * Test creating location block.
33 */
6a488035 34 public function testCreateLocBlock() {
f78dbf0b 35 $email = $this->callAPISuccess('email', 'create', [
6a488035 36 'contact_id' => 'null',
6a488035 37 'email' => 'test@loc.block',
f78dbf0b 38 ]);
39 $phone = $this->callAPISuccess('phone', 'create', [
6a488035
TO
40 'contact_id' => 'null',
41 'location_type_id' => 1,
42 'phone' => '1234567',
f78dbf0b 43 ]);
44 $address = $this->callAPISuccess('address', 'create', [
6a488035
TO
45 'contact_id' => 'null',
46 'location_type_id' => 1,
47 'street_address' => '1234567',
f78dbf0b 48 ]);
49 $params = [
6a488035
TO
50 'address_id' => $address['id'],
51 'phone_id' => $phone['id'],
52 'email_id' => $email['id'],
f78dbf0b 53 ];
69f028bc 54 $description = 'Create locBlock with existing entities';
a828d7b8 55 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description);
6a488035 56 $id = $result['id'];
5e4f7f74
EM
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$id]['id']);
6a488035
TO
59 $this->getAndCheck($params, $id, $this->_entity);
60 }
61
5e4f7f74
EM
62 /**
63 * Test creating location block entities.
64 */
6a488035 65 public function testCreateLocBlockEntities() {
f78dbf0b 66 $params = [
67 'email' => [
6a488035
TO
68 'location_type_id' => 1,
69 'email' => 'test2@loc.block',
f78dbf0b 70 ],
71 'phone' => [
6a488035
TO
72 'location_type_id' => 1,
73 'phone' => '987654321',
f78dbf0b 74 ],
75 'phone_2' => [
6a488035
TO
76 'location_type_id' => 1,
77 'phone' => '456-7890',
f78dbf0b 78 ],
79 'address' => [
6a488035
TO
80 'location_type_id' => 1,
81 'street_address' => '987654321',
f78dbf0b 82 ],
83 ];
5c49fee0 84 $description = "Create entities and locBlock in 1 api call.";
a828d7b8 85 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateEntities');
6a488035 86 $id = $result['id'];
5e4f7f74 87 $this->assertEquals(1, $result['count']);
6a488035 88
5e4f7f74 89 // Now check our results using the return param 'all'.
f78dbf0b 90 $getParams = [
69f028bc
CW
91 'id' => $id,
92 'return' => 'all',
f78dbf0b 93 ];
5e4f7f74 94 // Can't use callAPISuccess with getsingle.
a828d7b8 95 $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call');
69f028bc 96 $result = array_pop($result['values']);
5e4f7f74
EM
97 $this->assertNotNull($result['email_id']);
98 $this->assertNotNull($result['phone_id']);
99 $this->assertNotNull($result['phone_2_id']);
100 $this->assertNotNull($result['address_id']);
101 $this->assertEquals($params['email']['email'], $result['email']['email']);
102 $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone']);
103 $this->assertEquals($params['address']['street_address'], $result['address']['street_address']);
104
f78dbf0b 105 $this->callAPISuccess($this->_entity, 'delete', ['id' => $id]);
6a488035
TO
106 }
107
6a488035 108}