Greg Aker | 2c4b366 | 2011-08-21 16:28:06 -0500 | [diff] [blame] | 1 | <?php |
| 2 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 3 | class Url_helper_test extends CI_TestCase { |
Greg Aker | 2c4b366 | 2011-08-21 16:28:06 -0500 | [diff] [blame] | 4 | |
Taufan Aditya | e1dc9ea | 2012-03-28 16:49:49 +0700 | [diff] [blame] | 5 | public function set_up() |
| 6 | { |
| 7 | $this->helper('url'); |
| 8 | } |
| 9 | |
Greg Aker | 2c4b366 | 2011-08-21 16:28:06 -0500 | [diff] [blame] | 10 | public function test_url_title() |
| 11 | { |
| 12 | $words = array( |
| 13 | 'foo bar /' => 'foo-bar', |
| 14 | '\ testing 12' => 'testing-12' |
| 15 | ); |
Eric Barnes | 9407614 | 2011-11-27 00:59:07 -0500 | [diff] [blame] | 16 | |
Greg Aker | 2c4b366 | 2011-08-21 16:28:06 -0500 | [diff] [blame] | 17 | foreach ($words as $in => $out) |
| 18 | { |
| 19 | $this->assertEquals($out, url_title($in, 'dash', TRUE)); |
Eric Barnes | 9407614 | 2011-11-27 00:59:07 -0500 | [diff] [blame] | 20 | } |
Greg Aker | 2c4b366 | 2011-08-21 16:28:06 -0500 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // -------------------------------------------------------------------- |
| 24 | |
Eric Barnes | 9407614 | 2011-11-27 00:59:07 -0500 | [diff] [blame] | 25 | public function test_url_title_extra_dashes() |
| 26 | { |
| 27 | $words = array( |
| 28 | '_foo bar_' => 'foo_bar', |
| 29 | '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS' |
| 30 | ); |
| 31 | |
| 32 | foreach ($words as $in => $out) |
| 33 | { |
| 34 | $this->assertEquals($out, url_title($in, 'underscore')); |
| 35 | } |
| 36 | } |
Eric Barnes | 32b6780 | 2011-11-27 01:10:09 -0500 | [diff] [blame] | 37 | |
| 38 | // -------------------------------------------------------------------- |
| 39 | |
| 40 | public function test_prep_url() |
| 41 | { |
| 42 | $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com')); |
| 43 | $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com')); |
| 44 | } |
| 45 | |
| 46 | // -------------------------------------------------------------------- |
| 47 | |
| 48 | public function test_auto_link_url() |
| 49 | { |
| 50 | $strings = array( |
Andrey Andreev | 606fee0 | 2013-01-28 12:57:13 +0200 | [diff] [blame] | 51 | 'www.codeigniter.com test' => '<a href="http://www.codeigniter.com">www.codeigniter.com</a> test', |
Eric Barnes | 32b6780 | 2011-11-27 01:10:09 -0500 | [diff] [blame] | 52 | 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', |
Andrey Andreev | 606fee0 | 2013-01-28 12:57:13 +0200 | [diff] [blame] | 53 | '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>', |
| 54 | 'Download CodeIgniter at www.codeigniter.com. Period test.' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>. Period test.', |
| 55 | 'Download CodeIgniter at www.codeigniter.com, comma test' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>, comma test', |
Andrey Andreev | 6b08edf | 2017-09-29 12:04:38 +0300 | [diff] [blame] | 56 | 'This one: ://codeigniter.com must not break this one: http://codeigniter.com' => 'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>', |
| 57 | 'Trailing slash: https://codeigniter.com/ fubar' => 'Trailing slash: <a href="https://codeigniter.com/">https://codeigniter.com/</a> fubar' |
Eric Barnes | d90e1a0 | 2011-11-27 14:12:46 -0500 | [diff] [blame] | 58 | ); |
| 59 | |
| 60 | foreach ($strings as $in => $out) |
| 61 | { |
| 62 | $this->assertEquals($out, auto_link($in, 'url')); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // -------------------------------------------------------------------- |
| 67 | |
| 68 | public function test_pull_675() |
| 69 | { |
| 70 | $strings = array( |
Andrey Andreev | 606fee0 | 2013-01-28 12:57:13 +0200 | [diff] [blame] | 71 | '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>', |
Eric Barnes | 32b6780 | 2011-11-27 01:10:09 -0500 | [diff] [blame] | 72 | ); |
| 73 | |
| 74 | foreach ($strings as $in => $out) |
| 75 | { |
| 76 | $this->assertEquals($out, auto_link($in, 'url')); |
| 77 | } |
| 78 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 79 | |
Andrey Andreev | 8c9e510 | 2017-11-10 15:02:42 +0200 | [diff] [blame] | 80 | // -------------------------------------------------------------------- |
| 81 | |
| 82 | public function test_issue_5331() |
| 83 | { |
| 84 | $this->assertEquals( |
| 85 | 'this is some text that includes '.safe_mailto('www.email@domain.com').' which is causing an issue', |
| 86 | auto_link('this is some text that includes www.email@domain.com which is causing an issue') |
| 87 | ); |
| 88 | } |
Andrey Andreev | 6b08edf | 2017-09-29 12:04:38 +0300 | [diff] [blame] | 89 | } |