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