Skip to content

Commit

Permalink
fixup! fixup! IBX-7579:Richtext: Rows are added to ezurl_object_link …
Browse files Browse the repository at this point in the history
…on every save: Changed unit test into integration test
  • Loading branch information
vidarl committed Jun 19, 2024
1 parent 1c1c742 commit 26e6145
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 48 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ public function insertUrl($url)
/**
* Return a list of URLs used by the given field and version.
*
* @return bool[] An array of URLs, with urls as keys
* array<string, boolean> An array of URLs, with urls as keys
*/
public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array
{
$selectQuery = $this->connection->createQueryBuilder();
$selectQuery
->select($this->connection->quoteIdentifier('url.url'))
->from($this->connection->quoteIdentifier(self::URL_TABLE), 'url')
->leftJoin(
->innerJoin(
'url',
$this->connection->quoteIdentifier(self::URL_LINK_TABLE),
'link',
Expand All @@ -162,9 +162,9 @@ public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array
->setParameter(':contentobject_attribute_version', $versionNo, ParameterType::INTEGER);

$statement = $selectQuery->execute();
$rows = $statement->fetchAllAssociativeIndexed();
$rows = $statement->fetchFirstColumn();
$result = [];
foreach ($rows as $url => $item) {
foreach ($rows as $url) {
$result[$url] = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,37 @@
*/
declare(strict_types=1);

namespace Ibexa\Tests\integration\Core\FieldType\Url\UrlStorage\Gateway;
namespace Ibexa\Tests\Integration\Core\FieldType\Url\UrlStorage\Gateway;

use eZ\Publish\Core\FieldType\Tests\Integration\Url\UrlStorage\UrlStorageGatewayTest;
use eZ\Publish\Core\FieldType\Tests\Integration\BaseCoreFieldTypeIntegrationTest;
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway as UrlStorageGateway;
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage;

final class UrlDoctrineStorageGatewayTest extends UrlStorageGatewayTest
/**
* @covers \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage
*/
final class UrlDoctrineStorageGatewayTest extends BaseCoreFieldTypeIntegrationTest
{
public function testGetUrlsFromUrlLink(): void
{
$gateway = $this->getGateway();

$urlIds = [];
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example1');
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example2');
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example3');

$gateway->linkUrl($urlIds[0], 10, 1);
$gateway->linkUrl($urlIds[1], 10, 1);
$gateway->linkUrl($urlIds[1], 12, 2);
$gateway->linkUrl($urlIds[2], 14, 1);

self::assertEquals(['https://ibexa.co/example1' => true, 'https://ibexa.co/example2' => true], $gateway->getUrlsFromUrlLink(10, 1), 'Did not get expected urlS for field 10');
self::assertEquals(['https://ibexa.co/example2' => true], $gateway->getUrlsFromUrlLink(12, 2), 'Did not get expected url for field 12');
self::assertEquals(['https://ibexa.co/example3' => true], $gateway->getUrlsFromUrlLink(14, 1), 'Did not get expected url for field 14');
self::assertEquals([], $gateway->getUrlsFromUrlLink(15, 1), 'Expected no urls for field 15');
}

protected function getGateway(): UrlStorageGateway
{
return new DoctrineStorage($this->getDatabaseConnection());
Expand Down

0 comments on commit 26e6145

Please sign in to comment.