Merge pull request #17476 from civicrm/5.26
[civicrm-core.git] / tests / phpunit / CRM / Report / FormTest.php
CommitLineData
7ec58d2b
J
1<?php
2
3/*
7d61e75f
TO
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 +--------------------------------------------------------------------+
7ec58d2b
J
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 */
27class 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
f212762e 39 /**
40 * Used by testGetFromTo
41 */
42 private function fromToData() {
9099cab3 43 $cases = [];
7ec58d2b 44 // Absolute dates
f212762e 45 $cases['absolute'] = [
46 'expectedFrom' => '20170901000000',
47 'expectedTo' => '20170913235959',
48 'relative' => 0,
49 'from' => '09/01/2017',
50 'to' => '09/13/2017',
51 ];
7ec58d2b
J
52 // "Today" relative date filter
53 $date = new DateTime();
f212762e 54 $cases['today'] = [
55 'expectedFrom' => $date->format('Ymd') . '000000',
56 'expectedTo' => $date->format('Ymd') . '235959',
57 'relative' => 'this.day',
58 'from' => '',
59 'to' => '',
60 ];
7ec58d2b
J
61 // "yesterday" relative date filter
62 $date = new DateTime();
63 $date->sub(new DateInterval('P1D'));
f212762e 64 $cases['yesterday'] = [
65 'expectedFrom' => $date->format('Ymd') . '000000',
66 'expectedTo' => $date->format('Ymd') . '235959',
67 'relative' => 'previous.day',
68 'from' => '',
69 'to' => '',
70 ];
7ec58d2b
J
71 return $cases;
72 }
73
74 /**
75 * Test that getFromTo returns the correct dates.
7ec58d2b 76 */
f212762e 77 public function testGetFromTo() {
78 $cases = $this->fromToData();
79 foreach ($cases as $caseDescription => $case) {
80 $obj = new CRM_Report_Form();
81 list($calculatedFrom, $calculatedTo) = $obj->getFromTo($case['relative'], $case['from'], $case['to']);
82 $this->assertEquals([$case['expectedFrom'], $case['expectedTo']], [$calculatedFrom, $calculatedTo], "fail on data set '{$caseDescription}'. Local php time is " . date('Y-m-d H:i:s') . ' and mysql time is ' . CRM_Core_DAO::singleValueQuery('SELECT NOW()'));
659e3f52 83 }
7ec58d2b
J
84 }
85
86}