Merge pull request #3399 from totten/4.4-time-threshold
[civicrm-core.git] / tests / phpunit / CRM / Utils / TimeTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 class CRM_Utils_TimeTest extends CiviUnitTestCase {
6 public function equalCases() {
7 $cases = array(); // array(0 => $timeA, 1 => $timeB, 2 => $threshold, 3 => $expectedResult)
8 $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:00', 0, 1);
9 $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:01', 0, 0);
10 $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:00:50', 60, 1);
11 $cases[] = array('2012-04-01 12:00:00', '2012-04-01 12:01:02', 60, 0);
12 $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 0, 0);
13 $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 60, 1);
14 $cases[] = array('2012-04-01 12:00', '2012-04-01 12:01', 120, 1);
15 return $cases;
16 }
17
18 /**
19 * @param string $timeA
20 * @param string $timeB
21 * @param int $threshold
22 * @param bool $expectedResult
23 * @dataProvider equalCases
24 */
25 function testEquals($timeA, $timeB, $threshold, $expectedResult) {
26 $actual = CRM_Utils_Time::isEqual($timeA, $timeB, $threshold);
27 $this->assertEquals($expectedResult, $actual);
28
29 $actual = CRM_Utils_Time::isEqual($timeB, $timeA, $threshold);
30 $this->assertEquals($expectedResult, $actual);
31 }
32 }