|
1 | 1 | <?php |
2 | | - |
3 | 2 | namespace CodeIgniter\Helpers; |
4 | 3 |
|
5 | 4 | use Config\App; |
@@ -1085,4 +1084,79 @@ public function testUrlTitleExtraDashes() |
1085 | 1084 | } |
1086 | 1085 | } |
1087 | 1086 |
|
| 1087 | + //-------------------------------------------------------------------- |
| 1088 | + // Exploratory testing, investigating https://github.com/codeigniter4/CodeIgniter4/issues/2016 |
| 1089 | + |
| 1090 | + public function testBasedNoIndex() |
| 1091 | + { |
| 1092 | + $_SERVER['HTTP_HOST'] = 'example.com'; |
| 1093 | + $_SERVER['REQUEST_URI'] = '/ci/v4/x/y'; |
| 1094 | + |
| 1095 | + $config = new App(); |
| 1096 | + $config->baseURL = 'http://example.com/ci/v4/'; |
| 1097 | + $config->indexPage = 'index.php'; |
| 1098 | + $request = Services::request($config); |
| 1099 | + $request->uri = new URI('http://example.com/ci/v4/x/y'); |
| 1100 | + |
| 1101 | + Services::injectMock('request', $request); |
| 1102 | + |
| 1103 | + $this->assertEquals('http://example.com/ci/v4/index.php/controller/method', site_url('controller/method', null, $config)); |
| 1104 | + $this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config)); |
| 1105 | + $this->assertEquals(base_url(uri_string()), current_url()); |
| 1106 | + } |
| 1107 | + |
| 1108 | + public function testBasedWithIndex() |
| 1109 | + { |
| 1110 | + $_SERVER['HTTP_HOST'] = 'example.com'; |
| 1111 | + $_SERVER['REQUEST_URI'] = '/ci/v4/index.php/x/y'; |
| 1112 | + |
| 1113 | + $config = new App(); |
| 1114 | + $config->baseURL = 'http://example.com/ci/v4/'; |
| 1115 | + $config->indexPage = 'index.php'; |
| 1116 | + $request = Services::request($config); |
| 1117 | + $request->uri = new URI('http://example.com/ci/v4/index.php/x/y'); |
| 1118 | + |
| 1119 | + Services::injectMock('request', $request); |
| 1120 | + |
| 1121 | + $this->assertEquals('http://example.com/ci/v4/index.php/controller/method', site_url('controller/method', null, $config)); |
| 1122 | + $this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config)); |
| 1123 | + $this->assertEquals(base_url(uri_string()), current_url()); |
| 1124 | + } |
| 1125 | + |
| 1126 | + public function testBasedWithoutIndex() |
| 1127 | + { |
| 1128 | + $_SERVER['HTTP_HOST'] = 'example.com'; |
| 1129 | + $_SERVER['REQUEST_URI'] = '/ci/v4/x/y'; |
| 1130 | + |
| 1131 | + $config = new App(); |
| 1132 | + $config->baseURL = 'http://example.com/ci/v4/'; |
| 1133 | + $config->indexPage = ''; |
| 1134 | + $request = Services::request($config); |
| 1135 | + $request->uri = new URI('http://example.com/ci/v4/x/y'); |
| 1136 | + |
| 1137 | + Services::injectMock('request', $request); |
| 1138 | + |
| 1139 | + $this->assertEquals('http://example.com/ci/v4/controller/method', site_url('controller/method', null, $config)); |
| 1140 | + $this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config)); |
| 1141 | + $this->assertEquals(base_url(uri_string()), current_url()); |
| 1142 | + } |
| 1143 | + |
| 1144 | + public function testBasedWithOtherIndex() |
| 1145 | + { |
| 1146 | + $_SERVER['HTTP_HOST'] = 'example.com'; |
| 1147 | + $_SERVER['REQUEST_URI'] = '/ci/v4/x/y'; |
| 1148 | + |
| 1149 | + $config = new App(); |
| 1150 | + $config->baseURL = 'http://example.com/ci/v4/'; |
| 1151 | + $config->indexPage = 'fc.php'; |
| 1152 | + $request = Services::request($config); |
| 1153 | + $request->uri = new URI('http://example.com/ci/v4/x/y'); |
| 1154 | + |
| 1155 | + Services::injectMock('request', $request); |
| 1156 | + |
| 1157 | + $this->assertEquals('http://example.com/ci/v4/fc.php/controller/method', site_url('controller/method', null, $config)); |
| 1158 | + $this->assertEquals('http://example.com/ci/v4/controller/method', base_url('controller/method', null, $config)); |
| 1159 | + $this->assertEquals(base_url(uri_string()), current_url()); |
| 1160 | + } |
| 1161 | + |
1088 | 1162 | } |
0 commit comments