Commits

Greg Aker committed 51a1438

Adding string helper and inflector helper tests

Comments (0)

Files changed (2)

tests/codeigniter/helpers/inflector_helper_test.php

+<?php
+
+require_once(BASEPATH.'helpers/inflector_helper.php');
+
+class Inflector_helper_test extends PHPUnit_Framework_TestCase {
+	
+	
+	public function testSingular()
+	{
+		$strs = array(
+			'tellies'		=> 'telly',
+			'smellies'		=> 'smelly',
+			'abjectnesses'	=> 'abjectness',
+			'smells'		=> 'smell'
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, singular($str));
+		}
+	}
+	
+	// --------------------------------------------------------------------
+	
+	public function testPlural()
+	{
+		$strs = array(
+			'telly'			=> 'tellies',
+			'smelly'		=> 'smellies',
+			'abjectness'	=> 'abjectness',
+			'smell'			=> 'smells',
+			'witch'			=> 'witches'
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, plural($str));
+		}		
+	}	
+
+	// --------------------------------------------------------------------
+	
+	public function testCamelize()
+	{
+		$strs = array(
+			'this is the string'	=> 'thisIsTheString',
+			'this is another one'	=> 'thisIsAnotherOne',
+			'i-am-playing-a-trick'	=> 'i-am-playing-a-trick',
+			'what_do_you_think-yo?'	=> 'whatDoYouThink-yo?',
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, camelize($str));
+		}
+	}	
+
+	// --------------------------------------------------------------------
+	
+	public function testUnderscore()
+	{
+		$strs = array(
+			'this is the string'	=> 'this_is_the_string',
+			'this is another one'	=> 'this_is_another_one',
+			'i-am-playing-a-trick'	=> 'i-am-playing-a-trick',
+			'what_do_you_think-yo?'	=> 'what_do_you_think-yo?',
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, underscore($str));
+		}
+	}
+
+	// --------------------------------------------------------------------
+	
+	public function testHumanize()
+	{
+		$strs = array(
+			'this_is_the_string'	=> 'This Is The String',
+			'this_is_another_one'	=> 'This Is Another One',
+			'i-am-playing-a-trick'	=> 'I-am-playing-a-trick',
+			'what_do_you_think-yo?'	=> 'What Do You Think-yo?',
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, humanize($str));
+		}
+	}
+}

tests/codeigniter/helpers/string_helper_test.php

+<?php
+
+require_once(BASEPATH.'helpers/string_helper.php');
+
+class String_helper_test extends PHPUnit_Framework_TestCase
+{
+	public function testTrimSlashes()
+	{
+		$strs = array(
+			'//Slashes//\/'	=> 'Slashes//\\',
+			'/var/www/html/'	=> 'var/www/html'
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, trim_slashes($str));
+		}
+	}
+	
+	// --------------------------------------------------------------------	
+	
+	public function testStripSlashes()
+	{
+		$this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd"));
+	}
+
+	// --------------------------------------------------------------------	
+
+	public function testStripQuotes()
+	{
+		$strs = array(
+			'"me oh my!"'		=> 'me oh my!',
+			"it's a winner!"	=> 'its a winner!',
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, strip_quotes($str));
+		}
+	}
+
+	// --------------------------------------------------------------------	
+	
+	public function testQuotesToEntities()
+	{
+		$strs = array(
+			'"me oh my!"'		=> '&quot;me oh my!&quot;',
+			"it's a winner!"	=> 'it&#39;s a winner!',
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, quotes_to_entities($str));
+		}		
+	}
+
+	// --------------------------------------------------------------------	
+	
+	public function testReduceDoubleSlashes()
+	{
+		$strs = array(
+			'http://codeigniter.com'		=> 'http://codeigniter.com',
+			'//var/www/html/example.com/'	=> '/var/www/html/example.com/',
+			'/var/www/html//index.php'		=> '/var/www/html/index.php'
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, reduce_double_slashes($str));
+		}		
+	}
+
+	// --------------------------------------------------------------------	
+	
+	public function testReduceMultiples()
+	{
+		$strs = array(
+			'Fred, Bill,, Joe, Jimmy'	=> 'Fred, Bill, Joe, Jimmy',
+			'Ringo, John, Paul,,'		=> 'Ringo, John, Paul,'
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, reduce_multiples($str));
+		}
+		
+		$strs = array(
+			'Fred, Bill,, Joe, Jimmy'	=> 'Fred, Bill, Joe, Jimmy',
+			'Ringo, John, Paul,,'		=> 'Ringo, John, Paul'
+		);		
+
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, reduce_multiples($str, ',', TRUE));
+		}		
+	}
+	
+	// --------------------------------------------------------------------	
+	
+	public function testRepeater()
+	{
+		$strs = array(
+			'a'			=> 'aaaaaaaaaa',
+			'&nbsp;'	=> '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+			'<br>'		=> '<br><br><br><br><br><br><br><br><br><br>'
+			
+		);
+		
+		foreach ($strs as $str => $expect)
+		{
+			$this->assertEquals($expect, repeater($str, 10));
+		}
+	}	
+
+	// --------------------------------------------------------------------	
+
+}