Skip to content

Commit 26e6145

Browse files
committed
fixup! fixup! IBX-7579:Richtext: Rows are added to ezurl_object_link on every save: Changed unit test into integration test
1 parent 1c1c742 commit 26e6145

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

eZ/Publish/Core/FieldType/Tests/Integration/Url/UrlStorage/UrlStorageGatewayTest.php

-41
This file was deleted.

eZ/Publish/Core/FieldType/Url/UrlStorage/Gateway/DoctrineStorage.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ public function insertUrl($url)
132132
/**
133133
* Return a list of URLs used by the given field and version.
134134
*
135-
* @return bool[] An array of URLs, with urls as keys
135+
* array<string, boolean> An array of URLs, with urls as keys
136136
*/
137137
public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array
138138
{
139139
$selectQuery = $this->connection->createQueryBuilder();
140140
$selectQuery
141141
->select($this->connection->quoteIdentifier('url.url'))
142142
->from($this->connection->quoteIdentifier(self::URL_TABLE), 'url')
143-
->leftJoin(
143+
->innerJoin(
144144
'url',
145145
$this->connection->quoteIdentifier(self::URL_LINK_TABLE),
146146
'link',
@@ -162,9 +162,9 @@ public function getUrlsFromUrlLink(int $fieldId, int $versionNo): array
162162
->setParameter(':contentobject_attribute_version', $versionNo, ParameterType::INTEGER);
163163

164164
$statement = $selectQuery->execute();
165-
$rows = $statement->fetchAllAssociativeIndexed();
165+
$rows = $statement->fetchFirstColumn();
166166
$result = [];
167-
foreach ($rows as $url => $item) {
167+
foreach ($rows as $url) {
168168
$result[$url] = true;
169169
}
170170

tests/integration/Core/FieldType/Url/UrlStorage/Gateway/UrlDoctrineStorageGatewayTest.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,37 @@
66
*/
77
declare(strict_types=1);
88

9-
namespace Ibexa\Tests\integration\Core\FieldType\Url\UrlStorage\Gateway;
9+
namespace Ibexa\Tests\Integration\Core\FieldType\Url\UrlStorage\Gateway;
1010

11-
use eZ\Publish\Core\FieldType\Tests\Integration\Url\UrlStorage\UrlStorageGatewayTest;
11+
use eZ\Publish\Core\FieldType\Tests\Integration\BaseCoreFieldTypeIntegrationTest;
1212
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway as UrlStorageGateway;
1313
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage;
1414

15-
final class UrlDoctrineStorageGatewayTest extends UrlStorageGatewayTest
15+
/**
16+
* @covers \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage
17+
*/
18+
final class UrlDoctrineStorageGatewayTest extends BaseCoreFieldTypeIntegrationTest
1619
{
20+
public function testGetUrlsFromUrlLink(): void
21+
{
22+
$gateway = $this->getGateway();
23+
24+
$urlIds = [];
25+
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example1');
26+
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example2');
27+
$urlIds[] = $gateway->insertUrl('https://ibexa.co/example3');
28+
29+
$gateway->linkUrl($urlIds[0], 10, 1);
30+
$gateway->linkUrl($urlIds[1], 10, 1);
31+
$gateway->linkUrl($urlIds[1], 12, 2);
32+
$gateway->linkUrl($urlIds[2], 14, 1);
33+
34+
self::assertEquals(['https://ibexa.co/example1' => true, 'https://ibexa.co/example2' => true], $gateway->getUrlsFromUrlLink(10, 1), 'Did not get expected urlS for field 10');
35+
self::assertEquals(['https://ibexa.co/example2' => true], $gateway->getUrlsFromUrlLink(12, 2), 'Did not get expected url for field 12');
36+
self::assertEquals(['https://ibexa.co/example3' => true], $gateway->getUrlsFromUrlLink(14, 1), 'Did not get expected url for field 14');
37+
self::assertEquals([], $gateway->getUrlsFromUrlLink(15, 1), 'Expected no urls for field 15');
38+
}
39+
1740
protected function getGateway(): UrlStorageGateway
1841
{
1942
return new DoctrineStorage($this->getDatabaseConnection());

0 commit comments

Comments
 (0)