Skip to content

Commit

Permalink
Merge pull request ezsystems#24 from cleverti/FieldType
Browse files Browse the repository at this point in the history
FieldType context
  • Loading branch information
andrerom committed May 28, 2015
2 parents 55bfe62 + d39ddb8 commit f0da6a0
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 0 deletions.
1 change: 1 addition & 0 deletions Context/EzContext.php
Expand Up @@ -23,6 +23,7 @@ class EzContext implements KernelAwareContext
use Object\ContentTypeGroup;
use Object\UserGroup;
use Object\User;
use Object\FieldType;

const DEFAULT_SITEACCESS_NAME = 'behat_site';

Expand Down
74 changes: 74 additions & 0 deletions Context/Object/FieldType.php
@@ -0,0 +1,74 @@
<?php
/**
*This file is part of the BehatBundle 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 EzSystems\BehatBundle\Context\Object;

use Behat\Gherkin\Node\TableNode;
use PHPUnit_Framework_Assert as Assertion;

/**
* Sentences for Fields
*/
trait FieldType
{
/**
* @Given a Content Type with an :fieldType Field exists
* @Given a Content Type with an :fieldType Field with Name :name exists
*
* Creates a ContentType with only the desired FieldType
*/
public function createContentTypeWithFieldType( $fieldType, $name = null )
{
return $this->getFieldTypeManager()->createField( $fieldType, $name );
}

/**
* @Given a Content Type with a required :fieldType Field exists
* @Given a Content Type with a required :fieldType Field with Name :name exists
*
* Creates a ContentType with only the desired FieldType
*/
public function createContentTypeWithRequiredFieldType( $fieldType, $name = null )
{
return $this->getFieldTypeManager()->createField( $fieldType, $name, true );
}

/**
* @Given a Content of this type exists
* @Given a Content of this type exists with :field Field Value set to :value
* @And a Content of this type exists
* @And a Content of this type exists with :field Field Value set to :value
*
* Creates a Content with the previously defined ContentType
*/
public function createContentOfThisType( $field = null, $value = null )
{
return $this->getFieldTypeManager()->createContent( $field, $value );
}

/**
* @Given a Content Type with an :fieldType Field exists with Properties:
* @Given a Content Type with an :fieldType Field with Name :name exists with Properties:
*/
public function createContentOfThisTypeWithProperties( $fieldType, TableNode $properties, $name = null )
{
$this->getFieldTypeManager()->createField( $fieldType, $name );
foreach ( $properties as $property )
{
if ( $property[ 'Validator' ] == 'maximum value validator' )
{
$this->getFieldTypeManager()->addValueConstraint( $fieldType, $property[ 'Value' ], "max" );
}
else if ( $property[ 'Validator' ] == 'minimum value validator' )
{
$this->getFieldTypeManager()->addValueConstraint( $fieldType, $property[ 'Value' ], "min" );
}
}
}
}

0 comments on commit f0da6a0

Please sign in to comment.