summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/helpers/string_helper_test.php
blob: 71449f64a2c33e2f1937763f220fab69c25c407f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?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));
		}
	}	

	// --------------------------------------------------------------------	

}