-
Notifications
You must be signed in to change notification settings - Fork 2
feature/performance-optimisation #7
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
3 commits
Select commit
Hold shift + click to select a range
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
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
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
178 changes: 178 additions & 0 deletions
178
Tests/Functional/Domain/Repository/FindTagStringsTest.php
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,178 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Zeroseven\Pagebased\Tests\Functional\Domain\Repository; | ||
|
|
||
| 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; | ||
|
|
||
| /** | ||
| * Functional tests for AbstractObjectRepository::findTagStrings(). | ||
| * | ||
| * Verifies that findTagStrings(): | ||
| * - Returns raw tag strings for all visible, non-category pages | ||
| * - Filters results when a category UID is set on the demand | ||
| * - Returns an empty array when a category has no child pages | ||
| * - Produces identical results on a second call (cache-hit behaviour) | ||
| * | ||
| * Fixtures: Tests/Functional/Fixtures/Database/pages_many_objects.csv | ||
| * uid 400 → Category 1 (doktype=199), parent of objects 500-519 | ||
| * uid 401 → Category 2, parent of objects 520-539 | ||
| * uid 402 → Category 3, parent of objects 540-559 | ||
| * Last object in each category is hidden (uid 519, 539, 559) | ||
| * → 57 visible objects with non-empty pagebased_tags | ||
| */ | ||
| class FindTagStringsTest extends FunctionalTestCase | ||
| { | ||
| protected array $testExtensionsToLoad = [ | ||
| 'typo3conf/ext/pagebased', | ||
| 'typo3conf/ext/pagebased/Tests/Functional/Fixtures', | ||
| ]; | ||
|
|
||
| protected array $coreExtensionsToLoad = [ | ||
| 'core', | ||
| 'frontend', | ||
| ]; | ||
|
|
||
| private TestObjectRepository $repository; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->bootstrapTestRegistration(); | ||
| $this->importCSVDataSet(__DIR__ . '/../../Fixtures/Database/pages_many_objects.csv'); | ||
|
|
||
| $this->repository = $this->get(TestObjectRepository::class); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Return value correctness | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsReturnsArrayOfStrings(): void | ||
| { | ||
| $demand = $this->repository->initializeDemand(); | ||
| $result = $this->repository->findTagStrings($demand); | ||
|
|
||
| self::assertIsArray($result); | ||
| self::assertNotEmpty($result, 'Expected at least one tag string in fixture data'); | ||
|
|
||
| foreach ($result as $tagString) { | ||
| self::assertIsString($tagString, 'Each element must be a raw tag string'); | ||
| self::assertNotSame('', $tagString, 'Empty tag strings must be excluded by the query'); | ||
| } | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsReturnsExpectedCountForKnownDataset(): void | ||
| { | ||
| $demand = $this->repository->initializeDemand(); | ||
| $result = $this->repository->findTagStrings($demand); | ||
|
|
||
| // 3 categories × 20 objects = 60 total; last in each category is hidden → 57 visible | ||
| self::assertCount(57, $result, '57 visible objects with non-empty tags expected'); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Category filtering | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsWithCategoryFilterReturnsSubsetOfAllResults(): void | ||
| { | ||
| $allDemand = $this->repository->initializeDemand(); | ||
| $allResults = $this->repository->findTagStrings($allDemand); | ||
|
|
||
| $categoryDemand = $this->repository->initializeDemand()->setCategory(400); | ||
| $categoryResults = $this->repository->findTagStrings($categoryDemand); | ||
|
|
||
| self::assertNotEmpty($categoryResults, 'Category 400 must have objects with tags'); | ||
| self::assertLessThan( | ||
| count($allResults), | ||
| count($categoryResults), | ||
| 'Category-scoped result must be a strict subset of all results' | ||
| ); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsWithCategoryFilterReturnsOnlyObjectsUnderThatCategory(): void | ||
| { | ||
| // Category 400 has 20 objects (UIDs 500–519), last one is hidden → 19 visible | ||
| $demand = $this->repository->initializeDemand()->setCategory(400); | ||
| $result = $this->repository->findTagStrings($demand); | ||
|
|
||
| self::assertCount(19, $result, 'Category 400 must yield exactly 19 visible tag strings'); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsReturnsEmptyArrayForCategoryWithNoChildPages(): void | ||
| { | ||
| // UID 9999 does not exist in the fixture, so collectPagesBelow() returns []. | ||
| $demand = $this->repository->initializeDemand()->setCategory(9999); | ||
| $result = $this->repository->findTagStrings($demand); | ||
|
|
||
| self::assertSame([], $result, 'Non-existent category must yield an empty array'); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Cache-hit behaviour | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsReturnsSameResultOnConsecutiveCalls(): void | ||
| { | ||
| $demand = $this->repository->initializeDemand(); | ||
|
|
||
| $firstCall = $this->repository->findTagStrings($demand); | ||
| $secondCall = $this->repository->findTagStrings($demand); | ||
|
|
||
| self::assertSame( | ||
| $firstCall, | ||
| $secondCall, | ||
| 'Consecutive calls with identical demand must return the same result (cache hit)' | ||
| ); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function findTagStringsWithCategoryFilterReturnsSameResultOnConsecutiveCalls(): void | ||
| { | ||
| $demand = $this->repository->initializeDemand()->setCategory(401); | ||
|
|
||
| $firstCall = $this->repository->findTagStrings($demand); | ||
| $secondCall = $this->repository->findTagStrings($demand); | ||
|
|
||
| self::assertSame( | ||
| $firstCall, | ||
| $secondCall, | ||
| 'Consecutive category-filtered calls must return the same result (cache hit)' | ||
| ); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.