APIv4 - Reorganize test classes, don't use transactions for custom value tests
[civicrm-core.git] / tests / phpunit / api / v4 / Query / OneToOneJoinTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace api\v4\Query;
21
22 use Civi\Api4\Contact;
23 use api\v4\Api4TestBase;
24 use Civi\Test\TransactionalInterface;
25
26 /**
27 * Class OneToOneJoinTest
28 * @package api\v4\Query
29 * @group headless
30 */
31 class OneToOneJoinTest extends Api4TestBase implements TransactionalInterface {
32
33 public function testOneToOneJoin() {
34 $armenianContact = Contact::create()
35 ->addValue('first_name', 'Contact')
36 ->addValue('last_name', 'One')
37 ->addValue('contact_type', 'Individual')
38 ->addValue('preferred_language', 'hy_AM')
39 ->execute()
40 ->first();
41
42 $basqueContact = Contact::create()
43 ->addValue('first_name', 'Contact')
44 ->addValue('last_name', 'Two')
45 ->addValue('contact_type', 'Individual')
46 ->addValue('preferred_language', 'eu_ES')
47 ->execute()
48 ->first();
49
50 $contacts = Contact::get()
51 ->addWhere('id', 'IN', [$armenianContact['id'], $basqueContact['id']])
52 ->addSelect('preferred_language:label')
53 ->addSelect('last_name')
54 ->execute()
55 ->indexBy('last_name');
56
57 $this->assertEquals($contacts['One']['preferred_language:label'], 'Armenian');
58 $this->assertEquals($contacts['Two']['preferred_language:label'], 'Basque');
59 }
60
61 }