Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldType context #24

Merged
merged 14 commits into from
May 28, 2015
1 change: 1 addition & 0 deletions Context/EzContext.php
Original file line number Diff line number Diff line change
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
84 changes: 84 additions & 0 deletions Context/Object/FieldType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* File containing the Content Type context
*
* @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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem to do anything else then method above, missing something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One creates a required field, the other one a non-required one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was missing the true and thought the line where completely the same, indeed :)

}

/**
* @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" );
}
}
}

/**
* @Then I should have an "integer" field
*
* Creates a Content with the previously defined ContentType
*/
public function verifyContentOfType()
{
// return $this->getFieldTypeManager()->executeDelayedOperations();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not doing anything?

}
}
Loading