Convert test to use a dataprovider instead of multiple calls.

Dataproviders are generally a bit easier to work with in the future.
This commit is contained in:
mark_story 2014-06-16 21:42:54 -04:00
parent 96df2c4b68
commit 74d8e9ea40

View file

@ -363,54 +363,71 @@ class TextHelperTest extends CakeTestCase {
}
/**
* testAutoLinkEmails method
* Data provider for autoLinkEmail.
*
* @return void
*/
public function testAutoLinkEmails() {
$text = 'This is a test text';
$expected = 'This is a test text';
$result = $this->Text->autoLinkUrls($text);
$this->assertEquals($expected, $result);
public function autoLinkEmailProvider() {
return array(
array(
'This is a test text',
'This is a test text',
),
$text = 'email@example.com address';
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
$text = 'email@example.com address';
$expected = '<a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
'email@example.com address',
'<a href="mailto:email@example.com">email@example.com</a> address',
),
$text = '(email@example.com) address';
$expected = '(<a href="mailto:email@example.com">email@example.com</a>) address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
'(email@example.com) address',
'(<a href="mailto:email@example.com">email@example.com</a>) address',
),
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com">email@example.com</a> address',
),
$text = "Text with o'hare._-bob@example.com address";
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
"Text with o'hare._-bob@example.com address",
'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address',
),
$text = 'Text with email@example.com address';
$expected = 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address';
$result = $this->Text->autoLinkEmails($text, array('class' => 'link'));
$this->assertEquals($expected, $result);
array(
'Text with düsentrieb@küchenschöhn-not-working.de address',
'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
),
$text = 'Text with düsentrieb@küchenschöhn-not-working.de address';
$expected = 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address';
$result = $this->Text->autoLinkEmails($text);
$this->assertEquals($expected, $result);
array(
'Text with me@subdomain.küchenschöhn.de address',
'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
),
$text = 'Text with me@subdomain.küchenschöhn.de address';
$expected = 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address';
$result = $this->Text->autoLinkEmails($text);
array(
'Text with email@example.com address',
'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address',
array('class' => 'link'),
),
);
}
/**
* testAutoLinkEmails method
*
* @param string $text The text to link
* @param string $expected The expected results.
* @dataProvider autoLinkEmailProvider
* @return void
*/
public function testAutoLinkEmails($text, $expected, $attrs = array()) {
$result = $this->Text->autoLinkEmails($text, $attrs);
$this->assertEquals($expected, $result);
}