Skip to content

Commit

Permalink
fixup! IBX-7579:Richtext: Rows are added to ezurl_object_link on ever…
Browse files Browse the repository at this point in the history
…y save: Changed unit test into integration test
  • Loading branch information
vidarl committed Jun 12, 2024
1 parent 54e2918 commit 1c1c742
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\FieldType\Tests\Integration\Url\UrlStorage;

use eZ\Publish\Core\FieldType\Tests\Integration\BaseCoreFieldTypeIntegrationTest;
use eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway;

/**
* Url Field Type external storage gateway tests.
*/
abstract class UrlStorageGatewayTest extends BaseCoreFieldTypeIntegrationTest
{
abstract protected function getGateway(): Gateway;

/**
* @covers \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage::getUrlsFromUrlLink
*/
public function testGetUrlsFromUrlLink()
{
$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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,6 @@ public function testUnlinkUrl()
$this->assertEquals($expected, $result);
}

/**
* @covers \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway\DoctrineStorage::getUrlsFromUrlLink
*/
public function testGetUrlsFromUrlLink()
{
$gateway = $this->getStorageGateway();

$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 getStorageGateway(): Gateway
{
if (!isset($this->storageGateway)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

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

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

final class UrlDoctrineStorageGatewayTest extends UrlStorageGatewayTest
{
protected function getGateway(): UrlStorageGateway
{
return new DoctrineStorage($this->getDatabaseConnection());
}
}

0 comments on commit 1c1c742

Please sign in to comment.