|
14 | 14 | namespace CodeIgniter; |
15 | 15 |
|
16 | 16 | use App\Controllers\Home; |
| 17 | +use CodeIgniter\Config\Factories; |
17 | 18 | use CodeIgniter\Config\Services; |
18 | 19 | use CodeIgniter\Debug\Timer; |
19 | 20 | use CodeIgniter\Exceptions\PageNotFoundException; |
|
43 | 44 | */ |
44 | 45 | #[BackupGlobals(true)] |
45 | 46 | #[Group('Others')] |
46 | | -#[RunTestsInSeparateProcesses] |
| 47 | +// #[RunTestsInSeparateProcesses] |
47 | 48 | final class CodeIgniterTest extends CIUnitTestCase |
48 | 49 | { |
49 | 50 | private CodeIgniter $codeigniter; |
@@ -1187,4 +1188,47 @@ public function testRouteAttributeCustomCacheKeyIntegration(): void |
1187 | 1188 | // Clear cache after test |
1188 | 1189 | cache()->clean(); |
1189 | 1190 | } |
| 1191 | + |
| 1192 | + public function testRouteAttributesDisabledInConfig(): void |
| 1193 | + { |
| 1194 | + Services::superglobals()->setServer('REQUEST_URI', '/attribute/filtered'); |
| 1195 | + Services::superglobals()->setServer('SCRIPT_NAME', '/index.php'); |
| 1196 | + Services::superglobals()->setServer('REQUEST_METHOD', 'GET'); |
| 1197 | + |
| 1198 | + // Disable route attributes in config BEFORE creating CodeIgniter instance |
| 1199 | + $routing = config('routing'); |
| 1200 | + $routing->useControllerAttributes = false; |
| 1201 | + Factories::injectMock('config', 'routing', $routing); |
| 1202 | + |
| 1203 | + // Register the test filter (even though attributes are disabled, |
| 1204 | + // we need it registered to avoid FilterException) |
| 1205 | + $filterConfig = config('Filters'); |
| 1206 | + $filterConfig->aliases['testAttributeFilter'] = TestAttributeFilter::class; |
| 1207 | + service('filters', $filterConfig); |
| 1208 | + |
| 1209 | + $routes = service('routes'); |
| 1210 | + $routes->setAutoRoute(false); |
| 1211 | + |
| 1212 | + // We're testing that a route defined normally will work, |
| 1213 | + // but the attributes on the controller method won't be processed |
| 1214 | + $routes->get('attribute/filtered', '\Tests\Support\Router\Controllers\AttributeController::filtered'); |
| 1215 | + |
| 1216 | + $router = service('router', $routes, service('incomingrequest')); |
| 1217 | + Services::injectMock('router', $router); |
| 1218 | + |
| 1219 | + $config = new App(); |
| 1220 | + $codeigniter = new MockCodeIgniter($config); |
| 1221 | + |
| 1222 | + ob_start(); |
| 1223 | + $codeigniter->run($routes); |
| 1224 | + $output = ob_get_clean(); |
| 1225 | + |
| 1226 | + |
| 1227 | + // When useRouteAttributes is false, the filter attributes should NOT be processed |
| 1228 | + // So the filter should not have run |
| 1229 | + $this->assertStringNotContainsString('before_filter_ran', (string) $output); |
| 1230 | + $this->assertStringNotContainsString('after_filter_ran', (string) $output); |
| 1231 | + // But the controller method should still execute |
| 1232 | + $this->assertStringContainsString('Filtered', (string) $output); |
| 1233 | + } |
1190 | 1234 | } |
0 commit comments