blob: 663e354fef3053ad2a2f618fb2694cbaf8437594 [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 Andreev878e23f2016-08-10 15:15:49 +030014 $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
Eric Barnes19379ef2011-05-03 22:16:11 -040015 $lang->expects($this->once())
16 ->method('load')
17 ->with($this->equalTo('number'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030018
Eric Barnes19379ef2011-05-03 22:16:11 -040019 // Assign the proper language array
dchill427ecc5cd2012-10-12 16:25:51 -040020 $lang->language = $this->lang('number');
Andrey Andreev99b782d2012-06-09 22:24:46 +030021
Eric Barnes19379ef2011-05-03 22:16:11 -040022 // 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.
dchill427ecc5cd2012-10-12 16:25:51 -040025 $this->ci_instance_var('lang', $lang);
Eric Barnes19379ef2011-05-03 22:16:11 -040026 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030027
Eric Barnes19379ef2011-05-03 22:16:11 -040028 public function test_byte_format()
29 {
30 $this->assertEquals('456 Bytes', byte_format(456));
31 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030032
Eric Barnes19379ef2011-05-03 22:16:11 -040033 public function test_kb_format()
34 {
35 $this->assertEquals('4.5 KB', byte_format(4567));
36 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030037
Eric Barnes19379ef2011-05-03 22:16:11 -040038 public function test_kb_format_medium()
39 {
40 $this->assertEquals('44.6 KB', byte_format(45678));
41 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030042
Eric Barnes19379ef2011-05-03 22:16:11 -040043 public function test_kb_format_large()
44 {
45 $this->assertEquals('446.1 KB', byte_format(456789));
46 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030047
Eric Barnes19379ef2011-05-03 22:16:11 -040048 public function test_mb_format()
49 {
50 $this->assertEquals('3.3 MB', byte_format(3456789));
51 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030052
Eric Barnes19379ef2011-05-03 22:16:11 -040053 public function test_gb_format()
54 {
55 $this->assertEquals('1.8 GB', byte_format(1932735283.2));
56 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030057
Eric Barnes19379ef2011-05-03 22:16:11 -040058 public function test_tb_format()
59 {
60 $this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
61 }
Eric Barnes19379ef2011-05-03 22:16:11 -040062
Andrey Andreev878e23f2016-08-10 15:15:49 +030063}