Skip to content
Permalink
Browse files

Merge pull request #466 from ezsystems/fix-EZP-21035-issingular

Fix EZP-21035: User can not be properly created from inside storage
  • Loading branch information...
andrerom committed Aug 12, 2013
2 parents 4a54c67 + afca8e0 commit 02adc861b17607bf67482d85d950f6d43e95c02d
@@ -30,6 +30,25 @@ Changes affecting version compatibility with former or future versions.
Path remains available for both input and output, as a BC facilitator,
but will be removed in a further major version and should not be used

* ContentTypeService->createContentType()

The ContentTypeValidationException is introduced on this method, thrown when
ContentType being created is not valid. This will be the case when multiple field
definitions of the same singular type are provided in the create struct.

* ContentTypeService->addFieldDefinition()

ContentTypeFieldDefinitionValidationException is added to the interface of this
method. This exception was already being used, therefore this is only a PHPDoc change.

BadStateException is added to this method, thrown when content type that is being
updated is in a bad state. There are currently two possible cases when this can
happen:

* When the field definition is of singular type already existing in the content type.
* When the field definition is of the type that can't be added to a content type that
already has content instances is being added to such content type.

No further changes known in this release at time of writing.
See online on your corresponding eZ Publish version for
updated list of known issues (missing features, breaks and errata).
@@ -3532,6 +3532,7 @@ If publish = true:
:Error Codes:
:400: - If the Input does not match the input schema definition,
- If validation on a field definition fails
- If validation of the content type fails, eg. multiple fields of a same singular field type are provided
- If publish = true and the input is not complete e.g. no field definitions are provided
:401: If the user is not authorized to create this content type
:403: If a content type with same identifier already exists
@@ -3900,9 +3901,11 @@ Add Field definition
FieldDefinition_

:Error Codes:
:400: If the Input does not match the input schema definition, In this case the response contains an ErrorMessage_
:400: If the Input does not match the input schema definition or validation on the field definition fails, in this case the response contains an ErrorMessage_
:401: If the user is not authorized to add a field definition
:403: If a field definition with same identifier already exists in the given content type
:403: - If a field definition with same identifier already exists in the given content type
- If the field definition is of singular type, already existing in the given content type
- If the field definition of the type that can't be added to a content type that already has content instances is being added to such content type

Get Fielddefinition
```````````````````
@@ -67,7 +67,8 @@ public function testRedirectLocationByRemoteId( $locationHref )
*/
public function testRedirectLocationById( $locationHref )
{
$id = array_pop( explode( '/', $locationHref ) );
$hrefParts = explode( '/', $locationHref );
$id = array_pop( $hrefParts );
$response = $this->sendHttpRequest(
$this->createHttpRequest( "GET", "/api/ezp/v2/content/locations?id=$id" )
);
@@ -252,10 +252,12 @@ public function unassignContentTypeGroup( ContentType $contentType, ContentTypeG
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier in already exists in the content type
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit a content type
* @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
* if a field definition in the $contentTypeCreateStruct is not valid
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If field definition of the same non-repeatable type is being
* added to the ContentType that already contains one
* or 'ezuser' type field definition is being added to the
* ContentType that has Content instances
* or field definition that can't be added to a ContentType that
* has Content instances is being added to such ContentType
*
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
* @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
@@ -0,0 +1,17 @@
<?php
/**
* File containing the eZ\Publish\API\Repository\Exceptions\ContentTypeValidationException class.
*
* @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
*/
namespace eZ\Publish\API\Repository\Exceptions;
/**
* This Exception is thrown on create or update content type when content type is not valid
*/
abstract class ContentTypeValidationException extends ForbiddenException
{
}
@@ -110,6 +110,13 @@ public function isSearchable();
*/
public function isSingular();
/**
* Indicates if the field definition of this type can be added to a ContentType with Content instances.
*
* @return boolean
*/
public function onlyEmptyInstance();
/**
* Returns the empty value for this field type.
*
@@ -14,6 +14,8 @@
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
use eZ\Publish\API\Repository\Exceptions;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException;
use eZ\Publish\API\Repository\Values\Translation\Message;
use Exception;
use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue;
@@ -1054,6 +1056,73 @@ public function testCreateContentTypeThrowsInvalidArgumentExceptionDuplicateFiel
/* END: Use Case */
}
/**
* Test for the createContentType() method.
*
* @return void
* @see \eZ\Publish\API\Repository\ContentTypeService::createContentType()
* @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentType
*/
public function testCreateContentTypeThrowsContentTypeFieldDefinitionValidationException()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$contentTypeService = $repository->getContentTypeService();
$typeCreate = $contentTypeService->newContentTypeCreateStruct( 'blog-post' );
$fieldCreate = $contentTypeService->newFieldDefinitionCreateStruct(
'temperature', 'ezfloat'
);
$fieldCreate->isSearchable = true;
$fieldCreate->validatorConfiguration = array(
'FloatValueValidator' => array(
'minFloatValue' => "forty two point one",
'maxFloatValue' => "75.3",
)
);
$typeCreate->addFieldDefinition( $fieldCreate );
$groups = array(
$contentTypeService->loadContentTypeGroupByIdentifier( 'Media' ),
$contentTypeService->loadContentTypeGroupByIdentifier( 'Setup' )
);
try
{
// Throws validation exception, because field can't be created as searchable and it's validator configuration is invalid
$contentType = $contentTypeService->createContentType( $typeCreate, $groups );
}
catch ( ContentTypeFieldDefinitionValidationException $e )
{
$validationErrors = $e->getFieldErrors();
}
/* END: Use Case */
/** @var $validationErrors */
$this->assertTrue( isset( $validationErrors ) );
$this->assertInternalType( "array", $validationErrors );
$this->assertCount( 1, $validationErrors );
$this->assertArrayHasKey( "temperature", $validationErrors );
$this->assertInternalType( "array", $validationErrors["temperature"] );
$this->assertCount( 2, $validationErrors["temperature"] );
$this->assertInstanceOf( "eZ\\Publish\\Core\\FieldType\\ValidationError", $validationErrors["temperature"][0] );
$this->assertInstanceOf( "eZ\\Publish\\Core\\FieldType\\ValidationError", $validationErrors["temperature"][1] );
$this->assertEquals(
new Message( "FieldType 'ezfloat' is not searchable" ),
$validationErrors["temperature"][0]->getTranslatableMessage()
);
$this->assertEquals(
new Message(
"Validator parameter '%parameter%' value must be of numeric type",
array( "parameter" => "minFloatValue" )
),
$validationErrors["temperature"][1]->getTranslatableMessage()
);
}
/**
* Test for the newContentTypeUpdateStruct() method.
*
@@ -1391,6 +1460,76 @@ public function testAddFieldDefinitionThrowsInvalidArgumentExceptionDuplicateFie
/* END: Use Case */
}
/**
* Test for the addFieldDefinition() method.
*
* Testing that field definition of non-repeatable field type can not be added multiple
* times to the same ContentType.
*
* @return void
* @see \eZ\Publish\API\Repository\ContentTypeService::addFieldDefinition()
* @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testAddFieldDefinition
*/
public function testAddFieldDefinitionThrowsContentTypeFieldDefinitionValidationException()
{
$repository = $this->getRepository();
$contentTypeService = $repository->getContentTypeService();
/* BEGIN: Use Case */
$userContentType = $contentTypeService->loadContentTypeByIdentifier( "user" );
$userContentTypeDraft = $contentTypeService->createContentTypeDraft( $userContentType );
$fieldDefCreate = $contentTypeService->newFieldDefinitionCreateStruct(
'temperature', 'ezfloat'
);
$fieldDefCreate->isSearchable = true;
$fieldDefCreate->validatorConfiguration = array(
'FloatValueValidator' => array(
'minFloatValue' => "42.1",
'maxFloatValue' => "seventy five point three",
)
);
$fieldDefCreate->fieldGroup = 'blog-meta';
$fieldDefCreate->position = 1;
$fieldDefCreate->isTranslatable = false;
$fieldDefCreate->isRequired = true;
$fieldDefCreate->isInfoCollector = false;
$fieldDefCreate->fieldSettings = array();
try
{
// Throws an exception because $userContentTypeDraft already contains non-repeatable field type definition 'ezuser'
$contentTypeService->addFieldDefinition( $userContentTypeDraft, $fieldDefCreate );
}
catch ( ContentTypeFieldDefinitionValidationException $e )
{
$validationErrors = $e->getFieldErrors();
}
/* END: Use Case */
/** @var $validationErrors */
$this->assertTrue( isset( $validationErrors ) );
$this->assertInternalType( "array", $validationErrors );
$this->assertCount( 1, $validationErrors );
$this->assertArrayHasKey( "temperature", $validationErrors );
$this->assertInternalType( "array", $validationErrors["temperature"] );
$this->assertCount( 2, $validationErrors["temperature"] );
$this->assertInstanceOf( "eZ\\Publish\\Core\\FieldType\\ValidationError", $validationErrors["temperature"][0] );
$this->assertInstanceOf( "eZ\\Publish\\Core\\FieldType\\ValidationError", $validationErrors["temperature"][1] );
$this->assertEquals(
new Message( "FieldType 'ezfloat' is not searchable" ),
$validationErrors["temperature"][0]->getTranslatableMessage()
);
$this->assertEquals(
new Message(
"Validator parameter '%parameter%' value must be of numeric type",
array( "parameter" => "maxFloatValue" )
),
$validationErrors["temperature"][1]->getTranslatableMessage()
);
}
/**
* Test for the addFieldDefinition() method.
*
@@ -1438,7 +1577,7 @@ public function testAddFieldDefinitionThrowsBadStateExceptionNonRepeatableField(
/**
* Test for the addFieldDefinition() method.
*
* Testing that field definition of 'ezuser' field type can not be added to the ContentType that
* Testing adding field definition of the field type that can not be added to the ContentType that
* already has Content instances.
*
* @return void
@@ -1474,7 +1613,7 @@ public function testAddFieldDefinitionThrowsBadStateExceptionContentInstances()
$fieldDefCreate->fieldSettings = array();
$fieldDefCreate->isSearchable = false;
// Throws an exception because 'folder' ContentType has Content instances
// Throws an exception because 'ezuser' type field definition can't be added to ContentType that already has Content instances
$contentTypeService->addFieldDefinition( $folderContentTypeDraft, $fieldDefCreate );
/* END: Use Case */
}
@@ -15,7 +15,7 @@
/**
* This class is used for creating content types.
*
* @property $fieldDefinitions the collection of field definitions
* @property \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct[] $fieldDefinitions the collection of field definitions
*/
abstract class ContentTypeCreateStruct extends ValueObject
{
@@ -0,0 +1,19 @@
<?php
/**
* File containing the eZ\Publish\Core\Base\Exceptions\ContentTypeValidationException class.
*
* @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
*/
namespace eZ\Publish\Core\Base\Exceptions;
use eZ\Publish\API\Repository\Exceptions\ContentTypeValidationException as APIContentTypeValidationException;
/**
* This Exception is thrown on create or update content type when content type is not valid
*/
class ContentTypeValidationException extends APIContentTypeValidationException
{
}
@@ -315,7 +315,17 @@ public function isSearchable()
*/
public function isSingular()
{
return true;
return false;
}
/**
* Indicates if the field definition of this type can be added to a ContentType with Content instances.
*
* @return boolean
*/
public function onlyEmptyInstance()
{
return false;
}
/**
@@ -54,7 +54,17 @@ public function getName( SPIValue $value )
*/
public function isSingular()
{
return false;
return true;
}
/**
* Indicates if the field definition of this type can be added to a ContentType with Content instances.
*
* @return boolean
*/
public function onlyEmptyInstance()
{
return true;
}
/**
@@ -447,10 +447,12 @@ public function updateContentTypeDraft( ContentTypeDraft $contentTypeDraft, Cont
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier in already exists in the content type
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit a content type
* @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
* if a field definition in the $contentTypeCreateStruct is not valid
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If field definition of the same non-repeatable type is being
* added to the ContentType that already contains one
* or 'ezuser' type field definition is being added to the
* ContentType that has Content instances
* or field definition that can't be added to a ContentType that
* has Content instances is being added to such ContentType
*
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
* @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
@@ -132,6 +132,16 @@ public function isSingular()
return $this->innerFieldType->isSingular();
}
/**
* Indicates if the field definition of this type can be added to a ContentType with Content instances.
*
* @return boolean
*/
public function onlyEmptyInstance()
{
return $this->innerFieldType->onlyEmptyInstance();
}
/**
* Returns the fallback default value of field type when no such default
* value is provided in the field definition in content types.
Oops, something went wrong.

0 comments on commit 02adc86

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