Skip to content

Commit 89af2c8

Browse files
committed
Refactored LegacyContentFilteringTest to use RepositoryTestCase and improve folder creation logic
1 parent 8c8e690 commit 89af2c8

File tree

4 files changed

+67
-110
lines changed

4 files changed

+67
-110
lines changed

tests/integration/Core/Repository/Filtering/ContentFilteringTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ public function testLocationSortClausesStayDeterministicWithComplexCriteria(): v
180180
$locationService->newLocationCreateStruct(2)
181181
);
182182

183-
$referenceLocation = $this->loadMainLocation($locationService, $referenceContent);
184-
$middleLocation = $this->loadMainLocation($locationService, $middleContent);
185183
$mainLocation = $this->loadMainLocation($locationService, $contentWithAdditionalLocation);
186184
$nonMainLocations = [];
187185
foreach ($locationService->loadLocations($contentWithAdditionalLocation->contentInfo) as $location) {

tests/integration/Core/Repository/Filtering/LegacyContentFilteringTest.php

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,34 @@
99
namespace Ibexa\Tests\Integration\Core\Repository\Filtering;
1010

1111
use function array_map;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1314
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
1415
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter;
15-
use Ibexa\Contracts\Core\Test\Repository\SetupFactory;
16-
use Ibexa\Tests\Core\Repository\Filtering\TestContentProvider;
17-
use Ibexa\Tests\Integration\Core\Repository\BaseTest;
1816
use Ibexa\Tests\Integration\Core\Repository\Filtering\Fixtures\LegacyLocationSortClause;
17+
use Ibexa\Tests\Integration\Core\RepositoryTestCase;
1918
use function iterator_to_array;
2019

2120
/**
2221
* Integration BC check for legacy location sort clauses wired through the container.
2322
*
2423
* @group repository
2524
*/
26-
final class LegacyContentFilteringTest extends BaseTest
25+
final class LegacyContentFilteringTest extends RepositoryTestCase
2726
{
28-
private TestContentProvider $contentProvider;
29-
30-
protected function setUp(): void
31-
{
32-
parent::setUp();
33-
$this->contentProvider = new TestContentProvider($this->getRepository(), $this);
34-
}
35-
3627
public function testLegacyLocationSortClause(): void
3728
{
38-
$parentFolder = $this->contentProvider->createSharedContentStructure();
29+
$parentFolder = $this->createFolderWithRemoteId('legacy-parent', 'Legacy Parent');
30+
$folder1 = $this->createFolderWithRemoteId(
31+
'legacy-folder-1',
32+
'Legacy Folder 1',
33+
(int)$parentFolder->getContentInfo()->getMainLocationId()
34+
);
35+
$folder2 = $this->createFolderWithRemoteId(
36+
'legacy-folder-2',
37+
'Legacy Folder 2',
38+
(int)$parentFolder->getContentInfo()->getMainLocationId()
39+
);
3940

4041
$filter = (new Filter())
4142
->withCriterion(
@@ -46,7 +47,8 @@ public function testLegacyLocationSortClause(): void
4647
)
4748
->withSortClause(new LegacyLocationSortClause(Query::SORT_ASC));
4849

49-
$list = $this->getRepository()->getContentService()->find($filter, []);
50+
$contentService = self::getContentService();
51+
$list = $contentService->find($filter, []);
5052

5153
self::assertCount(2, $list);
5254
$remoteIds = array_map(
@@ -55,15 +57,40 @@ public function testLegacyLocationSortClause(): void
5557
);
5658
self::assertSame(
5759
[
58-
TestContentProvider::CONTENT_REMOTE_IDS['folder1'],
59-
TestContentProvider::CONTENT_REMOTE_IDS['folder2'],
60+
$folder1->getContentInfo()->remoteId,
61+
$folder2->getContentInfo()->remoteId,
6062
],
6163
$remoteIds
6264
);
6365
}
6466

65-
protected function getSetupFactory(): SetupFactory
67+
protected static function getKernelClass(): string
6668
{
67-
return new LegacyFilteringSetupFactory();
69+
return LegacyTestKernel::class;
70+
}
71+
72+
private function createFolderWithRemoteId(
73+
string $remoteId,
74+
string $name,
75+
int $parentLocationId = self::CONTENT_TREE_ROOT_ID
76+
): Content {
77+
$contentService = self::getContentService();
78+
$contentTypeService = self::getContentTypeService();
79+
$locationService = self::getLocationService();
80+
81+
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType $folderType */
82+
$folderType = $contentTypeService->loadContentTypeByIdentifier('folder');
83+
$createStruct = $contentService->newContentCreateStruct($folderType, 'eng-GB');
84+
$createStruct->setField('name', $name, 'eng-GB');
85+
$createStruct->remoteId = $remoteId;
86+
87+
$locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
88+
89+
$draft = $contentService->createContent(
90+
$createStruct,
91+
[$locationCreateStruct]
92+
);
93+
94+
return $contentService->publishVersion($draft->versionInfo);
6895
}
6996
}

tests/integration/Core/Repository/Filtering/LegacyFilteringSetupFactory.php

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Integration\Core\Repository\Filtering;
10+
11+
use Ibexa\Contracts\Core\Test\IbexaTestKernel;
12+
use Symfony\Component\Config\Loader\LoaderInterface;
13+
14+
final class LegacyTestKernel extends IbexaTestKernel
15+
{
16+
protected function loadServices(LoaderInterface $loader): void
17+
{
18+
parent::loadServices($loader);
19+
20+
$loader->load(__DIR__ . '/Resources/config/services/legacy_sort_clause.yaml');
21+
}
22+
}

0 commit comments

Comments
 (0)