fix typo in workaround
[civicrm-core.git] / tests / phpunit / CRM / Report / FormTest.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 * File for the FormTest class
15 *
16 * (PHP 5)
17 *
18 * @author Jon Goldberg <jon@megaphonetech.com>
19 */
20
21 /**
22 * Test CRM_Report_Form functions.
23 *
24 * @package CiviCRM
25 * @group headless
26 */
27 class CRM_Report_FormTest extends CiviUnitTestCase {
28
29 public function setUp() {
30 // There are only unit tests here at present, we can skip database loading.
31 return TRUE;
32 }
33
34 public function tearDown() {
35 // There are only unit tests here at present, we can skip database loading.
36 return TRUE;
37 }
38
39 public function fromToData() {
40 $cases = [];
41 // Absolute dates
42 $cases[] = ['20170901000000', '20170913235959', 0, '09/01/2017', '09/13/2017'];
43 // "Today" relative date filter
44 $date = new DateTime();
45 $expectedFrom = $date->format('Ymd') . '000000';
46 $expectedTo = $date->format('Ymd') . '235959';
47 $cases[] = [$expectedFrom, $expectedTo, 'this.day', '', ''];
48 // "yesterday" relative date filter
49 $date = new DateTime();
50 $date->sub(new DateInterval('P1D'));
51 $expectedFrom = $date->format('Ymd') . '000000';
52 $expectedTo = $date->format('Ymd') . '235959';
53 $cases[] = [$expectedFrom, $expectedTo, 'previous.day', '', ''];
54 return $cases;
55 }
56
57 /**
58 * Test that getFromTo returns the correct dates.
59 *
60 * @dataProvider fromToData
61 *
62 * @param string $expectedFrom
63 * @param string $expectedTo
64 * @param string $relative
65 * @param string $from
66 * @param string $to
67 */
68 public function testGetFromTo($expectedFrom, $expectedTo, $relative, $from, $to) {
69 $obj = new CRM_Report_Form();
70 if (date('Hi') === '0000') {
71 $this->markTestIncomplete('The date might have changed since the dataprovider was called. Skip to avoid flakiness');
72 }
73 list($calculatedFrom, $calculatedTo) = $obj->getFromTo($relative, $from, $to);
74 $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()'));
75 }
76
77 }