Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Query; |
23 | ||
24 | use Civi\Api4\Query\Api4SelectQuery; | |
25 | use api\v4\UnitTestCase; | |
26 | ||
27 | /** | |
28 | * @group headless | |
29 | */ | |
30 | class OptionValueJoinTest extends UnitTestCase { | |
31 | ||
32 | public function setUpHeadless() { | |
33 | $relatedTables = [ | |
34 | 'civicrm_address', | |
35 | 'civicrm_email', | |
36 | 'civicrm_phone', | |
37 | 'civicrm_openid', | |
38 | 'civicrm_im', | |
39 | 'civicrm_website', | |
40 | 'civicrm_activity', | |
41 | 'civicrm_activity_contact', | |
42 | ]; | |
43 | ||
44 | $this->cleanup(['tablesToTruncate' => $relatedTables]); | |
45 | $this->loadDataSet('SingleContact'); | |
46 | ||
47 | return parent::setUpHeadless(); | |
48 | } | |
49 | ||
50 | public function testCommunicationMethodJoin() { | |
3c7c8fa6 CW |
51 | $api = \Civi\API\Request::create('Contact', 'get', ['version' => 4, 'checkPermissions' => FALSE]); |
52 | $query = new Api4SelectQuery($api); | |
19b53e5b | 53 | $query->select[] = 'first_name'; |
340afbdf | 54 | $query->select[] = 'preferred_communication_method:label'; |
19b53e5b C |
55 | $query->where[] = ['preferred_communication_method', 'IS NOT NULL']; |
56 | $results = $query->run(); | |
57 | $first = array_shift($results); | |
75dbb936 CW |
58 | $keys = array_keys($first); |
59 | sort($keys); | |
340afbdf CW |
60 | $this->assertEquals(['first_name', 'id', 'preferred_communication_method:label'], $keys); |
61 | $firstPreferredMethod = array_shift($first['preferred_communication_method:label']); | |
19b53e5b C |
62 | |
63 | $this->assertEquals( | |
64 | 'Phone', | |
340afbdf | 65 | $firstPreferredMethod |
19b53e5b C |
66 | ); |
67 | } | |
68 | ||
69 | } |