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