Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected test for external link #240

Merged
merged 2 commits into from
Sep 20, 2023
Merged
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
7 changes: 5 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 41 additions & 12 deletions tests/integration/eZ/API/RichTextFieldTypeIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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 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;
Expand Down Expand Up @@ -636,14 +638,15 @@ 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
mateuszdebinski marked this conversation as resolved.
Show resolved Hide resolved
{
$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();

Expand All @@ -663,12 +666,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(
Expand All @@ -681,7 +680,37 @@ public function testExternalLinkStoringAfterUpdate(): void
$content->contentInfo->currentVersionNo
);

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

self::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(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 @@ -911,7 +940,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 @@ -939,7 +968,7 @@ public function testInternalLinkValidatorReturnsErrorOnMissingRelationInUpdatedF
$repository = $this->getRepository();
$contentService = $repository->getContentService();

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

Expand Down
Loading