4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 namespace api\v
4\Entity
;
21 use api\v
4\UnitTestCase
;
22 use Civi\Api4\Address
;
23 use Civi\Api4\Contact
;
24 use Civi\Test\TransactionalInterface
;
27 * Test Address functionality
31 class AddressTest
extends UnitTestCase
implements TransactionalInterface
{
34 * Check that 2 addresses for the same contact can't both be primary
36 public function testPrimary() {
37 $cid = Contact
::create(FALSE)->addValue('first_name', uniqid())->execute()->single()['id'];
39 $a1 = Address
::create(FALSE)
40 ->addValue('is_primary', TRUE)
41 ->addValue('contact_id', $cid)
42 ->addValue('location_type_id', 1)
43 ->addValue('city', 'Somewhere')
46 $a2 = Address
::create(FALSE)
47 ->addValue('is_primary', TRUE)
48 ->addValue('contact_id', $cid)
49 ->addValue('location_type_id', 2)
50 ->addValue('city', 'Elsewhere')
53 $addresses = Address
::get(FALSE)
54 ->addWhere('contact_id', '=', $cid)
58 $this->assertFalse($addresses[0]['is_primary']);
59 $this->assertTrue($addresses[1]['is_primary']);