Commit | Line | Data |
---|---|---|
7ec58d2b J |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
2fe49090 | 5 | | CiviCRM version 5 | |
7ec58d2b | 6 | +--------------------------------------------------------------------+ |
6b83d5bd | 7 | | Copyright CiviCRM LLC (c) 2004-2019 | |
7ec58d2b J |
8 | +--------------------------------------------------------------------+ |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * File for the FormTest class | |
31 | * | |
32 | * (PHP 5) | |
33 | * | |
34 | * @author Jon Goldberg <jon@megaphonetech.com> | |
35 | */ | |
36 | ||
37 | /** | |
38 | * Test CRM_Report_Form functions. | |
39 | * | |
40 | * @package CiviCRM | |
41 | * @group headless | |
42 | */ | |
43 | class CRM_Report_FormTest extends CiviUnitTestCase { | |
44 | ||
45 | public function setUp() { | |
46 | // There are only unit tests here at present, we can skip database loading. | |
47 | return TRUE; | |
48 | } | |
49 | ||
50 | public function tearDown() { | |
51 | // There are only unit tests here at present, we can skip database loading. | |
52 | return TRUE; | |
53 | } | |
54 | ||
55 | public function fromToData() { | |
56 | $cases = array(); | |
57 | // Absolute dates | |
58 | $cases[] = array('20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'); | |
59 | // "Today" relative date filter | |
60 | $date = new DateTime(); | |
61 | $expectedFrom = $date->format('Ymd') . '000000'; | |
62 | $expectedTo = $date->format('Ymd') . '235959'; | |
63 | $cases[] = array($expectedFrom, $expectedTo, 'this.day', '', ''); | |
64 | // "yesterday" relative date filter | |
65 | $date = new DateTime(); | |
66 | $date->sub(new DateInterval('P1D')); | |
67 | $expectedFrom = $date->format('Ymd') . '000000'; | |
68 | $expectedTo = $date->format('Ymd') . '235959'; | |
69 | $cases[] = array($expectedFrom, $expectedTo, 'previous.day', '', ''); | |
70 | return $cases; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Test that getFromTo returns the correct dates. | |
75 | * | |
76 | * @dataProvider fromToData | |
659e3f52 | 77 | * |
78 | * @param string $expectedFrom | |
79 | * @param string $expectedTo | |
80 | * @param string $relative | |
81 | * @param string $from | |
82 | * @param string $to | |
7ec58d2b J |
83 | */ |
84 | public function testGetFromTo($expectedFrom, $expectedTo, $relative, $from, $to) { | |
85 | $obj = new CRM_Report_Form(); | |
659e3f52 | 86 | if (date('H-i') === '00:00') { |
87 | $this->markTestIncomplete('The date might have changed since the dataprovider was called. Skip to avoid flakiness'); | |
88 | } | |
7ec58d2b | 89 | list($calculatedFrom, $calculatedTo) = $obj->getFromTo($relative, $from, $to); |
350f28f7 | 90 | $this->assertEquals([$expectedFrom, $expectedTo], [$calculatedFrom, $calculatedTo], "fail on data set [ $relative , $from , $to ]. Local php time is " . date('Y-m-d H:i:s') . ' and mysql time is ' . CRM_Core_DAO::singleValueQuery('SELECT NOW()')); |
7ec58d2b J |
91 | } |
92 | ||
93 | } |