babd1cec0fabeb1dda14764ab839aef72eefa605
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
22 namespace api\v
4\Action
;
24 use api\v
4\UnitTestCase
;
25 use Civi\Api4\Activity
;
26 use Civi\Api4\Contact
;
31 class FkJoinTest
extends UnitTestCase
{
33 public function setUpHeadless() {
37 'civicrm_activity_contact',
39 $this->cleanup(['tablesToTruncate' => $relatedTables]);
40 $this->loadDataSet('DefaultDataSet');
42 return parent
::setUpHeadless();
46 * Fetch all phone call activities. Expects a single activity
47 * loaded from the data set.
49 public function testThreeLevelJoin() {
50 $results = Activity
::get()
51 ->setCheckPermissions(FALSE)
52 ->addWhere('activity_type_id:name', '=', 'Phone Call')
55 $this->assertCount(1, $results);
58 public function testActivityContactJoin() {
59 $results = Activity
::get()
60 ->setCheckPermissions(FALSE)
61 ->addSelect('assignees.id')
62 ->addSelect('assignees.first_name')
63 ->addSelect('assignees.display_name')
64 ->addWhere('assignees.first_name', '=', 'Phoney')
67 $firstResult = $results->first();
69 $this->assertCount(1, $results);
70 $this->assertTrue(is_array($firstResult['assignees']));
72 $firstAssignee = array_shift($firstResult['assignees']);
73 $this->assertEquals($firstAssignee['first_name'], 'Phoney');
76 public function testContactPhonesJoin() {
77 $testContact = $this->getReference('test_contact_1');
78 $testPhone = $this->getReference('test_phone_1');
80 $results = Contact
::get()
81 ->setCheckPermissions(FALSE)
82 ->addSelect('phones.phone')
83 ->addWhere('id', '=', $testContact['id'])
84 ->addWhere('phones.location_type.name', '=', 'Home')
88 $this->assertArrayHasKey('phones', $results);
89 $this->assertCount(1, $results['phones']);
90 $firstPhone = array_shift($results['phones']);
91 $this->assertEquals($testPhone['phone'], $firstPhone['phone']);