Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 3 | class Number_helper_test extends CI_TestCase { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 4 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 5 | public function set_up() |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 6 | { |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 7 | $this->helper('number'); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 8 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 9 | // Grab the core lang class |
| 10 | $lang_cls = $this->ci_core_class('lang'); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 11 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 12 | // Mock away load, too much going on in there, |
| 13 | // we'll just check for the expected parameter |
Andrey Andreev | 878e23f | 2016-08-10 15:15:49 +0300 | [diff] [blame] | 14 | $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 15 | $lang->expects($this->once()) |
| 16 | ->method('load') |
| 17 | ->with($this->equalTo('number')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 18 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 19 | // Assign the proper language array |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 20 | $lang->language = $this->lang('number'); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 21 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 22 | // We don't have a controller, so just create |
| 23 | // a cheap class to act as our super object. |
| 24 | // Make sure it has a lang attribute. |
dchill42 | 7ecc5cd | 2012-10-12 16:25:51 -0400 | [diff] [blame] | 25 | $this->ci_instance_var('lang', $lang); |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 26 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 27 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 28 | public function test_byte_format() |
| 29 | { |
| 30 | $this->assertEquals('456 Bytes', byte_format(456)); |
| 31 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 32 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 33 | public function test_kb_format() |
| 34 | { |
| 35 | $this->assertEquals('4.5 KB', byte_format(4567)); |
| 36 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 37 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 38 | public function test_kb_format_medium() |
| 39 | { |
| 40 | $this->assertEquals('44.6 KB', byte_format(45678)); |
| 41 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 42 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 43 | public function test_kb_format_large() |
| 44 | { |
| 45 | $this->assertEquals('446.1 KB', byte_format(456789)); |
| 46 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 47 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 48 | public function test_mb_format() |
| 49 | { |
| 50 | $this->assertEquals('3.3 MB', byte_format(3456789)); |
| 51 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 52 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 53 | public function test_gb_format() |
| 54 | { |
| 55 | $this->assertEquals('1.8 GB', byte_format(1932735283.2)); |
| 56 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 57 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 58 | public function test_tb_format() |
| 59 | { |
| 60 | $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); |
| 61 | } |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 62 | |
Andrey Andreev | 878e23f | 2016-08-10 15:15:49 +0300 | [diff] [blame] | 63 | } |