Commit | Line | Data |
---|---|---|
819e6707 J |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.7 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2017 | | |
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 DateTest class | |
31 | * | |
32 | * (PHP 5) | |
33 | * | |
34 | * @author Jon Goldberg <jon@megaphonetech.com> | |
35 | */ | |
36 | ||
37 | /** | |
38 | * Test CRM_Utils_Date functions. | |
39 | * | |
40 | * @package CiviCRM | |
41 | * @group headless | |
42 | */ | |
43 | class CRM_Utils_DateTest 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 | |
77 | * @param $expectedFrom | |
78 | * @param $expectedTo | |
79 | * @param $relative | |
80 | * @param $from | |
81 | * @param $to | |
82 | */ | |
83 | public function testGetFromTo($expectedFrom, $expectedTo, $relative, $from, $to) { | |
84 | $obj = new CRM_Utils_Date(); | |
85 | list($calculatedFrom, $calculatedTo) = $obj->getFromTo($relative, $from, $to); | |
86 | $this->assertEquals($expectedFrom, $calculatedFrom); | |
87 | $this->assertEquals($expectedTo, $calculatedTo); | |
88 | } | |
89 | ||
90 | } |