|
13 | 13 |
|
14 | 14 | namespace CodeIgniter\Filters; |
15 | 15 |
|
| 16 | +use CodeIgniter\Autoloader\FileLocator; |
16 | 17 | use CodeIgniter\Config\Services; |
17 | 18 | use CodeIgniter\Filters\Exceptions\FilterException; |
18 | 19 | use CodeIgniter\Filters\fixtures\GoogleCurious; |
@@ -488,6 +489,52 @@ public function testAllCustomFiltersAreDiscoveredInConstructor(): void |
488 | 489 | $this->assertContains('test-customfilter', array_keys($configFilters->aliases)); |
489 | 490 | } |
490 | 491 |
|
| 492 | + public function testDiscoveryDoesNotTokenizeTheDefaultFiltersConfigs(): void |
| 493 | + { |
| 494 | + service('superglobals')->setServer('REQUEST_METHOD', 'GET'); |
| 495 | + |
| 496 | + $locator = new class (service('autoloader')) extends FileLocator { |
| 497 | + /** |
| 498 | + * @var list<string> |
| 499 | + */ |
| 500 | + public array $tokenized = []; |
| 501 | + |
| 502 | + public function getClassname(string $file): string |
| 503 | + { |
| 504 | + $this->tokenized[] = $file; |
| 505 | + |
| 506 | + return parent::getClassname($file); |
| 507 | + } |
| 508 | + }; |
| 509 | + Services::injectMock('locator', $locator); |
| 510 | + |
| 511 | + $appConfig = APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Filters.php'; |
| 512 | + $systemConfig = SYSTEMPATH . 'Config' . DIRECTORY_SEPARATOR . 'Filters.php'; |
| 513 | + $testConfig = realpath(TESTPATH . '_support/Config/Filters.php'); |
| 514 | + |
| 515 | + // Discovery does find them all, so the checks below are not vacuous. |
| 516 | + $found = $locator->search('Config/Filters.php'); |
| 517 | + $this->assertContains($appConfig, $found); |
| 518 | + $this->assertContains($systemConfig, $found); |
| 519 | + $this->assertContains($testConfig, $found); |
| 520 | + |
| 521 | + $config = [ |
| 522 | + 'aliases' => [], |
| 523 | + 'globals' => [], |
| 524 | + ]; |
| 525 | + $filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config); |
| 526 | + $filters = $this->createFilters($filtersConfig); |
| 527 | + |
| 528 | + $this->assertNotContains($appConfig, $locator->tokenized); |
| 529 | + $this->assertNotContains($systemConfig, $locator->tokenized); |
| 530 | + |
| 531 | + // Any other file is still checked and included. |
| 532 | + $this->assertContains($testConfig, $locator->tokenized); |
| 533 | + |
| 534 | + $configFilters = $this->getPrivateProperty($filters, 'config'); |
| 535 | + $this->assertContains('test-customfilter', array_keys($configFilters->aliases)); |
| 536 | + } |
| 537 | + |
491 | 538 | public function testRunThrowsWithInvalidClassType(): void |
492 | 539 | { |
493 | 540 | service('superglobals')->setServer('REQUEST_METHOD', 'GET'); |
|
0 commit comments