blob: 83a8c0ec2852226848f615d86634da7e4a6c9227 [file] [log] [blame]
Greg Aker2c4b3662011-08-21 16:28:06 -05001<?php
2
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07003class Url_helper_test extends CI_TestCase {
Greg Aker2c4b3662011-08-21 16:28:06 -05004
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07005 public function set_up()
6 {
7 $this->helper('url');
8 }
9
Greg Aker2c4b3662011-08-21 16:28:06 -050010 public function test_url_title()
11 {
12 $words = array(
13 'foo bar /' => 'foo-bar',
14 '\ testing 12' => 'testing-12'
15 );
Eric Barnes94076142011-11-27 00:59:07 -050016
Greg Aker2c4b3662011-08-21 16:28:06 -050017 foreach ($words as $in => $out)
18 {
19 $this->assertEquals($out, url_title($in, 'dash', TRUE));
Eric Barnes94076142011-11-27 00:59:07 -050020 }
Greg Aker2c4b3662011-08-21 16:28:06 -050021 }
22
23 // --------------------------------------------------------------------
24
Eric Barnes94076142011-11-27 00:59:07 -050025 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 Barnes32b67802011-11-27 01:10:09 -050037
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 Andreev606fee02013-01-28 12:57:13 +020051 'www.codeigniter.com test' => '<a href="http://www.codeigniter.com">www.codeigniter.com</a> test',
Eric Barnes32b67802011-11-27 01:10:09 -050052 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test',
Andrey Andreev606fee02013-01-28 12:57:13 +020053 '<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 Andreev6b08edf2017-09-29 12:04:38 +030056 '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 Barnesd90e1a02011-11-27 14:12:46 -050058 );
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 Andreev606fee02013-01-28 12:57:13 +020071 '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>',
Eric Barnes32b67802011-11-27 01:10:09 -050072 );
73
74 foreach ($strings as $in => $out)
75 {
76 $this->assertEquals($out, auto_link($in, 'url'));
77 }
78 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030079
Andrey Andreev8c9e5102017-11-10 15:02:42 +020080 // --------------------------------------------------------------------
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 Andreev6b08edf2017-09-29 12:04:38 +030089}