| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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 | require_once 'CiviTest/CiviUnitTestCase.php'; |
| 29 | |
| 30 | /** |
| 31 | * Class api_v3_LocBlockTest |
| 32 | */ |
| 33 | class api_v3_LocBlockTest extends CiviUnitTestCase { |
| 34 | protected $_apiversion = 3; |
| 35 | protected $_entity = 'loc_block'; |
| 36 | |
| 37 | public function setUp() { |
| 38 | parent::setUp(); |
| 39 | $this->useTransaction(TRUE); |
| 40 | } |
| 41 | |
| 42 | public function testCreateLocBlock() { |
| 43 | $email = $this->callAPISuccess('email', 'create', array( |
| 44 | 'contact_id' => 'null', |
| 45 | 'location_type_id' => 1, |
| 46 | 'email' => 'test@loc.block', |
| 47 | )); |
| 48 | $phone = $this->callAPISuccess('phone', 'create', array( |
| 49 | 'contact_id' => 'null', |
| 50 | 'location_type_id' => 1, |
| 51 | 'phone' => '1234567', |
| 52 | )); |
| 53 | $address = $this->callAPISuccess('address', 'create', array( |
| 54 | 'contact_id' => 'null', |
| 55 | 'location_type_id' => 1, |
| 56 | 'street_address' => '1234567', |
| 57 | )); |
| 58 | $params = array( |
| 59 | 'address_id' => $address['id'], |
| 60 | 'phone_id' => $phone['id'], |
| 61 | 'email_id' => $email['id'], |
| 62 | ); |
| 63 | $description = 'Create locBlock with existing entities'; |
| 64 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'simpleCreate'); |
| 65 | $id = $result['id']; |
| 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( |
| 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 | ); |
| 90 | $description = "Create entities and locBlock in 1 api call"; |
| 91 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'createEntities'); |
| 92 | $id = $result['id']; |
| 93 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
| 94 | |
| 95 | // Now check our results using the return param 'all' |
| 96 | $getParams = array( |
| 97 | 'id' => $id, |
| 98 | 'return' => 'all', |
| 99 | ); |
| 100 | // Can't use callAPISuccess with getsingle |
| 101 | $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', 'getEntities', 'get'); |
| 102 | $result = array_pop($result['values']); |
| 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 |
| 111 | $result = $this->callAPISuccess($this->_entity, 'delete', array('id' => $id)); |
| 112 | } |
| 113 | |
| 114 | } |