Skip to content
Permalink
Browse files

Merge pull request #1245 from ezsystems/impl-EZP-24314-indexable-bina…

…ryfile

Implement EZP-24314: Indexable BinaryFile field type
  • Loading branch information...
pspanja committed May 4, 2015
2 parents 55f4cc9 + 345736d commit c8493b557bb9d5aadbd38e10f04e1f010dfc9e5c
@@ -11,14 +11,16 @@
use eZ\Publish\Core\FieldType\BinaryFile\Value as BinaryFileValue;
use eZ\Publish\API\Repository\Values\Content\Field;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
/**
* Integration test for use field type
*
* @group integration
* @group field-type
*/
class BinaryFileIntegrationTest extends FileBaseIntegrationTest
class BinaryFileIntegrationTest extends FileSearchBaseIntegrationTest
{
/**
* Stores the loaded image path for copy test.
@@ -406,4 +408,227 @@ public function providerForTestIsNotEmptyValue()
),
);
}
protected function getValidSearchValueOne()
{
return new BinaryFileValue(
array(
'inputUri' => ( $path = __DIR__ . '/_fixtures/image.jpg' ),
'fileName' => 'blue-blue-blue-sindelfingen.jpg',
'fileSize' => filesize( $path ),
)
);
}
protected function getValidSearchValueTwo()
{
return new BinaryFileValue(
array(
'inputUri' => ( $path = __DIR__ . '/_fixtures/image.png' ),
'fileName' => 'icy-night-flower-binary.png',
'fileSize' => filesize( $path ),
)
);
}
protected function getSearchTargetValueOne()
{
$value = $this->getValidSearchValueOne();
return $value->fileName;
}
protected function getSearchTargetValueTwo()
{
$value = $this->getValidSearchValueTwo();
return $value->fileName;
}
/**
* Redefined here in order to execute before tests with modified fields below,
* which depend on it for the returned value.
*/
public function testCreateTestContent()
{
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\\Publish\\API\\Repository\\Tests\\SetupFactory\\Legacy' )
{
$this->markTestSkipped(
"BinaryFile field type is not searchable with Field criterion and sort clause in Legacy search engine"
);
}
return parent::testCreateTestContent();
}
public function criteriaProviderModifiedFieldMimeType()
{
return $this->provideCriteria( "image/jpeg", "image/png" );
}
/**
* Tests Content Search filtering with Field criterion on the alternative text modified field
*
* @dataProvider criteriaProviderModifiedFieldMimeType
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
* @param boolean $includesOne
* @param boolean $includesTwo
* @param array $context
*/
public function testFilterContentModifiedFieldMimeType(
Criterion $criterion,
$includesOne,
$includesTwo,
array $context
)
{
$this->assertFilterContentModifiedField(
$criterion,
$includesOne,
$includesTwo,
$context,
true,
"mime_type"
);
}
/**
* Tests Content Search querying with Field criterion on the alternative text modified field
*
* @dataProvider criteriaProviderModifiedFieldMimeType
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
* @param boolean $includesOne
* @param boolean $includesTwo
* @param array $context
*/
public function testQueryContentModifiedFieldMimeType(
Criterion $criterion,
$includesOne,
$includesTwo,
array $context
)
{
$this->assertFilterContentModifiedField(
$criterion,
$includesOne,
$includesTwo,
$context,
false,
"mime_type"
);
}
public function criteriaProviderModifiedFieldFileSize()
{
$valueOne = $this->getValidSearchValueOne();
$valueTwo = $this->getValidSearchValueTwo();
return $this->provideCriteria( $valueOne->fileSize, $valueTwo->fileSize );
}
/**
* Tests Content Search filtering with Field criterion on the file size modified field
*
* @dataProvider criteriaProviderModifiedFieldFileSize
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
* @param boolean $includesOne
* @param boolean $includesTwo
* @param array $context
*/
public function testFilterContentModifiedFieldFileSize(
Criterion $criterion,
$includesOne,
$includesTwo,
array $context
)
{
$this->assertFilterContentModifiedField(
$criterion,
$includesOne,
$includesTwo,
$context,
true,
"file_size"
);
}
/**
* Tests Content Search querying with Field criterion on the file size modified field
*
* @dataProvider criteriaProviderModifiedFieldFileSize
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
* @param boolean $includesOne
* @param boolean $includesTwo
* @param array $context
*/
public function testQueryContentModifiedFieldFileSize(
Criterion $criterion,
$includesOne,
$includesTwo,
array $context
)
{
$this->assertFilterContentModifiedField(
$criterion,
$includesOne,
$includesTwo,
$context,
false,
"file_size"
);
}
/**
* Tests Content Search sort with Field sort clause on the alternative text modified field
*
* @dataProvider sortClauseProvider
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause
* @param boolean $ascending
* @param array $context
*/
public function testSortContentModifiedFieldMimeType(
SortClause $sortClause,
$ascending,
array $context
)
{
$this->assertSortContentModifiedField(
$sortClause,
$ascending,
$context,
"mime_type"
);
}
/**
* Tests Content Search sort with Field sort clause on the file size modified field
*
* @dataProvider sortClauseProvider
* @depends testCreateTestContent
*
* @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause
* @param boolean $ascending
* @param array $context
*/
public function testSortContentModifiedFieldFieldSize(
SortClause $sortClause,
$ascending,
array $context
)
{
$this->assertSortContentModifiedField(
$sortClause,
$ascending,
$context,
"file_size"
);
}
}
@@ -121,6 +121,16 @@ protected function getSearchTargetValueTwo()
return $this->getValidSearchValueTwo();
}
protected function checkCustomFieldsSupport()
{
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\\Publish\\API\\Repository\\Tests\\SetupFactory\\Legacy' )
{
$this->markTestSkipped(
"Legacy Search Engine does not support custom fields"
);
}
}
/**
* Creates and returns content with given $fieldData
*
@@ -730,6 +740,8 @@ public function assertFilterContentModifiedField(
$fieldName
)
{
$this->checkCustomFieldsSupport();
$this->modifyFieldCriterion( $criterion, $fieldName );
list( $repository, $contentOneId, $contentTwoId ) = $context;
@@ -758,6 +770,8 @@ public function assertSortContentModifiedField(
{
$setupFactory = $this->getSetupFactory();
$this->checkCustomFieldsSupport();
if ( $setupFactory instanceof LegacySolr )
{
$this->markTestSkipped(
@@ -0,0 +1,77 @@
<?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\Core\FieldType\BinaryFile;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\FieldType\Indexable;
use eZ\Publish\SPI\Search;
/**
* Indexable definition for BinaryFile field type
*/
class SearchField implements Indexable
{
/**
* Get index data for field for search backend
*
* @param Field $field
*
* @return \eZ\Publish\SPI\Search\Field[]
*/
public function getIndexData( Field $field )
{
return array(
new Search\Field(
'file_name',
$field->value->externalData["fileName"],
new Search\FieldType\StringField()
),
new Search\Field(
'file_size',
$field->value->externalData["fileSize"],
new Search\FieldType\IntegerField()
),
new Search\Field(
'mime_type',
$field->value->externalData["mimeType"],
new Search\FieldType\StringField()
),
);
}
/**
* Get index field types for search backend
*
* @return \eZ\Publish\SPI\Search\FieldType[]
*/
public function getIndexDefinition()
{
return array(
'file_name' => new Search\FieldType\StringField(),
'file_size' => new Search\FieldType\IntegerField(),
'mime_type' => new Search\FieldType\StringField(),
);
}
/**
* Get name of the default field to be used for query and sort.
*
* As field types can index multiple fields (see MapLocation field type's
* implementation of this interface), this method is used to define default
* field for query and sort. Default field is typically used by Field
* criterion and sort clause.
*
* @return string
*/
public function getDefaultField()
{
return "file_name";
}
}
@@ -7,6 +7,7 @@ parameters:
ezpublish.fieldType.indexable.ezimage.class: eZ\Publish\Core\FieldType\Image\SearchField
ezpublish.fieldType.indexable.ezmedia.class: eZ\Publish\Core\FieldType\Media\SearchField
ezpublish.fieldType.indexable.ezobjectrelation.class: eZ\Publish\Core\FieldType\Relation\SearchField
ezpublish.fieldType.indexable.ezbinaryfile.class: eZ\Publish\Core\FieldType\BinaryFile\SearchField
ezpublish.fieldType.indexable.ezprice.class: eZ\Publish\Core\FieldType\Price\SearchField
ezpublish.fieldType.indexable.ezgmaplocation.class: eZ\Publish\Core\FieldType\MapLocation\SearchField
ezpublish.fieldType.indexable.ezcountry.class: eZ\Publish\Core\FieldType\Country\SearchField
@@ -60,6 +61,11 @@ services:
tags:
- {name: ezpublish.fieldType.indexable, alias: ezmedia}

ezpublish.fieldType.indexable.ezbinaryfile:
class: %ezpublish.fieldType.indexable.ezbinaryfile.class%
tags:
- {name: ezpublish.fieldType.indexable, alias: ezbinaryfile}

ezpublish.fieldType.indexable.eztext:
class: %ezpublish.fieldType.indexable.eztext.class%
tags:
@@ -115,6 +121,5 @@ services:
- {name: ezpublish.fieldType.indexable, alias: ezsubtreesubscription}
- {name: ezpublish.fieldType.indexable, alias: ezobjectrelationlist}
- {name: ezpublish.fieldType.indexable, alias: ezoption}
- {name: ezpublish.fieldType.indexable, alias: ezbinaryfile}
- {name: ezpublish.fieldType.indexable, alias: ezpage}
- {name: ezpublish.fieldType.indexable, alias: ezcomcomments}

0 comments on commit c8493b5

Please sign in to comment.
You can’t perform that action at this time.