Thomas Bruederli
2013-02-01 c5a5f989a9bf91927e6bb627f9f789800ce02fad
commit | author | age
5f8ada 1 <?php
AM 2
3 /**
4  * Test class to test rcube_string_replacer class
5  *
6  * @package Tests
7  */
8 class Framework_StringReplacer extends PHPUnit_Framework_TestCase
9 {
10
11     /**
12      * Class constructor
13      */
14     function test_class()
15     {
16         $sr = new rcube_string_replacer;
17
18         $this->assertInstanceOf('rcube_string_replacer', $sr, "Class constructor");
19     }
22c67d 20
AM 21     /**
22      * Data for test_replace()
23      */
24     function data_replace()
25     {
26         return array(
27             array('http://domain.tld/path*path2', '<a href="http://domain.tld/path*path2" target="_blank">http://domain.tld/path*path2</a>'),
c96d3f 28             array("Click this link:\nhttps://mail.xn--brderli-o2a.ch/rc/ EOF", "Click this link:\n<a href=\"https://mail.xn--brderli-o2a.ch/rc/\" target=\"_blank\">https://mail.xn--brderli-o2a.ch/rc/</a> EOF"),
TB 29             array('Start http://localhost/?foo End', 'Start <a href="http://localhost/?foo" target="_blank">http://localhost/?foo</a> End'),
22c67d 30             array('www.domain.tld', '<a href="http://www.domain.tld" target="_blank">www.domain.tld</a>'),
AM 31             array('WWW.DOMAIN.TLD', '<a href="http://WWW.DOMAIN.TLD" target="_blank">WWW.DOMAIN.TLD</a>'),
0931a9 32             array('[http://link.com]', '[<a href="http://link.com" target="_blank">http://link.com</a>]'),
AM 33             array('http://link.com?a[]=1', '<a href="http://link.com?a[]=1" target="_blank">http://link.com?a[]=1</a>'),
34             array('http://link.com?a[]', '<a href="http://link.com?a[]" target="_blank">http://link.com?a[]</a>'),
35             array('(http://link.com)', '(<a href="http://link.com" target="_blank">http://link.com</a>)'),
36             array('http://link.com?a(b)c', '<a href="http://link.com?a(b)c" target="_blank">http://link.com?a(b)c</a>'),
37             array('http://link.com?(link)', '<a href="http://link.com?(link)" target="_blank">http://link.com?(link)</a>'),
16915e 38             array('http://<test>', 'http://<test>'),
AM 39             array('http://', 'http://'),
22c67d 40         );
AM 41     }
42
43     /**
44      * @dataProvider data_replace
45      */
46     function test_replace($input, $output)
47     {
48         $replacer = new rcube_string_replacer;
49         $result = $replacer->replace($input);
50         $result = $replacer->resolve($result);
51
52         $this->assertEquals($output, $result);
53     }
5f8ada 54 }