api4 - Import CRM/, Civi/, templates/, ang/, css/, js/, xml/menu
[civicrm-core.git] / tests / phpunit / api / v4 / Action / DateTest.php
CommitLineData
19b53e5b
C
1<?php
2
3namespace api\v4\Action;
4
5use Civi\Api4\Contact;
6use Civi\Api4\Relationship;
7use api\v4\UnitTestCase;
8
9/**
10 * @group headless
11 */
12class DateTest extends UnitTestCase {
13
14 public function testRelationshipDate() {
15 $c1 = Contact::create()
16 ->addValue('first_name', 'c')
17 ->addValue('last_name', 'one')
18 ->execute()
19 ->first()['id'];
20 $c2 = Contact::create()
21 ->addValue('first_name', 'c')
22 ->addValue('last_name', 'two')
23 ->execute()
24 ->first()['id'];
25 $r = Relationship::create()
26 ->addValue('contact_id_a', $c1)
27 ->addValue('contact_id_b', $c2)
28 ->addValue('relationship_type_id', 1)
29 ->addValue('start_date', 'now')
30 ->addValue('end_date', 'now + 1 week')
31 ->execute()
32 ->first()['id'];
33 $result = Relationship::get()
34 ->addWhere('start_date', '=', 'now')
35 ->addWhere('end_date', '>', 'now + 1 day')
36 ->execute()
37 ->indexBy('id');
38 $this->assertArrayHasKey($r, $result);
39 $result = Relationship::get()
40 ->addWhere('start_date', '<', 'now')
41 ->execute()
42 ->indexBy('id');
43 $this->assertArrayNotHasKey($r, $result);
44 }
45
46}