-
Notifications
You must be signed in to change notification settings - Fork 2
[FEATURE] Add nonglobal tag scoping via TYPO3 feature flag #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ee2358
Update TagUtility.php to filter out global tags that are not within t…
9f43354
Update TagUtility.php
96077b4
Merge branch 'feature/nonglobal-tags': Filter tags by category from r…
teneris 19e5bfd
[FEATURE] Add nonglobal tag scoping via feature flag
teneris 6d91db1
[BUGFIX] Address PR #8 review comments
teneris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| pages,,,,,,,,,,,,,,, | ||
| ,uid,pid,title,doktype,sorting,deleted,hidden,nav_hide,sys_language_uid,l10n_parent,_pagebased_registration,_pagebased_site,_pagebased_child_object,pagebased_tags | ||
| ,1,0,Site Root,1,256,0,0,0,0,0,,1,0, | ||
| ,10,1,Category A,199,128,0,0,0,0,0,,1,0, | ||
| ,20,10,Object A1,1,128,0,0,0,0,0,test_news,1,0,"php,typo3" | ||
| ,21,10,Object A2,1,256,0,0,0,0,0,test_news,1,0,"php,symfony" | ||
| ,30,1,Category B,199,256,0,0,0,0,0,,1,0, | ||
| ,31,30,Object B1,1,128,0,0,0,0,0,test_news,1,0,"javascript,typo3" | ||
| ,40,1,Standalone Page,1,384,0,0,0,0,0,,1,0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Zeroseven\Pagebased\Tests\Functional\Utility; | ||
|
|
||
| use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
| use Zeroseven\Pagebased\Registration\CategoryRegistration; | ||
| use Zeroseven\Pagebased\Registration\ObjectRegistration; | ||
| use Zeroseven\Pagebased\Registration\Registration; | ||
| use Zeroseven\Pagebased\Registration\RegistrationService; | ||
| use Zeroseven\Pagebased\Tests\Functional\Fixtures\Classes\TestCategory; | ||
| use Zeroseven\Pagebased\Tests\Functional\Fixtures\Classes\TestCategoryRepository; | ||
| use Zeroseven\Pagebased\Tests\Functional\Fixtures\Classes\TestObject; | ||
| use Zeroseven\Pagebased\Tests\Functional\Fixtures\Classes\TestObjectRepository; | ||
| use Zeroseven\Pagebased\Utility\RootLineUtility; | ||
| use Zeroseven\Pagebased\Utility\TagUtility; | ||
|
|
||
| /** | ||
| * Functional tests for TagUtility::getTags() with the pagebased.nonglobalTags feature flag. | ||
| * | ||
| * Fixture layout (pages_tags.csv): | ||
| * uid 1 → Site root (doktype=1) | ||
| * uid 10 → Category A (doktype=199) | ||
| * uid 20 → Object in Category A, tags: "php,typo3" | ||
| * uid 21 → Object in Category A, tags: "php,symfony" | ||
| * uid 30 → Category B (doktype=199) | ||
| * uid 31 → Object in Category B, tags: "javascript,typo3" | ||
| * uid 40 → Standalone page (doktype=1, no registered category in rootline) | ||
| * | ||
| * Feature flag OFF (default): tags are collected globally across all categories. | ||
| * Feature flag ON: | ||
| * - Category already set in demand → rootline detection is skipped. | ||
| * - No category in demand, category page found in rootline → demand is scoped automatically. | ||
| * - No category in demand, no category page in rootline → null returned. | ||
| */ | ||
| class TagUtilityTest extends FunctionalTestCase | ||
| { | ||
| protected array $testExtensionsToLoad = [ | ||
| 'typo3conf/ext/pagebased', | ||
| ]; | ||
|
|
||
| protected array $coreExtensionsToLoad = [ | ||
| 'core', | ||
| 'frontend', | ||
| ]; | ||
|
|
||
| private TestObjectRepository $repository; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->bootstrapTestRegistration(); | ||
| $this->importCSVDataSet(__DIR__ . '/../Fixtures/Database/pages_tags.csv'); | ||
|
|
||
| $this->repository = $this->get(TestObjectRepository::class); | ||
|
|
||
| // Ensure the feature flag is off by default for each test. | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = false; | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| // Clear the static RootLineUtility cache so page-context changes between | ||
| // tests do not bleed into one another. | ||
| // Note: setAccessible(true) is intentionally omitted – it is a no-op since PHP 8.1 | ||
| // and produces a deprecation notice on PHP 8.4. | ||
| $reflection = new \ReflectionProperty(RootLineUtility::class, 'cache'); | ||
| $reflection->setValue(null, []); | ||
|
|
||
| unset($_GET['id']); | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = false; | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
|
|
||
| private function bootstrapTestRegistration(): void | ||
| { | ||
| $objectRegistration = new ObjectRegistration('Test Object'); | ||
| $objectRegistration->setClassName(TestObject::class); | ||
| $objectRegistration->setRepositoryClass(TestObjectRepository::class); | ||
|
|
||
| $categoryRegistration = new CategoryRegistration('Test Category'); | ||
| $categoryRegistration->setClassName(TestCategory::class); | ||
| $categoryRegistration->setRepositoryClass(TestCategoryRepository::class); | ||
| $categoryRegistration->setDocumentType(199); | ||
|
|
||
| $registration = new Registration('test', 'test_news'); | ||
| $registration->setObject($objectRegistration); | ||
| $registration->setCategory($categoryRegistration); | ||
|
|
||
| RegistrationService::addRegistration($registration); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Feature flag OFF (default behaviour) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** @test */ | ||
| public function getTagsReturnsGlobalTagsWhenFeatureFlagIsOff(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = false; | ||
|
|
||
| $demand = $this->repository->initializeDemand(); | ||
| $tags = TagUtility::getTags($demand, $this->repository); | ||
|
|
||
| // All objects across all categories are included: php, typo3, symfony, javascript | ||
| self::assertNotNull($tags); | ||
| self::assertContains('php', $tags); | ||
| self::assertContains('typo3', $tags); | ||
| self::assertContains('symfony', $tags); | ||
| self::assertContains('javascript', $tags); | ||
| self::assertSame(['javascript', 'php', 'symfony', 'typo3'], $tags); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Feature flag ON – rootline detection active | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** @test */ | ||
| public function getTagsScopesTagsToCategoryFoundInRootlineWhenFlagIsOn(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = true; | ||
|
|
||
| // Simulate browsing object page 20 (child of Category A, uid=10) | ||
| $_GET['id'] = '20'; | ||
|
|
||
| $demand = $this->repository->initializeDemand(); | ||
| $tags = TagUtility::getTags($demand, $this->repository); | ||
|
|
||
| // Only objects in Category A (uid 20, 21): php, typo3, symfony | ||
| self::assertNotNull($tags); | ||
| self::assertSame(['php', 'symfony', 'typo3'], $tags); | ||
| self::assertNotContains('javascript', $tags); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function getTagsReturnsNullWhenFlagIsOnButNoCategoryPageInRootline(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = true; | ||
|
|
||
| // Simulate browsing a standalone page (uid=40) with no registered category ancestor | ||
| $_GET['id'] = '40'; | ||
|
|
||
| $demand = $this->repository->initializeDemand(); | ||
| $result = TagUtility::getTags($demand, $this->repository); | ||
|
|
||
| self::assertNull($result); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function getTagsSkipsRootlineDetectionWhenCategoryAlreadySetInDemand(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = true; | ||
|
|
||
| // Category B (uid=30) is set explicitly – rootline should not be consulted. | ||
| // $_GET['id'] points to a page outside any category to prove rootline is skipped. | ||
| $_GET['id'] = '40'; | ||
|
|
||
| $demand = $this->repository->initializeDemand(); | ||
| $demand->{'setCategory'}(30); | ||
|
|
||
| $tags = TagUtility::getTags($demand, $this->repository); | ||
|
|
||
| // Only objects in Category B (uid 31): javascript, typo3 | ||
| self::assertNotNull($tags); | ||
| self::assertSame(['javascript', 'typo3'], $tags); | ||
| self::assertNotContains('php', $tags); | ||
| self::assertNotContains('symfony', $tags); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function getTagsOnCategoryPageItselfResolvesCorrectlyWhenFlagIsOn(): void | ||
| { | ||
| $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['pagebased.nonglobalTags'] = true; | ||
|
|
||
| // Simulate browsing the Category A page itself (uid=10, doktype=199) | ||
| $_GET['id'] = '10'; | ||
|
|
||
| $demand = $this->repository->initializeDemand(); | ||
| $tags = TagUtility::getTags($demand, $this->repository); | ||
|
|
||
| // collectPagesAbove with includingStartingPoint=true includes uid=10 itself | ||
| self::assertNotNull($tags); | ||
| self::assertSame(['php', 'symfony', 'typo3'], $tags); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.