Skip to content
This repository
Browse code

Reduce duplication in test case.

  • Loading branch information...
commit 8800d7bdec1a2a08999ca7932a3b830a0ec79c6d 1 parent b1dfab8
Mark Story authored October 11, 2012
127  lib/Cake/Test/Case/View/Helper/TextHelperTest.php
@@ -166,80 +166,91 @@ public function testAutoLinkEscape() {
166 166
 	}
167 167
 
168 168
 /**
  169
+ * Data provider for autoLinking
  170
+ */
  171
+	public static function autoLinkProvider() {
  172
+		return array(
  173
+			array(
  174
+				'This is a test text',
  175
+				'This is a test text',
  176
+			),
  177
+			array(
  178
+				'This is a test that includes (www.cakephp.org)',
  179
+				'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)',
  180
+			),
  181
+			array(
  182
+				'This is a test that includes www.cakephp.org:8080',
  183
+				'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>',
  184
+			),
  185
+			array(
  186
+				'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
  187
+				'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
  188
+			),
  189
+			array(
  190
+				'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
  191
+				'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
  192
+			),
  193
+			array(
  194
+				'This is a test that includes http://example.com/test.php?foo=bar text',
  195
+				'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text',
  196
+			),
  197
+			array(
  198
+				'This is a test that includes www.example.com/test.php?foo=bar text',
  199
+				'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text',
  200
+			),
  201
+			array(
  202
+				'Text with a partial www.cakephp.org URL',
  203
+				'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL',
  204
+			),
  205
+			array(
  206
+				'Text with a partial WWW.cakephp.org URL',
  207
+				'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> URL',
  208
+			),
  209
+			array(
  210
+				'Text with a partial WWW.cakephp.org &copy, URL',
  211
+				'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> &amp;copy, URL',
  212
+			),
  213
+			array(
  214
+				'Text with a url www.cot.ag/cuIb2Q and more',
  215
+				'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more',
  216
+			),
  217
+			array(
  218
+				'Text with a url http://www.does--not--work.com and more',
  219
+				'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more',
  220
+			),
  221
+			array(
  222
+				'Text with a url http://www.not--work.com and more',
  223
+				'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
  224
+			),
  225
+		);
  226
+	}
  227
+
  228
+/**
169 229
  * testAutoLinkUrls method
170 230
  *
  231
+ * @dataProvider autoLinkProvider
171 232
  * @return void
172 233
  */
173  
-	public function testAutoLinkUrls() {
174  
-		$text = 'This is a test text';
175  
-		$expected = 'This is a test text';
176  
-		$result = $this->Text->autoLinkUrls($text);
177  
-		$this->assertEquals($expected, $result);
178  
-
179  
-		$text = 'This is a test that includes (www.cakephp.org)';
180  
-		$expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
181  
-		$result = $this->Text->autoLinkUrls($text);
182  
-		$this->assertEquals($expected, $result);
183  
-
184  
-		$text = 'This is a test that includes www.cakephp.org:8080';
185  
-		$expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
  234
+	public function testAutoLinkUrls($text, $expected) {
186 235
 		$result = $this->Text->autoLinkUrls($text);
187 236
 		$this->assertEquals($expected, $result);
  237
+	}
188 238
 
189  
-		$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
190  
-		$expected = 'This is a test that includes <a href="http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
191  
-		$result = $this->Text->autoLinkUrls($text);
192  
-		$this->assertEquals($expected, $result);
193  
-
194  
-		$text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
195  
-		$expected = 'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>';
196  
-		$result = $this->Text->autoLinkUrls($text);
197  
-		$this->assertEquals($expected, $result);
198  
-
199  
-		$text = 'This is a test that includes http://example.com/test.php?foo=bar text';
200  
-		$expected = 'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text';
201  
-		$result = $this->Text->autoLinkUrls($text);
202  
-		$this->assertEquals($expected, $result);
203  
-
204  
-		$text = 'This is a test that includes www.example.com/test.php?foo=bar text';
205  
-		$expected = 'This is a test that includes <a href="http://www.example.com/test.php?foo=bar">www.example.com/test.php?foo=bar</a> text';
206  
-		$result = $this->Text->autoLinkUrls($text);
207  
-		$this->assertEquals($expected, $result);
208  
-
209  
-		$text = 'Text with a partial www.cakephp.org URL';
210  
-		$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
211  
-		$result = $this->Text->autoLinkUrls($text);
212  
-		$this->assertRegExp('#^' . $expected . '$#', $result);
213  
-
  239
+/**
  240
+ * Test the options for autoLinkUrls
  241
+ *
  242
+ * @return void
  243
+ */
  244
+	public function testAutoLinkUrlsOptions() {
214 245
 		$text = 'Text with a partial www.cakephp.org URL';
215 246
 		$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
216 247
 		$result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
217 248
 		$this->assertRegExp('#^' . $expected . '$#', $result);
218 249
 
219  
-		$text = 'Text with a partial WWW.cakephp.org URL';
220  
-		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
221  
-		$result = $this->Text->autoLinkUrls($text);
222  
-		$this->assertRegExp('#^' . $expected . '$#', $result);
223  
-
224 250
 		$text = 'Text with a partial WWW.cakephp.org &copy; URL';
225 251
 		$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> &copy; URL';
226 252
 		$result = $this->Text->autoLinkUrls($text, array('escape' => false));
227 253
 		$this->assertRegExp('#^' . $expected . '$#', $result);
228  
-
229  
-		$text = 'Text with a url www.cot.ag/cuIb2Q and more';
230  
-		$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
231  
-		$result = $this->Text->autoLinkUrls($text);
232  
-		$this->assertEquals($expected, $result);
233  
-
234  
-		$text = 'Text with a url http://www.does--not--work.com and more';
235  
-		$expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
236  
-		$result = $this->Text->autoLinkUrls($text);
237  
-		$this->assertEquals($expected, $result);
238  
-
239  
-		$text = 'Text with a url http://www.not--work.com and more';
240  
-		$expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
241  
-		$result = $this->Text->autoLinkUrls($text);
242  
-		$this->assertEquals($expected, $result);
243 254
 	}
244 255
 
245 256
 /**

0 notes on commit 8800d7b

Please sign in to comment.
Something went wrong with that request. Please try again.