Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/bundle/Core/Resources/config/storage/legacy/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,14 @@ tables:
ibexa_content_version:
indexes:
ibexa_content_version_status: { fields: [status] }
ibexa_content_version_idx_ver: { fields: [contentobject_id, version] }
ibexa_content_version_idx_status: { fields: [contentobject_id, status] }
ibexa_content_version_creator_id: { fields: [creator_id] }
uniqueConstraints:
ibexa_content_version_coid_version_unique: { fields: [contentobject_id, version] }
id:
id: { type: integer, nullable: false, options: { autoincrement: true } }
fields:
contentobject_id: { type: integer, nullable: true }
contentobject_id: { type: integer, nullable: false }
created: { type: integer, nullable: false, options: { default: '0' } }
creator_id: { type: integer, nullable: false, options: { default: '0' } }
initial_language_id: { type: bigint, nullable: false, options: { default: '0' } }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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\Persistence\Legacy\Content\Gateway;

use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Test\IbexaKernelTestCase;
use Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase;

/**
* @internal
*
* @covers \Ibexa\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase
*/
final class DoctrineDatabaseTest extends IbexaKernelTestCase
{
private const int CONTENT_ID = 2342;

private const int VERSION_NO = 1;

private DoctrineDatabase $gateway;

protected function setUp(): void
{
parent::setUp();

self::loadSchema();
self::loadFixtures();

self::setAdministratorUser();

$gateway = self::getContainer()->get(DoctrineDatabase::class . '.inner');
self::assertInstanceOf(DoctrineDatabase::class, $gateway);

$this->gateway = $gateway;
}

public function testInsertVersionThrowsOnDuplicateContentIdAndVersionNo(): void
{
$versionInfo = $this->getVersionInfoFixture();

self::assertGreaterThan(0, $this->gateway->insertVersion($versionInfo, []));

$this->expectException(UniqueConstraintViolationException::class);
$this->gateway->insertVersion($versionInfo, []);
}

private function getVersionInfoFixture(): VersionInfo
{
$versionInfo = new VersionInfo();

$versionInfo->id = null;
$versionInfo->versionNo = self::VERSION_NO;
$versionInfo->creatorId = 14;
$versionInfo->status = VersionInfo::STATUS_DRAFT;
$versionInfo->creationDate = 1312278322;
$versionInfo->modificationDate = 1312278323;
$versionInfo->initialLanguageCode = 'eng-GB';
$versionInfo->contentInfo = new ContentInfo(
[
'id' => self::CONTENT_ID,
'alwaysAvailable' => true,
]
);

return $versionInfo;
}
}