2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Test for format number and byte
6 * @author Michal Biniek <michal@bystrzyca.pl>
7 * @package phpMyAdmin-test
8 * @version $Id: PMA_formatNumberByteDown_test.php
14 require_once 'PHPUnit/Framework.php';
19 require_once './libraries/common.lib.php';
22 * Test formating number and byte.
25 class PMA_formatNumberByteDown_test
extends PHPUnit_Framework_TestCase
29 * temporary variable for globals array
32 protected $tmpGlobals;
35 * temporary variable for session array
38 protected $tmpSession;
41 * storing globals and session
43 public function setUp() {
45 $this->tmpGlobals
= $GLOBALS;
46 $this->tmpSession
= $_SESSION;
51 * recovering globals and session
53 public function tearDown() {
55 $GLOBALS = $this->tmpGlobals
;
56 $_SESSION = $this->tmpSession
;
61 * format number data provider
64 public function formatNumberDataProvider() {
66 array(10, 2, 2, '10,00 '),
67 array(100, 2, 0, '100 '),
68 array(100, 2, 2, '0,10 k'),
69 array(-1000.454, 4, 2, '-1 000,45 '),
70 array(0.00003, 3, 2, '0,03 m'),
71 array(0.003, 3, 3, '0,003 '),
72 array(-0.003, 6, 0, '-3 m'),
73 array(100.98, 0, 2, '100,98')
78 * format number test, globals are defined
79 * @dataProvider formatNumberDataProvider
82 public function testFormatNumber($a, $b, $c, $e) {
83 $GLOBALS['number_thousands_separator'] = ' ';
84 $GLOBALS['number_decimal_separator'] = ',';
86 $this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false));
90 * format byte down data provider
93 public function formatByteDownDataProvider() {
95 array(10, 2, 2, array('10', 'B')),
96 array(100, 2, 0, array('0', 'KB')),
97 array(100, 3, 0, array('100', 'B')),
98 array(100, 2, 2, array('0,10', 'KB')),
99 array(1034, 3, 2, array('1,01', 'KB')),
100 array(100233, 3, 3, array('97,884', 'KB')),
101 array(2206451, 1, 2, array('2,10', 'MB'))
106 * format byte test, globals are defined
107 * @dataProvider formatByteDownDataProvider
110 public function testFormatByteDown($a, $b, $c, $e) {
111 $GLOBALS['byteUnits'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
112 $GLOBALS['number_thousands_separator'] = ' ';
113 $GLOBALS['number_decimal_separator'] = ',';
116 $result = PMA_formatByteDown($a, $b, $c);
117 $result[0] = trim($result[0]);
118 $this->assertEquals($e, $result);