-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\Core\Repository\ContentService; | ||
|
||
use Ibexa\Tests\Integration\Core\RepositoryTestCase; | ||
|
||
/** | ||
* @covers \eZ\Publish\API\Repository\ContentService | ||
*/ | ||
final class LoadVersionInfoTest extends RepositoryTestCase | ||
{ | ||
/** | ||
* @throws \eZ\Publish\API\Repository\Exceptions\Exception | ||
*/ | ||
public function testLoadVersionInfoListByContentInfo(): void | ||
{ | ||
$contentService = self::getContentService(); | ||
|
||
$folder1 = $this->createFolder(['eng-GB' => 'Folder1'], 2); | ||
$folder2 = $this->createFolder(['eng-GB' => 'Folder2'], 2); | ||
|
||
$versionInfoList = $contentService->loadVersionInfoListByContentInfo( | ||
[ | ||
$folder1->getVersionInfo()->getContentInfo(), | ||
$folder2->getVersionInfo()->getContentInfo(), | ||
] | ||
); | ||
|
||
self::assertCount(2, $versionInfoList); | ||
|
||
foreach ($versionInfoList as $versionInfo) { | ||
$loadedVersionInfo = $contentService->loadVersionInfo( | ||
$versionInfo->getContentInfo(), | ||
$versionInfo->versionNo | ||
); | ||
self::assertEquals($loadedVersionInfo, $versionInfo); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Integration\Core; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
use Ibexa\Contracts\Core\Test\IbexaKernelTestCase; | ||
use InvalidArgumentException; | ||
|
||
abstract class RepositoryTestCase extends IbexaKernelTestCase | ||
{ | ||
public const CONTENT_TREE_ROOT_ID = 2; | ||
|
||
private const CONTENT_TYPE_FOLDER_IDENTIFIER = 'folder'; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
self::loadSchema(); | ||
self::loadFixtures(); | ||
|
||
self::setAdministratorUser(); | ||
} | ||
|
||
/** | ||
* @param array<string, string> $names | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\Exception | ||
*/ | ||
public function createFolder(array $names, int $parentLocationId = self::CONTENT_TREE_ROOT_ID): Content | ||
Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (7.4)
Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (8.0)
Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (8.1)
|
||
{ | ||
$contentService = self::getContentService(); | ||
$draft = $this->createFolderDraft($names, $parentLocationId); | ||
|
||
return $contentService->publishVersion($draft->getVersionInfo()); | ||
} | ||
|
||
/** | ||
* @param array<string, string> $names | ||
* | ||
* @throws \eZ\Publish\API\Repository\Exceptions\Exception | ||
*/ | ||
public function createFolderDraft(array $names, int $parentLocationId = self::CONTENT_TREE_ROOT_ID): Content | ||
Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (7.4)
Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (8.0)
Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php GitHub Actions / Unit tests & SQLite integration tests (8.1)
|
||
{ | ||
if (empty($names)) { | ||
throw new InvalidArgumentException(__METHOD__ . ' requires $names to be not empty'); | ||
} | ||
|
||
$contentService = self::getContentService(); | ||
$contentTypeService = self::getContentTypeService(); | ||
$locationService = self::getLocationService(); | ||
|
||
$folderType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_FOLDER_IDENTIFIER); | ||
$mainLanguageCode = array_keys($names)[0]; | ||
$contentCreateStruct = $contentService->newContentCreateStruct($folderType, $mainLanguageCode); | ||
foreach ($names as $languageCode => $name) { | ||
$contentCreateStruct->setField('name', $name, $languageCode); | ||
} | ||
|
||
return $contentService->createContent( | ||
$contentCreateStruct, | ||
[ | ||
$locationService->newLocationCreateStruct($parentLocationId), | ||
] | ||
); | ||
} | ||
} |