diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8d8a5229..a2ff65c9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/tests/integration/Repository/RichTextFieldTypeIntegrationTest.php b/tests/integration/Repository/RichTextFieldTypeIntegrationTest.php index ebd91582..ee120e59 100644 --- a/tests/integration/Repository/RichTextFieldTypeIntegrationTest.php +++ b/tests/integration/Repository/RichTextFieldTypeIntegrationTest.php @@ -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; @@ -637,6 +639,8 @@ 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 @@ -644,7 +648,8 @@ public function testConvertRemoteObjectIdToObjectId($test, $expected): void */ 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(); @@ -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( @@ -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; } /** @@ -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(); @@ -941,7 +972,7 @@ public function testInternalLinkValidatorReturnsErrorOnMissingRelationInUpdatedF $repository = $this->getRepository(); $contentService = $repository->getContentService(); - list($deletedLocation, $brokenContent) = $this->prepareInternalLinkValidatorBrokenLinksTestCase( + [$deletedLocation, $brokenContent] = $this->prepareInternalLinkValidatorBrokenLinksTestCase( $repository ); @@ -1000,8 +1031,8 @@ private function createXmlDocumentWithExternalLink(array $urls): DOMDocument
$links