Skip to content

Commit

Permalink
WIP: Part VII (Tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed Dec 12, 2023
1 parent 5d0ca46 commit 02cbb10
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 212 deletions.
1 change: 1 addition & 0 deletions src/lib/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function extractContentFromRows(array $rows, array $nameRows, $prefix = '
$content->versionInfo->contentInfo = $contentInfo;
$content->fields = array_values($fields[$contentId][$versionId]);

/** @var string $languageCode */
foreach ($fieldDefinitions[$contentId][$versionId] as $languageCode => $versionFieldDefinitions) {
foreach ($versionFieldDefinitions as $fieldDefinition) {
$content->fields[] = $this->createEmptyField(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Persistence/Legacy/Content/StorageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function copyFieldData(VersionInfo $versionInfo, Field $field, Field $ori
public function getFieldData(VersionInfo $versionInfo, Field $field)
{
$storage = $this->storageRegistry->getStorage($field->type);
if ($storage->hasFieldData()) {
if ($storage->hasFieldData() && $field->id !== null) {
$storage->getFieldData($versionInfo, $field, $this->context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Ibexa\Core\Persistence\Legacy\Content\Type\Update\Handler;

use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Core\Persistence\Legacy\Content\Type\ContentUpdater;
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway;
use Ibexa\Core\Persistence\Legacy\Content\Type\Update\Handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Ibexa\Core\Persistence\Legacy\SharedGateway\DatabasePlatform;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
use Ibexa\Core\Base\Exceptions\DatabaseException;
use Ibexa\Core\Persistence\Legacy\SharedGateway\Gateway;

Expand All @@ -20,39 +18,19 @@ final class SqliteGateway implements Gateway
*/
private const FATAL_ERROR_CODE = 7;

/** @var \Doctrine\DBAL\Connection */
private $connection;

/** @var \Doctrine\DBAL\Platforms\AbstractPlatform */
private $databasePlatform;

/** @var int[] */
private $lastInsertedIds = [];

/**
* @throws \Doctrine\DBAL\DBALException
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
$this->databasePlatform = $connection->getDatabasePlatform();
}

public function getColumnNextIntegerValue(
string $tableName,
string $columnName,
string $sequenceName
): ?int {
$query = $this->connection->createQueryBuilder();
$query
->select($this->databasePlatform->getMaxExpression($columnName))
->from($tableName);

$lastId = (int)$query->execute()->fetch(FetchMode::COLUMN);
$lastId = $this->lastInsertedIds[$sequenceName] ?? 0;
$nextId = (int)hrtime(true);

$this->lastInsertedIds[$sequenceName] = $lastId + 1;

return $this->lastInsertedIds[$sequenceName];
// $lastId === $nextId shouldn't happen using high-resolution time, but better safe than sorry
return $this->lastInsertedIds[$sequenceName] = $lastId === $nextId ? $nextId + 1 : $nextId;
}

/**
Expand Down
60 changes: 0 additions & 60 deletions tests/integration/Core/Repository/ContentTypeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2085,66 +2085,6 @@ public function testRemoveFieldDefinitionRemovesFieldFromContentRemoved($data)
);
}

/**
* @covers \Ibexa\Contracts\Core\Repository\ContentTypeService::removeFieldDefinition()
*/
public function testRemoveFieldDefinitionRemovesOrphanedRelations(): void
{
$repository = $this->getRepository();

$contentTypeService = $repository->getContentTypeService();
$contentService = $repository->getContentService();

// Create ContentType
$contentTypeDraft = $this->createContentTypeDraft([$this->getRelationFieldDefinition()]);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
$publishedType = $contentTypeService->loadContentType($contentTypeDraft->id);

// Create Content with Relation
$contentDraft = $this->createContentDraft();
$publishedVersion = $contentService->publishVersion($contentDraft->versionInfo);

$newDraft = $contentService->createContentDraft($publishedVersion->contentInfo);
$updateStruct = $contentService->newContentUpdateStruct();
$updateStruct->setField('relation', 14, 'eng-US');
$contentDraft = $contentService->updateContent($newDraft->versionInfo, $updateStruct);
$publishedContent = $contentService->publishVersion($contentDraft->versionInfo);

// Remove field definition from ContentType
$contentTypeDraft = $contentTypeService->createContentTypeDraft($publishedType);
$relationField = $contentTypeDraft->getFieldDefinition('relation');
$contentTypeService->removeFieldDefinition($contentTypeDraft, $relationField);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);

// Load Content
$content = $contentService->loadContent($publishedContent->contentInfo->id);

$this->assertCount(0, $contentService->loadRelations($content->versionInfo));
}

private function getRelationFieldDefinition(): FieldDefinitionCreateStruct
{
$repository = $this->getRepository();

$contentTypeService = $repository->getContentTypeService();

$relationFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
'relation',
'ezobjectrelation'
);
$relationFieldCreate->names = ['eng-US' => 'Relation'];
$relationFieldCreate->descriptions = ['eng-US' => 'Relation to any Content'];
$relationFieldCreate->fieldGroup = 'blog-content';
$relationFieldCreate->position = 3;
$relationFieldCreate->isTranslatable = false;
$relationFieldCreate->isRequired = false;
$relationFieldCreate->isInfoCollector = false;
$relationFieldCreate->validatorConfiguration = [];
$relationFieldCreate->isSearchable = false;

return $relationFieldCreate;
}

/**
* Test for the addFieldDefinition() method.
*
Expand Down
82 changes: 0 additions & 82 deletions tests/integration/Core/Repository/ProofOfConceptTest.php

This file was deleted.

Loading

0 comments on commit 02cbb10

Please sign in to comment.