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 * @return void
*/ */
public function testAutoLinkEmails() { public function autoLinkEmailProvider() {
$text = 'This is a test text'; return array(
$expected = 'This is a test text'; array(
$result = $this->Text->autoLinkUrls($text); 'This is a test text',
$this->assertEquals($expected, $result); 'This is a test text',
),
$text = 'email@example.com address'; array(
$expected = '<a href="mailto:email@example.com">email@example.com</a> address'; 'email@example.com address',
$result = $this->Text->autoLinkEmails($text); '<a href="mailto:email@example.com">email@example.com</a> address',
$this->assertEquals($expected, $result); ),
$text = 'email@example.com address'; array(
$expected = '<a href="mailto:email@example.com">email@example.com</a> address'; 'email@example.com address',
$result = $this->Text->autoLinkEmails($text); '<a href="mailto:email@example.com">email@example.com</a> address',
$this->assertEquals($expected, $result); ),
$text = '(email@example.com) address'; array(
$expected = '(<a href="mailto:email@example.com">email@example.com</a>) address'; '(email@example.com) address',
$result = $this->Text->autoLinkEmails($text); '(<a href="mailto:email@example.com">email@example.com</a>) address',
$this->assertEquals($expected, $result); ),
$text = 'Text with email@example.com address'; array(
$expected = 'Text with <a href="mailto:email@example.com">email@example.com</a> address'; 'Text with email@example.com address',
$result = $this->Text->autoLinkEmails($text); 'Text with <a href="mailto:email@example.com">email@example.com</a> address',
$this->assertEquals($expected, $result); ),
$text = "Text with o'hare._-bob@example.com address"; array(
$expected = 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address'; "Text with o'hare._-bob@example.com address",
$result = $this->Text->autoLinkEmails($text); 'Text with <a href="mailto:o&#039;hare._-bob@example.com">o&#039;hare._-bob@example.com</a> address',
$this->assertEquals($expected, $result); ),
$text = 'Text with email@example.com address'; array(
$expected = 'Text with <a href="mailto:email@example.com" class="link">email@example.com</a> address'; 'Text with düsentrieb@küchenschöhn-not-working.de address',
$result = $this->Text->autoLinkEmails($text, array('class' => 'link')); 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address',
$this->assertEquals($expected, $result); ),
$text = 'Text with düsentrieb@küchenschöhn-not-working.de address'; array(
$expected = 'Text with <a href="mailto:düsentrieb@küchenschöhn-not-working.de">düsentrieb@küchenschöhn-not-working.de</a> address'; 'Text with me@subdomain.küchenschöhn.de address',
$result = $this->Text->autoLinkEmails($text); 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address',
$this->assertEquals($expected, $result); ),
$text = 'Text with me@subdomain.küchenschöhn.de address'; array(
$expected = 'Text with <a href="mailto:me@subdomain.küchenschöhn.de">me@subdomain.küchenschöhn.de</a> address'; 'Text with email@example.com address',
$result = $this->Text->autoLinkEmails($text); '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); $this->assertEquals($expected, $result);
} }