Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 3 | require_once BASEPATH.'helpers/number_helper.php'; |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 4 | |
| 5 | class Number_helper_test extends CI_TestCase |
| 6 | { |
| 7 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 8 | public function set_up() |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 9 | { |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 10 | // Grab the core lang class |
| 11 | $lang_cls = $this->ci_core_class('lang'); |
| 12 | |
| 13 | // Mock away load, too much going on in there, |
| 14 | // we'll just check for the expected parameter |
| 15 | |
| 16 | $lang = $this->getMock($lang_cls, array('load')); |
| 17 | $lang->expects($this->once()) |
| 18 | ->method('load') |
| 19 | ->with($this->equalTo('number')); |
| 20 | |
| 21 | // Assign the proper language array |
| 22 | |
| 23 | $lang->language = $this->_get_lang('number'); |
| 24 | |
| 25 | // We don't have a controller, so just create |
| 26 | // a cheap class to act as our super object. |
| 27 | // Make sure it has a lang attribute. |
| 28 | |
| 29 | $obj = new StdClass; |
| 30 | $obj->lang = $lang; |
| 31 | $this->ci_instance($obj); |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Eric Barnes | 19379ef | 2011-05-03 22:16:11 -0400 | [diff] [blame] | 34 | // Quick helper to actually grab the language |
| 35 | // file. Consider moving this to ci_testcase? |
| 36 | public function _get_lang($name) |
| 37 | { |
| 38 | require BASEPATH.'language/english/'.$name.'_lang.php'; |
| 39 | return $lang; |
| 40 | } |
| 41 | |
| 42 | public function test_byte_format() |
| 43 | { |
| 44 | $this->assertEquals('456 Bytes', byte_format(456)); |
| 45 | } |
| 46 | |
| 47 | public function test_kb_format() |
| 48 | { |
| 49 | $this->assertEquals('4.5 KB', byte_format(4567)); |
| 50 | } |
| 51 | |
| 52 | public function test_kb_format_medium() |
| 53 | { |
| 54 | $this->assertEquals('44.6 KB', byte_format(45678)); |
| 55 | } |
| 56 | |
| 57 | public function test_kb_format_large() |
| 58 | { |
| 59 | $this->assertEquals('446.1 KB', byte_format(456789)); |
| 60 | } |
| 61 | |
| 62 | public function test_mb_format() |
| 63 | { |
| 64 | $this->assertEquals('3.3 MB', byte_format(3456789)); |
| 65 | } |
| 66 | |
| 67 | public function test_gb_format() |
| 68 | { |
| 69 | $this->assertEquals('1.8 GB', byte_format(1932735283.2)); |
| 70 | } |
| 71 | |
| 72 | public function test_tb_format() |
| 73 | { |
| 74 | $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // EOF |