Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3' into temp_2.3_to_4.5
Browse files Browse the repository at this point in the history
# Conflicts:
#	phpstan-baseline.neon
#	tests/integration/Repository/RichTextFieldTypeIntegrationTest.php
  • Loading branch information
mateuszdebinski committed Sep 20, 2023
2 parents 397ff27 + 938d2b3 commit b07863b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
7 changes: 5 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1407,9 +1407,12 @@ parameters:

-
message: "#^Cannot access property \\$id on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 2
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php
-
message: "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#"
count: 1
path: tests/integration/Repository/RichTextFieldTypeIntegrationTest.php

-
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 1
Expand Down
53 changes: 42 additions & 11 deletions tests/integration/Repository/RichTextFieldTypeIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Core\Base\Exceptions\NotFoundException;
use Ibexa\Core\Persistence\Legacy\URL\Gateway\DoctrineDatabase;
use Ibexa\Core\Repository\Values\Content\Relation;
use Ibexa\FieldTypeRichText\FieldType\RichText\Value as RichTextValue;
use Ibexa\Tests\Integration\Core\Repository\FieldType\RelationSearchBaseIntegrationTestTrait;
Expand Down Expand Up @@ -637,14 +639,17 @@ public function testConvertRemoteObjectIdToObjectId($test, $expected): void
}

/**
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
* @throws \ErrorException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ForbiddenException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
public function testExternalLinkStoringAfterUpdate(): void
{
$xmlDocument = $this->createXmlDocumentWithExternalLink(['https://ibexa.co/', 'https://support.ibexa.co/']);
$testLink = 'https://support.ibexa.co/';
$xmlDocument = $this->createXmlDocumentWithExternalLink(['https://ibexa.co/', $testLink]);
$repository = $this->getRepository();
$contentService = $repository->getContentService();

Expand All @@ -664,12 +669,8 @@ public function testExternalLinkStoringAfterUpdate(): void
$content = $contentService->publishVersion(
$content->versionInfo
);
$urlIds = $this->getUrlIdsForContentObjectAttributeIdAndVersionNo(
$content->getField('description')->id,
$content->contentInfo->currentVersionNo
);

$xmlDocument = $this->createXmlDocumentWithExternalLink(['https://support.ibexa.co/']);
$xmlDocument = $this->createXmlDocumentWithExternalLink([$testLink]);
$contentUpdateStruct = $contentService->newContentUpdateStruct();
$contentUpdateStruct->setField('description', $xmlDocument, 'eng-GB');
$contentDraft = $contentService->updateContent(
Expand All @@ -682,7 +683,37 @@ public function testExternalLinkStoringAfterUpdate(): void
$content->contentInfo->currentVersionNo
);

$this->assertNotContains(reset($urlIds), $urlIdsAfterUpdate);
$urlId = $this->getUrlIdForLink($testLink);

self::assertContains($urlId, $urlIdsAfterUpdate);
}

/**
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
* @throws \ErrorException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
private function getUrlIdForLink(string $link): int
{
$connection = $this->getRawDatabaseConnection();
$query = $connection->createQueryBuilder();
$query
->select(
$connection->quoteIdentifier('id')
)
->from(DoctrineDatabase::URL_TABLE)
->where('url = :url')
->setParameter(':url', $link, ParameterType::STRING)
;

$id = $query->execute()->fetchOne();

if ($id === false) {
throw new NotFoundException('ezurl', $link);
}

return (int)$id;
}

/**
Expand Down Expand Up @@ -913,7 +944,7 @@ public function testInternalLinkValidatorIgnoresMissingRelationOnNotUpdatedField
$repository = $this->getRepository();
$contentService = $repository->getContentService();

list(, $contentB) = $this->prepareInternalLinkValidatorBrokenLinksTestCase($repository);
[, $contentB] = $this->prepareInternalLinkValidatorBrokenLinksTestCase($repository);

// update field w/o erroneous link to trigger validation
$contentUpdateStruct = $contentService->newContentUpdateStruct();
Expand Down Expand Up @@ -941,7 +972,7 @@ public function testInternalLinkValidatorReturnsErrorOnMissingRelationInUpdatedF
$repository = $this->getRepository();
$contentService = $repository->getContentService();

list($deletedLocation, $brokenContent) = $this->prepareInternalLinkValidatorBrokenLinksTestCase(
[$deletedLocation, $brokenContent] = $this->prepareInternalLinkValidatorBrokenLinksTestCase(
$repository
);

Expand Down Expand Up @@ -1000,8 +1031,8 @@ private function createXmlDocumentWithExternalLink(array $urls): DOMDocument
<section
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml"
xmlns:ezcustom="http://ibexa.co/xmlns/dxp/docbook/custom"
xmlns:ezxhtml="http://ibexa.co/xmlns/dxp/docbook/xhtml"
xmlns:ezcustom="http://ibexa.co/xmlns/dxp/docbook/custom"
version="5.0-variant ezpublish-1.0">
<para>
$links
Expand Down

0 comments on commit b07863b

Please sign in to comment.