Skip to content

Commit

Permalink
Merge pull request ezsystems#1061 from emodric/fix-url-with-id-0-not-…
Browse files Browse the repository at this point in the history
…found

Fix EZP-23544: UrlStorage::getFieldData logs an error if URL with an empty ID is not found
  • Loading branch information
pspanja committed Oct 31, 2014
2 parents 58e2a73 + e4314cd commit 7f11bf7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
19 changes: 19 additions & 0 deletions eZ/Publish/Core/FieldType/Tests/Url/UrlStorageTest.php
Expand Up @@ -144,6 +144,25 @@ public function testGetFieldDataNotFound()
$this->assertEquals( "", $field->value->externalData );
}

public function testGetFieldDataWithEmptyUrlId()
{
$versionInfo = new VersionInfo();
$fieldValue = new FieldValue( array( "data" => array( "urlId" => null ) ) );
$field = new Field( array( "id" => 42, "value" => $fieldValue ) );
$gateway = $this->getGatewayMock();

$gateway
->expects( $this->never() )
->method( "getIdUrlMap" );

$logger = $this->getLoggerMock();
$logger
->expects( $this->never() )
->method( "error" );

$this->assertEquals( null, $field->value->externalData );
}

public function testDeleteFieldData()
{
$versionInfo = new VersionInfo( array( "versionNo" => 24 ) );
Expand Down
9 changes: 7 additions & 2 deletions eZ/Publish/Core/FieldType/Url/UrlStorage.php
Expand Up @@ -78,10 +78,15 @@ public function storeFieldData( VersionInfo $versionInfo, Field $field, array $c
*/
public function getFieldData( VersionInfo $versionInfo, Field $field, array $context )
{
/** @var \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway $gateway */
$gateway = $this->getGateway( $context );
$id = $field->value->data["urlId"];
if ( empty( $id ) )
{
$field->value->externalData = null;
return;
}

/** @var \eZ\Publish\Core\FieldType\Url\UrlStorage\Gateway $gateway */
$gateway = $this->getGateway( $context );
$map = $gateway->getIdUrlMap( array( $id ) );

// URL id is not in the DB
Expand Down

0 comments on commit 7f11bf7

Please sign in to comment.