@@ -42,112 +42,149 @@ public function tearDown(): void
4242 }
4343
4444 //--------------------------------------------------------------------
45- // Test site_url
4645
47- public function testSiteURLBasics ()
48- {
49- $ request = Services::request ($ this ->config );
50- $ request ->uri = new URI ('http://example.com/ ' );
51-
52- Services::injectMock ('request ' , $ request );
53-
54- $ this ->assertEquals ('http://example.com/index.php ' , site_url ('' , null , $ this ->config ));
55- }
56-
57- public function testSiteURLHTTPS ()
58- {
59- $ _SERVER ['HTTPS ' ] = 'on ' ;
60-
61- $ request = Services::request ($ this ->config );
62- $ request ->uri = new URI ('http://example.com/ ' );
63-
64- Services::injectMock ('request ' , $ request );
65-
66- $ this ->assertEquals ('https://example.com/index.php ' , site_url ('' , null , $ this ->config ));
67- }
68-
69- public function testSiteURLNoTrailingSlash ()
70- {
71- $ this ->config ->baseURL = 'http://example.com ' ;
72- $ request = Services::request ($ this ->config );
73- $ request ->uri = new URI ('http://example.com/index.php ' );
74-
75- Services::injectMock ('request ' , $ request );
76-
77- $ this ->assertEquals ('http://example.com/index.php ' , site_url ('' , null , $ this ->config ));
78- }
79-
80- public function testSiteURLNoIndex ()
81- {
82- $ this ->config ->indexPage = '' ;
83- $ request = Services::request ($ this ->config );
84- $ request ->uri = new URI ('http://example.com/ ' );
85-
86- Services::injectMock ('request ' , $ request );
87-
88- $ this ->assertEquals ('http://example.com/ ' , site_url ('' , null , $ this ->config ));
89- }
90-
91- public function testSiteURLDifferentIndex ()
92- {
93- $ this ->config ->indexPage = 'banana.php ' ;
94- $ request = Services::request ($ this ->config );
95- $ request ->uri = new URI ('http://example.com/ ' );
96-
97- Services::injectMock ('request ' , $ request );
98-
99- $ this ->assertEquals ('http://example.com/banana.php ' , site_url ('' , null , $ this ->config ));
100- }
101-
102- public function testSiteURLNoIndexButPath ()
46+ /**
47+ * @dataProvider siteUrlProvider
48+ */
49+ public function testSiteUrl ($ baseURL , $ indexPage , $ param , $ protocol , $ expected )
10350 {
104- $ this ->config ->indexPage = '' ;
105- $ request = Services::request ($ this ->config );
106- $ request ->uri = new URI ('http://example.com/ ' );
107-
108- Services::injectMock ('request ' , $ request );
51+ // Set the config
52+ $ this ->config ->baseURL = $ baseURL ;
53+ $ this ->config ->indexPage = $ indexPage ;
10954
110- $ this ->assertEquals ('http://example.com/abc ' , site_url ('abc ' , null , $ this ->config ));
111- }
112-
113- public function testSiteURLAttachesPath ()
114- {
55+ // Mock the Request
11556 $ request = Services::request ($ this ->config );
11657 $ request ->uri = new URI ('http://example.com/ ' );
117-
11858 Services::injectMock ('request ' , $ request );
11959
120- $ this ->assertEquals (' http://example.com/index.php/foo ' , site_url (' foo ' , null , $ this ->config ));
60+ $ this ->assertEquals ($ expected , site_url ($ param , $ protocol , $ this ->config ));
12161 }
12262
123- public function testSiteURLAttachesScheme ()
63+ public function siteUrlProvider ()
12464 {
125- $ request = Services::request ($ this ->config );
126- $ request ->uri = new URI ('http://example.com/ ' );
127-
128- Services::injectMock ('request ' , $ request );
129-
130- $ this ->assertEquals ('ftp://example.com/index.php/foo ' , site_url ('foo ' , 'ftp ' , $ this ->config ));
65+ // baseURL, indexPage, param, protocol, expected
66+ return [
67+ [
68+ 'http://example.com/ ' ,
69+ 'index.php ' ,
70+ '' ,
71+ null ,
72+ 'http://example.com/index.php ' ,
73+ ],
74+ [
75+ 'http://example.com ' ,
76+ 'index.php ' ,
77+ '' ,
78+ null ,
79+ 'http://example.com/index.php ' ,
80+ ],
81+ [
82+ 'http://example.com/ ' ,
83+ '' ,
84+ '' ,
85+ null ,
86+ 'http://example.com/ ' ,
87+ ],
88+ [
89+ 'http://example.com/ ' ,
90+ 'banana.php ' ,
91+ '' ,
92+ null ,
93+ 'http://example.com/banana.php ' ,
94+ ],
95+ [
96+ 'http://example.com/ ' ,
97+ '' ,
98+ 'abc ' ,
99+ null ,
100+ 'http://example.com/abc ' ,
101+ ],
102+ [
103+ 'http://example.com/public/ ' ,
104+ 'index.php ' ,
105+ '' ,
106+ null ,
107+ 'http://example.com/public/index.php ' ,
108+ ],
109+ [
110+ 'http://example.com/public/ ' ,
111+ '' ,
112+ '' ,
113+ null ,
114+ 'http://example.com/public/ ' ,
115+ ],
116+ [
117+ 'http://example.com/public ' ,
118+ '' ,
119+ '' ,
120+ null ,
121+ 'http://example.com/public/ ' ,
122+ ],
123+ [
124+ 'http://example.com/public ' ,
125+ 'index.php ' ,
126+ '/ ' ,
127+ null ,
128+ 'http://example.com/public/index.php/ ' ,
129+ ],
130+ [
131+ 'http://example.com/public/ ' ,
132+ 'index.php ' ,
133+ '/ ' ,
134+ null ,
135+ 'http://example.com/public/index.php/ ' ,
136+ ],
137+ [
138+ 'http://example.com/ ' ,
139+ 'index.php ' ,
140+ 'foo ' ,
141+ null ,
142+ 'http://example.com/index.php/foo ' ,
143+ ],
144+ [
145+ 'http://example.com/public ' ,
146+ 'index.php ' ,
147+ 'foo ' ,
148+ null ,
149+ 'http://example.com/public/index.php/foo ' ,
150+ ],
151+ [
152+ 'http://example.com/ ' ,
153+ 'index.php ' ,
154+ 'foo ' ,
155+ 'ftp ' ,
156+ 'ftp://example.com/index.php/foo ' ,
157+ ],
158+ [
159+ 'http://example.com/ ' ,
160+ 'index.php ' ,
161+ 'news/local/123 ' ,
162+ null ,
163+ 'http://example.com/index.php/news/local/123 ' ,
164+ ],
165+ [
166+ 'http://example.com/ ' ,
167+ 'index.php ' ,
168+ [
169+ 'news ' ,
170+ 'local ' ,
171+ '123 ' ,
172+ ], null ,
173+ 'http://example.com/index.php/news/local/123 ' ,
174+ ],
175+ ];
131176 }
132177
133- public function testSiteURLExample ()
178+ public function testSiteURLHTTPS ()
134179 {
135- $ request = Services::request ($ this ->config );
136- $ request ->uri = new URI ('http://example.com/ ' );
137-
138- Services::injectMock ('request ' , $ request );
139-
140- $ this ->assertEquals ('http://example.com/index.php/news/local/123 ' , site_url ('news/local/123 ' , null , $ this ->config ));
141- }
180+ $ _SERVER ['HTTPS ' ] = 'on ' ;
142181
143- public function testSiteURLSegments ()
144- {
145182 $ request = Services::request ($ this ->config );
146183 $ request ->uri = new URI ('http://example.com/ ' );
147184
148185 Services::injectMock ('request ' , $ request );
149186
150- $ this ->assertEquals ('http ://example.com/index.php/news/local/123 ' , site_url ([ ' news ' , ' local ' , ' 123 ' ] , null , $ this ->config ));
187+ $ this ->assertEquals ('https ://example.com/index.php ' , site_url ('' , null , $ this ->config ));
151188 }
152189
153190 /**
0 commit comments