Eric Barnes avatar Eric Barnes committed 4328728

Added unit tests for number helper.

Comments (0)

Files changed (1)

tests/codeigniter/helpers/number_helper_test.php

 <?php
 
-require_once(BASEPATH.'helpers/number_helper.php');
+require_once BASEPATH.'helpers/number_helper.php';
 
 class Number_helper_test extends CI_TestCase
 {
 	
+	public function set_up()
+	{
+		// Grab the core lang class
+		$lang_cls = $this->ci_core_class('lang');
+		
+		// Mock away load, too much going on in there,
+		// we'll just check for the expected parameter
+		
+		$lang = $this->getMock($lang_cls, array('load'));
+		$lang->expects($this->once())
+			 ->method('load')
+			 ->with($this->equalTo('number'));
+		
+		// Assign the proper language array
+		
+		$lang->language = $this->_get_lang('number');
+		
+		// We don't have a controller, so just create
+		// a cheap class to act as our super object.
+		// Make sure it has a lang attribute.
+		
+		$obj = new StdClass;
+		$obj->lang = $lang;
+		$this->ci_instance($obj);
+	}
+	
+	// Quick helper to actually grab the language
+	// file. Consider moving this to ci_testcase?
+	public function _get_lang($name)
+	{
+		require BASEPATH.'language/english/'.$name.'_lang.php';
+		return $lang;
+	}
+	
 	public function test_byte_format()
 	{
-		// $this->assertEquals('456 Bytes', byte_format(456));
+		$this->assertEquals('456 Bytes', byte_format(456));
 	}
 	
-}
+	public function test_kb_format()
+	{
+		$this->assertEquals('4.5 KB', byte_format(4567));
+	}
+	
+	public function test_kb_format_medium()
+	{
+		$this->assertEquals('44.6 KB', byte_format(45678));
+	}
+	
+	public function test_kb_format_large()
+	{
+		$this->assertEquals('446.1 KB', byte_format(456789));
+	}
+	
+	public function test_mb_format()
+	{
+		$this->assertEquals('3.3 MB', byte_format(3456789));
+	}
+	
+	public function test_gb_format()
+	{
+		$this->assertEquals('1.8 GB', byte_format(1932735283.2));
+	}
+	
+	public function test_tb_format()
+	{
+		$this->assertEquals('112,283.3 TB', byte_format(123456789123456789));
+	}
+}
+
+// EOF
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.