From b4756baac9e169d5123c1eaa8c05a4d9b1fe705d Mon Sep 17 00:00:00 2001 From: matx132 Date: Tue, 19 Sep 2023 14:02:02 +0200 Subject: [PATCH 1/2] Corrected test for external link --- phpstan-baseline.neon | 7 ++- .../API/RichTextFieldTypeIntegrationTest.php | 46 +++++++++++++++---- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2c8f17f4..61341fa8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1662,9 +1662,12 @@ parameters: - message: "#^Cannot access property \\$id on eZ\\\\Publish\\\\API\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#" - count: 2 + count: 1 + path: tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php + - + message: "#^Cannot call method fetchOne\\(\\) on Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\Result\\|int\\|string\\.$#" + count: 1 path: tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php - - message: "#^Cannot access property \\$value on eZ\\\\Publish\\\\API\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#" count: 1 diff --git a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php index af6e087b..a0dcd0c5 100644 --- a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php +++ b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php @@ -16,6 +16,7 @@ use eZ\Publish\API\Repository\Tests\FieldType\RelationSearchBaseIntegrationTestTrait; use eZ\Publish\API\Repository\Tests\FieldType\SearchBaseIntegrationTest; use eZ\Publish\API\Repository\Values\Content\Location; +use eZ\Publish\Core\Base\Exceptions\NotFoundException; use EzSystems\EzPlatformRichText\eZ\FieldType\RichText\Value as RichTextValue; use eZ\Publish\API\Repository\Values\Content\Field; use DOMDocument; @@ -643,7 +644,8 @@ public function testConvertRemoteObjectIdToObjectId($test, $expected): void */ public function testExternalLinkStoringAfterUpdate(): void { - $xmlDocument = $this->createXmlDocumentWithExternalLink(['https://ez.no/', 'https://support.ez.no/']); + $testLink = 'https://support.ez.no/'; + $xmlDocument = $this->createXmlDocumentWithExternalLink(['https://ez.no/', $testLink]); $repository = $this->getRepository(); $contentService = $repository->getContentService(); @@ -663,12 +665,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.ez.no/']); + $xmlDocument = $this->createXmlDocumentWithExternalLink([$testLink]); $contentUpdateStruct = $contentService->newContentUpdateStruct(); $contentUpdateStruct->setField('description', $xmlDocument, 'eng-GB'); $contentDraft = $contentService->updateContent( @@ -681,7 +679,37 @@ public function testExternalLinkStoringAfterUpdate(): void $content->contentInfo->currentVersionNo ); - $this->assertNotContains(reset($urlIds), $urlIdsAfterUpdate); + $urlId = $this->getUrlIdForLink($testLink); + + $this->assertContains($urlId, $urlIdsAfterUpdate); + } + + /** + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \Doctrine\DBAL\Driver\Exception + * @throws \Doctrine\DBAL\Exception + * @throws \ErrorException + */ + private function getUrlIdForLink(string $link): int + { + $connection = $this->getRawDatabaseConnection(); + $query = $connection->createQueryBuilder(); + $query + ->select( + $connection->quoteIdentifier('id') + ) + ->from('ezurl') + ->where('url = :url') + ->setParameter(':url', $link, ParameterType::STRING) + ; + + $id = $query->execute()->fetchOne(); + + if ($id === false) { + throw new NotFoundException('ezurl', $link); + } + + return (int)$id; } /** @@ -911,7 +939,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(); @@ -939,7 +967,7 @@ public function testInternalLinkValidatorReturnsErrorOnMissingRelationInUpdatedF $repository = $this->getRepository(); $contentService = $repository->getContentService(); - list($deletedLocation, $brokenContent) = $this->prepareInternalLinkValidatorBrokenLinksTestCase( + [$deletedLocation, $brokenContent] = $this->prepareInternalLinkValidatorBrokenLinksTestCase( $repository ); From cddeba5452dff743bb8aed3a260140c2915fd45c Mon Sep 17 00:00:00 2001 From: matx132 Date: Wed, 20 Sep 2023 14:39:17 +0200 Subject: [PATCH 2/2] Corrected PHPDoc and set table name from DoctrineDatabase::URL_TABLE --- .../eZ/API/RichTextFieldTypeIntegrationTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php index a0dcd0c5..aff08aab 100644 --- a/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php +++ b/tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php @@ -17,6 +17,7 @@ use eZ\Publish\API\Repository\Tests\FieldType\SearchBaseIntegrationTest; use eZ\Publish\API\Repository\Values\Content\Location; use eZ\Publish\Core\Base\Exceptions\NotFoundException; +use eZ\Publish\Core\Persistence\Legacy\URL\Gateway\DoctrineDatabase; use EzSystems\EzPlatformRichText\eZ\FieldType\RichText\Value as RichTextValue; use eZ\Publish\API\Repository\Values\Content\Field; use DOMDocument; @@ -637,10 +638,10 @@ public function testConvertRemoteObjectIdToObjectId($test, $expected): void } /** + * @throws \Doctrine\DBAL\Driver\Exception + * @throws \Doctrine\DBAL\Exception * @throws \ErrorException - * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException - * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException - * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\Exception */ public function testExternalLinkStoringAfterUpdate(): void { @@ -681,7 +682,7 @@ public function testExternalLinkStoringAfterUpdate(): void $urlId = $this->getUrlIdForLink($testLink); - $this->assertContains($urlId, $urlIdsAfterUpdate); + self::assertContains($urlId, $urlIdsAfterUpdate); } /** @@ -698,7 +699,7 @@ private function getUrlIdForLink(string $link): int ->select( $connection->quoteIdentifier('id') ) - ->from('ezurl') + ->from(DoctrineDatabase::URL_TABLE) ->where('url = :url') ->setParameter(':url', $link, ParameterType::STRING) ;