blob: ef6aae138e2e2ad16e10b7d9d39f72e6019d9c9e [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 {
Andrey Andreev99b782d2012-06-09 22:24:46 +03004
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');
Andrey Andreev99b782d2012-06-09 22:24:46 +03008
Eric Barnes19379ef2011-05-03 22:16:11 -04009 // Grab the core lang class
10 $lang_cls = $this->ci_core_class('lang');
Andrey Andreev99b782d2012-06-09 22:24:46 +030011
Eric Barnes19379ef2011-05-03 22:16:11 -040012 // Mock away load, too much going on in there,
13 // we'll just check for the expected parameter
Andrey Andreev99b782d2012-06-09 22:24:46 +030014
Eric Barnes19379ef2011-05-03 22:16:11 -040015 $lang = $this->getMock($lang_cls, array('load'));
16 $lang->expects($this->once())
17 ->method('load')
18 ->with($this->equalTo('number'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030019
Eric Barnes19379ef2011-05-03 22:16:11 -040020 // Assign the proper language array
Andrey Andreev99b782d2012-06-09 22:24:46 +030021
Eric Barnes19379ef2011-05-03 22:16:11 -040022 $lang->language = $this->_get_lang('number');
Andrey Andreev99b782d2012-06-09 22:24:46 +030023
Eric Barnes19379ef2011-05-03 22:16:11 -040024 // 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.
Andrey Andreev99b782d2012-06-09 22:24:46 +030027
Andrey Andreevc1862882012-06-09 23:16:58 +030028 $obj = new stdClass;
Eric Barnes19379ef2011-05-03 22:16:11 -040029 $obj->lang = $lang;
30 $this->ci_instance($obj);
Eric Barnes68286a42011-04-21 22:00:33 -040031 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030032
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 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030040
Eric Barnes19379ef2011-05-03 22:16:11 -040041 public function test_byte_format()
42 {
43 $this->assertEquals('456 Bytes', byte_format(456));
44 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030045
Eric Barnes19379ef2011-05-03 22:16:11 -040046 public function test_kb_format()
47 {
48 $this->assertEquals('4.5 KB', byte_format(4567));
49 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030050
Eric Barnes19379ef2011-05-03 22:16:11 -040051 public function test_kb_format_medium()
52 {
53 $this->assertEquals('44.6 KB', byte_format(45678));
54 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030055
Eric Barnes19379ef2011-05-03 22:16:11 -040056 public function test_kb_format_large()
57 {
58 $this->assertEquals('446.1 KB', byte_format(456789));
59 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030060
Eric Barnes19379ef2011-05-03 22:16:11 -040061 public function test_mb_format()
62 {
63 $this->assertEquals('3.3 MB', byte_format(3456789));
64 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030065
Eric Barnes19379ef2011-05-03 22:16:11 -040066 public function test_gb_format()
67 {
68 $this->assertEquals('1.8 GB', byte_format(1932735283.2));
69 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030070
Eric Barnes19379ef2011-05-03 22:16:11 -040071 public function test_tb_format()
72 {
73 $this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
74 }
Eric Barnes19379ef2011-05-03 22:16:11 -040075
Andrey Andreev99b782d2012-06-09 22:24:46 +030076}