mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Reduce duplication in test case.
This commit is contained in:
parent
b1dfab87e4
commit
8800d7bdec
1 changed files with 72 additions and 61 deletions
|
@ -165,81 +165,92 @@ class TextHelperTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for autoLinking
|
||||
*/
|
||||
public static function autoLinkProvider() {
|
||||
return array(
|
||||
array(
|
||||
'This is a test text',
|
||||
'This is a test text',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes (www.cakephp.org)',
|
||||
'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes www.cakephp.org:8080',
|
||||
'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
|
||||
'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>',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment',
|
||||
'This is a test that includes <a href="http://www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment">www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment</a>',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes http://example.com/test.php?foo=bar text',
|
||||
'This is a test that includes <a href="http://example.com/test.php?foo=bar">http://example.com/test.php?foo=bar</a> text',
|
||||
),
|
||||
array(
|
||||
'This is a test that includes www.example.com/test.php?foo=bar text',
|
||||
'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',
|
||||
),
|
||||
array(
|
||||
'Text with a partial www.cakephp.org URL',
|
||||
'Text with a partial <a href="http://www.cakephp.org">www.cakephp.org</a> URL',
|
||||
),
|
||||
array(
|
||||
'Text with a partial WWW.cakephp.org URL',
|
||||
'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> URL',
|
||||
),
|
||||
array(
|
||||
'Text with a partial WWW.cakephp.org ©, URL',
|
||||
'Text with a partial <a href="http://WWW.cakephp.org">WWW.cakephp.org</a> &copy, URL',
|
||||
),
|
||||
array(
|
||||
'Text with a url www.cot.ag/cuIb2Q and more',
|
||||
'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more',
|
||||
),
|
||||
array(
|
||||
'Text with a url http://www.does--not--work.com and more',
|
||||
'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more',
|
||||
),
|
||||
array(
|
||||
'Text with a url http://www.not--work.com and more',
|
||||
'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAutoLinkUrls method
|
||||
*
|
||||
* @dataProvider autoLinkProvider
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoLinkUrls($text, $expected) {
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the options for autoLinkUrls
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAutoLinkUrls() {
|
||||
$text = 'This is a test text';
|
||||
$expected = 'This is a test text';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes (www.cakephp.org)';
|
||||
$expected = 'This is a test that includes (<a href="http://www.cakephp.org">www.cakephp.org</a>)';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes www.cakephp.org:8080';
|
||||
$expected = 'This is a test that includes <a href="http://www.cakephp.org:8080">www.cakephp.org:8080</a>';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes http://de.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
|
||||
$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>';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes www.wikipedia.org/wiki/Kanton_(Schweiz)#fragment';
|
||||
$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>';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes http://example.com/test.php?foo=bar text';
|
||||
$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';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'This is a test that includes www.example.com/test.php?foo=bar text';
|
||||
$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';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'Text with a partial www.cakephp.org URL';
|
||||
$expected = 'Text with a partial <a href="http://www.cakephp.org"\s*>www.cakephp.org</a> URL';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertRegExp('#^' . $expected . '$#', $result);
|
||||
|
||||
public function testAutoLinkUrlsOptions() {
|
||||
$text = 'Text with a partial www.cakephp.org URL';
|
||||
$expected = 'Text with a partial <a href="http://www.cakephp.org" \s*class="link">www.cakephp.org</a> URL';
|
||||
$result = $this->Text->autoLinkUrls($text, array('class' => 'link'));
|
||||
$this->assertRegExp('#^' . $expected . '$#', $result);
|
||||
|
||||
$text = 'Text with a partial WWW.cakephp.org URL';
|
||||
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> URL';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertRegExp('#^' . $expected . '$#', $result);
|
||||
|
||||
$text = 'Text with a partial WWW.cakephp.org © URL';
|
||||
$expected = 'Text with a partial <a href="http://WWW.cakephp.org"\s*>WWW.cakephp.org</a> © URL';
|
||||
$result = $this->Text->autoLinkUrls($text, array('escape' => false));
|
||||
$this->assertRegExp('#^' . $expected . '$#', $result);
|
||||
|
||||
$text = 'Text with a url www.cot.ag/cuIb2Q and more';
|
||||
$expected = 'Text with a url <a href="http://www.cot.ag/cuIb2Q">www.cot.ag/cuIb2Q</a> and more';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'Text with a url http://www.does--not--work.com and more';
|
||||
$expected = 'Text with a url <a href="http://www.does--not--work.com">http://www.does--not--work.com</a> and more';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$text = 'Text with a url http://www.not--work.com and more';
|
||||
$expected = 'Text with a url <a href="http://www.not--work.com">http://www.not--work.com</a> and more';
|
||||
$result = $this->Text->autoLinkUrls($text);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue