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 | */ |
18 | ||
19 | ||
19b53e5b C |
20 | namespace api\v4\Action; |
21 | ||
22 | use Civi\Api4\Contact; | |
23 | use Civi\Api4\Relationship; | |
24 | use api\v4\UnitTestCase; | |
25 | ||
26 | /** | |
27 | * @group headless | |
28 | */ | |
29 | class DateTest extends UnitTestCase { | |
30 | ||
31 | public function testRelationshipDate() { | |
32 | $c1 = Contact::create() | |
33 | ->addValue('first_name', 'c') | |
34 | ->addValue('last_name', 'one') | |
35 | ->execute() | |
36 | ->first()['id']; | |
37 | $c2 = Contact::create() | |
38 | ->addValue('first_name', 'c') | |
39 | ->addValue('last_name', 'two') | |
40 | ->execute() | |
41 | ->first()['id']; | |
42 | $r = Relationship::create() | |
43 | ->addValue('contact_id_a', $c1) | |
44 | ->addValue('contact_id_b', $c2) | |
45 | ->addValue('relationship_type_id', 1) | |
46 | ->addValue('start_date', 'now') | |
47 | ->addValue('end_date', 'now + 1 week') | |
48 | ->execute() | |
49 | ->first()['id']; | |
50 | $result = Relationship::get() | |
51 | ->addWhere('start_date', '=', 'now') | |
52 | ->addWhere('end_date', '>', 'now + 1 day') | |
53 | ->execute() | |
54 | ->indexBy('id'); | |
55 | $this->assertArrayHasKey($r, $result); | |
56 | $result = Relationship::get() | |
57 | ->addWhere('start_date', '<', 'now') | |
58 | ->execute() | |
59 | ->indexBy('id'); | |
60 | $this->assertArrayNotHasKey($r, $result); | |
61 | } | |
62 | ||
63 | } |