Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PMA_localisedDateTimespan_test.php « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c9884f0a643d5d04e27d006e6043b1b95c082b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Test for generating localised date or timespan expression
 *
 * @author Michal Biniek <michal@bystrzyca.pl>
 * @package phpMyAdmin-test
 * @version $Id: PMA_localisedDateTimespan_test.php
 */

/**
 * Tests core.
 */
require_once 'PHPUnit/Framework.php';

/**
 * Include to test.
 */
require_once './libraries/common.lib.php';

/**
 * Test localised date or timespan expression.
 *
 */
class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
{

    /**
     * temporary variable for globals array
     */

    protected $tmpGlobals;

    /**
     * temporary variable for session array
     */

    protected $tmpSession;

	/**
	 * temporary variable for timezone info
	 */

	protected $tmpTimezone;

    /**
     * storing globals and session
     */
    public function setUp() {

        $this->tmpGlobals = $GLOBALS;
        $this->tmpSession = $_SESSION;
		$this->tmpTimezone = date_default_timezone_get();        
		date_default_timezone_set('Europe/London');
    }

    /**
     * recovering globals and session
     */
    public function tearDown() {

        $GLOBALS = $this->tmpGlobals;
        $_SESSION = $this->tmpSession;
		date_default_timezone_set($this->tmpTimezone);

    }

    /**
     * data provider for localised date test
     */

    public function localisedDateDataProvider() {
        return array(
            array(1227455558, '', 'Nov 23, 2008 at 03:52 PM'),
            array(1227455558, '%Y-%m-%d %H:%M:%S %a', '2008-11-23 15:52:38 Sun')
        );
    }

    /**
     * localised date test, globals are defined
     * @dataProvider localisedDateDataProvider
     */

    public function testLocalisedDate($a, $b, $e) {
        $GLOBALS['day_of_week'] = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
        $GLOBALS['month'] = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
        $GLOBALS['datefmt'] = '%B %d, %Y at %I:%M %p';

        $this->assertEquals($e, PMA_localisedDate($a, $b));
    }

    /**
     * data provider for localised timestamp test
     */

    public function timespanFormatDataProvider() {
        return array(
            array(1258, '0 days, 0 hours, 20 minutes and 58 seconds'),
            array(821958, '9 days, 12 hours, 19 minutes and 18 seconds')
        );
    }

    /**
     * localised timestamp test, globals are defined
     * @dataProvider timespanFormatDataProvider
     */

    public function testTimespanFormat($a, $e) {
        $GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds';

        $this->assertEquals($e, PMA_timespanFormat($a));
    }
}
?>