blob: 71449f64a2c33e2f1937763f220fab69c25c407f [file] [log] [blame]
Greg Aker052b01d2011-04-21 14:38:03 -05001<?php
2
3require_once(BASEPATH.'helpers/string_helper.php');
4
5class String_helper_test extends PHPUnit_Framework_TestCase
6{
7 public function testTrimSlashes()
8 {
9 $strs = array(
10 '//Slashes//\/' => 'Slashes//\\',
11 '/var/www/html/' => 'var/www/html'
12 );
13
14 foreach ($strs as $str => $expect)
15 {
16 $this->assertEquals($expect, trim_slashes($str));
17 }
18 }
19
20 // --------------------------------------------------------------------
21
22 public function testStripSlashes()
23 {
24 $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd"));
25 }
26
27 // --------------------------------------------------------------------
28
29 public function testStripQuotes()
30 {
31 $strs = array(
32 '"me oh my!"' => 'me oh my!',
33 "it's a winner!" => 'its a winner!',
34 );
35
36 foreach ($strs as $str => $expect)
37 {
38 $this->assertEquals($expect, strip_quotes($str));
39 }
40 }
41
42 // --------------------------------------------------------------------
43
44 public function testQuotesToEntities()
45 {
46 $strs = array(
47 '"me oh my!"' => '&quot;me oh my!&quot;',
48 "it's a winner!" => 'it&#39;s a winner!',
49 );
50
51 foreach ($strs as $str => $expect)
52 {
53 $this->assertEquals($expect, quotes_to_entities($str));
54 }
55 }
56
57 // --------------------------------------------------------------------
58
59 public function testReduceDoubleSlashes()
60 {
61 $strs = array(
62 'http://codeigniter.com' => 'http://codeigniter.com',
63 '//var/www/html/example.com/' => '/var/www/html/example.com/',
64 '/var/www/html//index.php' => '/var/www/html/index.php'
65 );
66
67 foreach ($strs as $str => $expect)
68 {
69 $this->assertEquals($expect, reduce_double_slashes($str));
70 }
71 }
72
73 // --------------------------------------------------------------------
74
75 public function testReduceMultiples()
76 {
77 $strs = array(
78 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy',
79 'Ringo, John, Paul,,' => 'Ringo, John, Paul,'
80 );
81
82 foreach ($strs as $str => $expect)
83 {
84 $this->assertEquals($expect, reduce_multiples($str));
85 }
86
87 $strs = array(
88 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy',
89 'Ringo, John, Paul,,' => 'Ringo, John, Paul'
90 );
91
92 foreach ($strs as $str => $expect)
93 {
94 $this->assertEquals($expect, reduce_multiples($str, ',', TRUE));
95 }
96 }
97
98 // --------------------------------------------------------------------
99
100 public function testRepeater()
101 {
102 $strs = array(
103 'a' => 'aaaaaaaaaa',
104 '&nbsp;' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
105 '<br>' => '<br><br><br><br><br><br><br><br><br><br>'
106
107 );
108
109 foreach ($strs as $str => $expect)
110 {
111 $this->assertEquals($expect, repeater($str, 10));
112 }
113 }
114
115 // --------------------------------------------------------------------
116
117}