-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1227 from ezsystems/impl-EZP-24267-indexable-rela…
…tion Implement EZP-24266: Indexable Relation field type
- Loading branch information
Showing
39 changed files
with
901 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
eZ/Publish/API/Repository/Tests/FieldType/RelationSearchBaseIntegrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ Publish Kernel package | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
|
||
namespace eZ\Publish\API\Repository\Tests\FieldType; | ||
|
||
use eZ\Publish\Core\Repository\Values\Content\Relation; | ||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
/** | ||
* Base integration test for field types handling content relations. | ||
* | ||
* @group integration | ||
* @group field-type | ||
* @group relation | ||
*/ | ||
abstract class RelationSearchBaseIntegrationTest extends SearchBaseIntegrationTest | ||
{ | ||
/** | ||
* @param \eZ\Publish\API\Repository\Values\Content\Content $content | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Content\Relation[] | ||
*/ | ||
abstract public function getCreateExpectedRelations( Content $content ); | ||
|
||
/** | ||
* @param \eZ\Publish\API\Repository\Values\Content\Content $content | ||
* | ||
* @return \eZ\Publish\API\Repository\Values\Content\Relation[] | ||
*/ | ||
abstract public function getUpdateExpectedRelations( Content $content ); | ||
|
||
/** | ||
* Tests relation processing on field create. | ||
*/ | ||
public function testCreateContentRelationsProcessedCorrect() | ||
{ | ||
$content = $this->createContent( $this->getValidCreationFieldData() ); | ||
|
||
$this->assertEquals( | ||
$this->normalizeRelations( | ||
$this->getCreateExpectedRelations( $content ) | ||
), | ||
$this->normalizeRelations( | ||
$this->getRepository()->getContentService()->loadRelations( $content->versionInfo ) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Tests relation processing on field update. | ||
*/ | ||
public function testUpdateContentRelationsProcessedCorrect() | ||
{ | ||
$content = $this->updateContent( $this->getValidUpdateFieldData() ); | ||
|
||
$this->assertEquals( | ||
$this->normalizeRelations( | ||
$this->getUpdateExpectedRelations( $content ) | ||
), | ||
$this->normalizeRelations( | ||
$this->getRepository()->getContentService()->loadRelations( $content->versionInfo ) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Normalizes given $relations for easier comparison. | ||
* | ||
* @param \eZ\Publish\Core\Repository\Values\Content\Relation[] $relations | ||
* | ||
* @return \eZ\Publish\Core\Repository\Values\Content\Relation[] | ||
*/ | ||
protected function normalizeRelations( array $relations ) | ||
{ | ||
usort( | ||
$relations, | ||
function ( Relation $a, Relation $b ) | ||
{ | ||
if ( $a->type == $b->type ) | ||
{ | ||
return $a->destinationContentInfo->id < $b->destinationContentInfo->id ? 1 : -1; | ||
} | ||
return $a->type < $b->type ? 1 : -1; | ||
} | ||
); | ||
$normalized = array_map( | ||
function ( Relation $relation ) | ||
{ | ||
$newRelation = new Relation( | ||
array( | ||
"id" => null, | ||
"sourceFieldDefinitionIdentifier" => $relation->sourceFieldDefinitionIdentifier, | ||
"type" => $relation->type, | ||
"sourceContentInfo" => $relation->sourceContentInfo, | ||
"destinationContentInfo" => $relation->destinationContentInfo | ||
) | ||
); | ||
return $newRelation; | ||
}, | ||
$relations | ||
); | ||
|
||
return $normalized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.