Skip to content

Commit

Permalink
Merge pull request #1227 from ezsystems/impl-EZP-24267-indexable-rela…
Browse files Browse the repository at this point in the history
…tion

Implement EZP-24266: Indexable Relation field type
  • Loading branch information
pspanja committed May 1, 2015
2 parents 659b3e1 + c9a9047 commit 784b3da
Show file tree
Hide file tree
Showing 39 changed files with 901 additions and 678 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @group integration
* @group field-type
*/
class RelationFieldTypeIntegrationTest extends RelationBaseIntegrationTest
class RelationFieldTypeIntegrationTest extends RelationSearchBaseIntegrationTest
{
/**
* Get name of tested field type
Expand Down Expand Up @@ -363,4 +363,30 @@ public function providerForTestIsNotEmptyValue()
),
);
}

protected function getValidSearchValueOne()
{
// Using different values for Legacy Search Engine, in order to demonstrate that sort will
// depend on how search engine stores field type's value. Legacy stores it as integer, while
// other engines (Solr and Elasticsearch) store it as string.
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return 4;
}

return 10;
}

protected function getValidSearchValueTwo()
{
// Using different values for Legacy Search Engine, in order to demonstrate that sort will
// depend on how search engine stores field type's value. Legacy stores it as integer, while
// other engines (Solr and Elasticsearch) store it as string.
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return 49;
}

return 4;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 10,
'title' => 'Anonymous User',
),
'score' => 1,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 10,
'title' => 'Anonymous User',
'id' => 4,
'title' => 'Users',
),
'score' => 1,
'index' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 10,
'title' => 'Anonymous User',
),
'score' => 1,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 10,
'title' => 'Anonymous User',
'id' => 11,
'title' => 'Members',
),
'score' => 1,
'index' => NULL,
Expand All @@ -32,8 +32,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 11,
'title' => 'Members',
'id' => 12,
'title' => 'Administrator users',
),
'score' => 1,
'index' => NULL,
Expand All @@ -43,8 +43,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 12,
'title' => 'Administrator users',
'id' => 13,
'title' => 'Editors',
),
'score' => 1,
'index' => NULL,
Expand All @@ -54,8 +54,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 13,
'title' => 'Editors',
'id' => 14,
'title' => 'Administrator User',
),
'score' => 1,
'index' => NULL,
Expand All @@ -65,8 +65,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 14,
'title' => 'Administrator User',
'id' => 4,
'title' => 'Users',
),
'score' => 1,
'index' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 10,
'title' => 'Anonymous User',
),
'score' => 1,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 10,
'title' => 'Anonymous User',
'id' => 12,
'title' => 'Administrator users',
),
'score' => 1,
'index' => NULL,
Expand All @@ -32,8 +32,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 12,
'title' => 'Administrator users',
'id' => 13,
'title' => 'Editors',
),
'score' => 1,
'index' => NULL,
Expand All @@ -43,8 +43,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 13,
'title' => 'Editors',
'id' => 4,
'title' => 'Users',
),
'score' => 1,
'index' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 10,
'title' => 'Anonymous User',
),
'score' => 1,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 10,
'title' => 'Anonymous User',
'id' => 4,
'title' => 'Users',
),
'score' => 1,
'index' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 10,
'title' => 'Anonymous User',
),
'score' => 0.35355337999999997,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 10,
'title' => 'Anonymous User',
'id' => 14,
'title' => 'Administrator User',
),
'score' => 0.35355337999999997,
'index' => NULL,
Expand All @@ -32,8 +32,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 14,
'title' => 'Administrator User',
'id' => 4,
'title' => 'Users',
),
'score' => 0.35355337999999997,
'index' => NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 4,
'title' => 'Users',
'id' => 11,
'title' => 'Members',
),
'score' => 1,
'index' => NULL,
Expand All @@ -21,8 +21,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 11,
'title' => 'Members',
'id' => 12,
'title' => 'Administrator users',
),
'score' => 1,
'index' => NULL,
Expand All @@ -32,8 +32,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 12,
'title' => 'Administrator users',
'id' => 13,
'title' => 'Editors',
),
'score' => 1,
'index' => NULL,
Expand All @@ -43,8 +43,8 @@
eZ\Publish\API\Repository\Values\Content\Search\SearchHit::__set_state(array(
'valueObject' =>
array (
'id' => 13,
'title' => 'Editors',
'id' => 4,
'title' => 'Users',
),
'score' => 1,
'index' => NULL,
Expand Down
Loading

0 comments on commit 784b3da

Please sign in to comment.