Merge branch 'QA_3_3'
[phpmyadmin/dkf.git] / test / PMA_formatNumberByteDown_test.php
blobfcc3bc539aa76ef647ff6915da5d411002a51616
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for format number and byte
6 * @package phpMyAdmin-test
7 * @version $Id: PMA_formatNumberByteDown_test.php
8 */
10 /**
11 * Tests core.
13 require_once 'PHPUnit/Framework.php';
15 /**
16 * Include to test.
18 require_once './libraries/common.lib.php';
20 /**
21 * Test formating number and byte.
24 class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
27 /**
28 * temporary variable for globals array
31 protected $tmpGlobals;
33 /**
34 * temporary variable for session array
37 protected $tmpSession;
39 /**
40 * storing globals and session
42 public function setUp() {
44 $this->tmpGlobals = $GLOBALS;
45 $this->tmpSession = $_SESSION;
49 /**
50 * recovering globals and session
52 public function tearDown() {
54 $GLOBALS = $this->tmpGlobals;
55 $_SESSION = $this->tmpSession;
59 /**
60 * format number data provider
63 public function formatNumberDataProvider() {
64 return array(
65 array(10, 2, 2, '10,00 '),
66 array(100, 2, 0, '100 '),
67 array(100, 2, 2, '0,10 k'),
68 array(-1000.454, 4, 2, '-1 000,45 '),
69 array(0.00003, 3, 2, '0,03 m'),
70 array(0.003, 3, 3, '0,003 '),
71 array(-0.003, 6, 0, '-3 m'),
72 array(100.98, 0, 2, '100,98')
76 /**
77 * format number test, globals are defined
78 * @dataProvider formatNumberDataProvider
81 public function testFormatNumber($a, $b, $c, $e) {
82 $GLOBALS['number_thousands_separator'] = ' ';
83 $GLOBALS['number_decimal_separator'] = ',';
85 $this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false));
88 /**
89 * format byte down data provider
92 public function formatByteDownDataProvider() {
93 return array(
94 array(10, 2, 2, array('10', 'B')),
95 array(100, 2, 0, array('0', 'KB')),
96 array(100, 3, 0, array('100', 'B')),
97 array(100, 2, 2, array('0,10', 'KB')),
98 array(1034, 3, 2, array('1,01', 'KB')),
99 array(100233, 3, 3, array('97,884', 'KB')),
100 array(2206451, 1, 2, array('2,10', 'MB'))
105 * format byte test, globals are defined
106 * @dataProvider formatByteDownDataProvider
109 public function testFormatByteDown($a, $b, $c, $e) {
110 $GLOBALS['byteUnits'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
111 $GLOBALS['number_thousands_separator'] = ' ';
112 $GLOBALS['number_decimal_separator'] = ',';
115 $result = PMA_formatByteDown($a, $b, $c);
116 $result[0] = trim($result[0]);
117 $this->assertEquals($e, $result);