Dotclear

source: unit-tests/inc/libs/clearbricks/common/lib.date.Test.php @ 1095:4c9e899ae2df

Revision 1095:4c9e899ae2df, 2.1 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

PHPUnit Unit tests: Clearbricks lib, not yet completed

Line 
1<?php
2# error reporting
3ini_set('display_errors',1);
4error_reporting(E_ALL|E_STRICT);
5
6# include PHPUnit
7require 'PHPUnit/Autoload.php';
8
9// Paths
10if (!defined('NAME_UNIT_TEST')) {
11     defined('NAME_UNIT_TEST','unit-tests');
12}
13$sync_test_path = preg_replace('#/'.NAME_UNIT_TEST.'#','',dirname(__FILE__));
14
15// File to test
16//define('CLEARBRICKS_PATH',ROOT_UNIT_TEST.'/inc/libs/clearbricks');
17//require_once(CLEARBRICKS_PATH.'/common/lib.date.php');
18require_once($sync_test_path.'/lib.date.php');
19
20// Unit test class
21class dtTest extends PHPUnit_Framework_TestCase
22{
23     // Fixture
24     protected $d;
25
26     public function setUp() {
27          $this->d = new dt;
28          $this->d->setTZ('UTC');
29     }
30     public function tearDown() {}
31
32     // Unit test methods
33
34     public function test_str() {
35          $t = mktime(10, 42, 0, 8, 13, 2003);
36          $this->assertTrue($this->d->str('%A %e %B %Y %H:%M:%S',$t) == 'Wednesday 13 August 2003 10:42:00');
37     }
38
39     public function test_dt2str() {
40          $t = mktime(10, 42, 0, 8, 13, 2003);
41          $this->assertTrue($this->d->dt2str('%A %e %B %Y %H:%M:%S',date('D, d M Y H:i:s',$t)) == 'Wednesday 13 August 2003 10:42:00');
42     }
43
44     public function test_isoe8601() {
45          $t = mktime(10, 42, 0, 8, 13, 2003);
46          $this->assertTrue($this->d->iso8601($t) == '2003-08-13T10:42:00+00:00');
47     }
48
49     public function test_rfc822() {
50          $t = mktime(10, 42, 0, 8, 13, 2003);
51          $this->assertTrue($this->d->rfc822($t) == 'Wed, 13 Aug 2003 10:42:00 +0000');
52     }
53
54     public function test_setTZ() {
55          $this->d->setTZ('Europe/Paris');
56          $this->assertTrue($this->d->getTZ() == 'Europe/Paris');
57     }
58
59     public function test_getTZ() {
60          $this->assertTrue($this->d->getTZ() == 'UTC');
61     }
62
63     public function test_getTimeOffset() {
64          // Should cope with summer/winter time offset
65          $this->assertTrue($this->d->getTimeOffset('Europe/Paris') == 3600 || $this->d->getTimeOffset('Europe/Paris') == 7200);
66     }
67
68     public function test_toUTC() {
69          $this->assertTrue($this->d->toUTC(time()) == time());
70     }
71
72     public function test_addTimeZone() {
73          $this->assertTrue($this->d->addTimeZone('UTC') == time());
74     }
75
76     public function test_getZones() {
77          $this->assertNotEmpty($this->d->getZones(false,true));
78     }
79}
80?>
Note: See TracBrowser for help on using the repository browser.

Sites map