Merge branch 'master' into 'master'

Various improvements

- Introduce tests for twig functions ;
- Make the twig function `chill_custom_field_is_emtpy` consistent with other functions ;
- remove dead code from CustomFieldsHelper ;
- add validation on custom field slug
- fix bug in test
- re-introduce the units label in numeric/integer custom fields

See merge request !12
This commit is contained in:
Julien Fastré 2016-01-01 16:25:59 +01:00
commit b4ce83453c
16 changed files with 523 additions and 107 deletions

View File

@ -3,7 +3,8 @@ services:
before_script: before_script:
- composer config github-oauth.github.com $GITHUB_TOKEN - composer config github-oauth.github.com $GITHUB_TOKEN
- composer install --no-interaction - if [ $CI_BUILD_REF_NAME = "1.0" ] ; then export COMPOSER_ROOT_VERSION="1.0-dev"; else export COMPOSER_ROOT_VERSION="dev-master"; fi
- composer install --no-interaction --ignore-platform-reqs
- cp Tests/Fixtures/App/app/config/parameters.gitlab-ci.yml Tests/Fixtures/App/app/config/parameters.yml - cp Tests/Fixtures/App/app/config/parameters.gitlab-ci.yml Tests/Fixtures/App/app/config/parameters.yml
- ./console.sh --env=test cache:warmup - ./console.sh --env=test cache:warmup
- ./console.sh doctrine:migrations:migrate --env=test --no-interaction - ./console.sh doctrine:migrations:migrate --env=test --no-interaction
@ -11,7 +12,8 @@ before_script:
test:php-5.6: test:php-5.6:
stage: test stage: test
script: phpunit --testdox script: phpunit
test:php-7: test:php-7:
stage: test stage: test
script: phpunit --testdox image: chill/ci-image:php-7
script: phpunit

View File

@ -124,5 +124,5 @@ services:
class: Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository class: Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository
factory: ["@doctrine", getRepository] factory: ["@doctrine", getRepository]
arguments: arguments:
- "Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option" - "Chill\\CustomFieldsBundle\\Entity\\CustomFieldLongChoice\\Option"

View File

@ -0,0 +1,7 @@
Chill\CustomFieldsBundle\Entity\CustomField:
properties:
slug:
- Regex:
pattern: '/^[0-9a-z\-]{1,}$/'
message: Characters not allowed. Only lowercase letters, numbers and "-" are allowed.

View File

@ -0,0 +1 @@
Characters not allowed. Only lowercase letters, numbers and "-" are allowed.: Caractères non autorisés. Seules les lettres minuscules, les nombres et le tiret ("-") sont autorisés.

View File

@ -22,7 +22,7 @@
{%- endif -%} {%- endif -%}
{%- endif -%} {%- endif -%}
{% else %} {% else %}
{%- if show_empty == true or (chill_custom_field_is_empty(customField, cFData) == false) -%} {%- if show_empty == true or (chill_custom_field_is_empty(cFData, customField) == false) -%}
{%- if title is not empty -%} {%- if title is not empty -%}
{{ chill_custom_field_widget(cFData, title) }} {{ chill_custom_field_widget(cFData, title) }}
{%- set title = null -%} {%- set title = null -%}

View File

@ -80,5 +80,29 @@
</script> </script>
{% endblock cf_choices_row %} {% endblock cf_choices_row %}
{# extend the number type to add post_text extension #}
{% block number_widget %}
{%- if post_text is defined and post_text is not empty-%}
<div class="input_with_post_text">
{%- endif -%}
{{ block('form_widget') }}
{%- if post_text is defined and post_text is not empty-%}
<span class="post_text">{{ post_text }}</span>
</div>
{%- endif -%}
{% endblock %}
{# extend the number type to add post_text extension #}
{% block integer_widget %}
{%- if post_text is defined and post_text is not empty-%}
<div class="input_with_post_text">
{%- endif -%}
{{ block('form_widget') }}
{%- if post_text is defined and post_text is not empty-%}
<span class="post_text">{{ post_text }}</span>
</div>
{%- endif -%}
{% endblock %}
{# The choice_with_other_widget widget is defined in the main bundle #} {# The choice_with_other_widget widget is defined in the main bundle #}

View File

@ -45,10 +45,6 @@ class CustomFieldsHelper
* fields */ * fields */
private $provider; private $provider;
/** @var array $cache Matrix to cache all the custom fields. The array
* is indexed by the EntityClass then the slug */
private $cache = array();
/** /**
* Constructor * Constructor
* *
@ -63,83 +59,8 @@ class CustomFieldsHelper
$this->provider = $provider; $this->provider = $provider;
} }
/** public function isEmptyValue(array $fields, CustomField $customField)
* Set in cache all the custom fields of a given class containing some
* custom fields.
*
* @param object|string $class The given class.
* @todo check if this fucntions has to call _cacheCustomFieldsGroup instead of
* _cacheCustomFields ?
*/
private function _cacheCustomFields($class)
{ {
$customFieldsGroups = $this->em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->findBy(array('entity' => (is_string($class)) ? $class : get_class($class)));
if (!$customFieldsGroups) {
throw CustomFieldsHelperException::customFieldsGroupNotFound((is_string($class)) ? $class : get_class($class));
}
foreach ($customFieldsGroup as $cfGroup) {
$this->_cacheCustomFields($cfGroup);
}
}
/**
* Set in cache of the custom fields of a customfield Group.
*
* @param CustomFieldsGroup $group The given CustomFieldsGroup
*/
private function _cacheCustomFieldsGroup(CustomFieldsGroup $group)
{
foreach ($group->getCustomFields() as $field) {
$this->cache[$group->getEntity()][$field->getSlug()] = $field;
}
}
/**
* Return a requested customField
*
* @param object|string $class The requested class
* @param string $slug The slug. BEWARE If the slug is null, throw a proper CustomFieldsHelperException
* @return CustomField The requested CustomField
* @throws CustomFieldsHelperException if $slug is null
*/
public function getCustomField($class, $slug = null)
{
if (!$slug) {
throw CustomFieldsHelperException::slugIsMissing();
}
$resolveClass = (is_string($class)) ? $class : get_class($class);
if (!$this->cache[$resolveClass][$slug]) {
$this->_cacheCustomFields($resolveClass);
}
return $this->cache[$resolveClass][$slug];
}
/**
* Return the stored/raw value of a custom field.
*
* The method return null if the slug is not recorded.
*
* @param array $fields the **raw** array, as stored in the db
* @param object|string $class
* @param string $slug
* @return mixed|null The value or null if the slug is not recorded
*/
private function getCustomFieldValue(array $fields, $class, $slug)
{
return (isset($fields[$slug])) ? $this->provider
->getCustomFieldByType($this->getCustomField($class, $slug)->getType())
->deserialize($fields[$slug])
: null;
}
public function isEmptyValue(array $fields, $classOrCustomField, $slug = null)
{
$customField = ($classOrCustomField instanceof CustomField) ? $classOrCustomField : $this->getCustomField($classOrCustomField, $slug);
$slug = $customField->getSlug(); $slug = $customField->getSlug();
$rawValue = (isset($fields[$slug])) ? $fields[$slug] : null; $rawValue = (isset($fields[$slug])) ? $fields[$slug] : null;
@ -152,16 +73,13 @@ class CustomFieldsHelper
* Render the value of a custom field * Render the value of a custom field
* *
* @param array $fields the **raw** array, as stored in the db * @param array $fields the **raw** array, as stored in the db
* @param CustomField|object|string $classOrCustomField the object OR the get_class($object) string OR The CustomField * @param CustomField $customField the customField entity
* @param string $documentType The type of document in which the rendered value is displayed ('html' or 'csv'). * @param string $documentType The type of document in which the rendered value is displayed ('html' or 'csv').
* @param string $slug The slug of the custom field to render.
* @param boolean $showIfEmpty If the widget must be rendered if the value is empty. An empty value is all values described as http://php.net/manual/fr/function.empty.php, except `FALSE`
* @throws CustomFieldsHelperException if slug is missing * @throws CustomFieldsHelperException if slug is missing
* @return The representation of the value the customField. * @return The representation of the value the customField.
*/ */
public function renderCustomField(array $fields, $classOrCustomField, $documentType='html', $slug = null, $showIfEmpty = true) public function renderCustomField(array $fields, CustomField $customField, $documentType='html')
{ {
$customField = ($classOrCustomField instanceof CustomField) ? $classOrCustomField : $this->getCustomField($classOrCustomField, $slug);
$slug = $customField->getSlug(); $slug = $customField->getSlug();
$rawValue = (isset($fields[$slug])) ? $fields[$slug] : null; $rawValue = (isset($fields[$slug])) ? $fields[$slug] : null;
$customFieldType = $this->provider->getCustomFieldByType($customField->getType()); $customFieldType = $this->provider->getCustomFieldByType($customField->getType());

View File

@ -26,11 +26,11 @@ class CustomFieldsHelperException extends \Exception
{ {
public static function customFieldsGroupNotFound($entity) public static function customFieldsGroupNotFound($entity)
{ {
return new CustomFieldsRenderingException("The customFieldsGroups associated with $entity are not found"); return new CustomFieldsHelperException("The customFieldsGroups associated with $entity are not found");
} }
public static function slugIsMissing() public static function slugIsMissing()
{ {
return new CustomFieldsRenderingException("The slug is missing"); return new CustomFieldsHelperException("The slug is missing");
} }
} }

View File

@ -85,10 +85,10 @@ class CustomFieldRenderingTwig extends \Twig_Extension implements ContainerAware
} }
public function isEmptyValue($customFieldorClass, $fields, $slug = null) public function isEmptyValue($fields, CustomField $customField)
{ {
return $this->container->get('chill.custom_field.helper') return $this->container->get('chill.custom_field.helper')
->isEmptyValue($fields, $customFieldorClass); ->isEmptyValue($fields, $customField);
} }
/* (non-PHPdoc) /* (non-PHPdoc)
@ -102,19 +102,14 @@ class CustomFieldRenderingTwig extends \Twig_Extension implements ContainerAware
/** /**
* Twig Extension that is used to render the label of a custom field. * Twig Extension that is used to render the label of a custom field.
* *
* @param CustomField|object|string $customFieldOrClass Either a customField OR a customizable_entity OR the FQDN of the entity * @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param string $slug The slug ONLY necessary if the first argument is NOT a CustomField instance
* @param array $params The parameters for rendering. Currently, 'label_layout' allow to choose a different label. Default is 'ChillCustomFieldsBundle:CustomField:render_label.html.twig' * @param array $params The parameters for rendering. Currently, 'label_layout' allow to choose a different label. Default is 'ChillCustomFieldsBundle:CustomField:render_label.html.twig'
* @return string HTML representation of the custom field label. * @return string HTML representation of the custom field label.
*/ */
public function renderLabel($customFieldOrClass, $slug = null, array $params = array()) public function renderLabel(CustomField $customField, array $params = array())
{ {
$resolvedParams = array_merge($this->defaultParams, $params); $resolvedParams = array_merge($this->defaultParams, $params);
$customField = ($customFieldOrClass instanceof CustomField)
? $customFieldOrClass : $this->container->get('chill.custom_field.provider')
->getCustomField($customFieldOrClass, $slug);
return $this->container->get('templating') return $this->container->get('templating')
->render($resolvedParams['label_layout'], array('customField' => $customField)); ->render($resolvedParams['label_layout'], array('customField' => $customField));
} }
@ -125,14 +120,14 @@ class CustomFieldRenderingTwig extends \Twig_Extension implements ContainerAware
* The presentation of the value is influenced by the document type. * The presentation of the value is influenced by the document type.
* *
* @param array $fields The array raw, as stored in the db * @param array $fields The array raw, as stored in the db
* @param CustomField|object|string $customFieldOrClass Either a customField OR a customizable_entity OR the FQDN of the entity * @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param string $documentType The type of the document (csv, html) * @param string $documentType The type of the document (csv, html)
* @param string $slug The slug of the custom field ONLY necessary if the first argument is NOT a CustomField instance * @param string $slug The slug of the custom field ONLY necessary if the first argument is NOT a CustomField instance
* @return string HTML representation of the custom field value, as described in the CustomFieldInterface. Is HTML safe * @return string HTML representation of the custom field value, as described in the CustomFieldInterface. Is HTML safe
*/ */
public function renderWidget(array $fields, $customFieldOrClass, $documentType='html', $slug = null) public function renderWidget(array $fields, CustomField $customField, $documentType='html')
{ {
return $this->container->get('chill.custom_field.helper') return $this->container->get('chill.custom_field.helper')
->renderCustomField($fields, $customFieldOrClass, $documentType, $slug); ->renderCustomField($fields, $customField, $documentType);
} }
} }

View File

@ -51,7 +51,10 @@ class CustomFieldsGroupControllerTest extends WebTestCase
private function editCustomFieldsGroup(Client $client) private function editCustomFieldsGroup(Client $client)
{ {
$crawler = $client->request('GET', '/fr/admin/customfieldsgroup/'); $crawler = $client->request('GET', '/fr/admin/customfieldsgroup/');
$links = $crawler->selectLink('modifier'); $links = $crawler->selectLink('Modifier');
$this->assertGreaterThan(0, $links->count(),
"We can't find a 'Modifier' link on the index page");
$crawler = $client->click($links->last()->link()); $crawler = $client->click($links->last()->link());
$this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals(200, $client->getResponse()->getStatusCode());

View File

@ -0,0 +1,58 @@
<?php
/*
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFields\Tests\Form\Extension;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Test the post-text extension
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PostTextIntegerExtensionTest extends KernelTestCase
{
/**
*
* @var \Symfony\Component\Form\FormBuilderInterface
*/
private $formBuilder;
public function setUp()
{
self::bootKernel();
$container = self::$kernel->getContainer();
$this->formBuilder = $container->get('form.factory')
->createBuilder('form', null);
}
public function testCreateView()
{
$form = $this->formBuilder->add('test', 'integer', array(
'post_text' => 'my text'
))->getForm();
$view = $form->createView();
$this->assertEquals('my text', $view['test']->vars['post_text']);
}
}

View File

@ -0,0 +1,58 @@
<?php
/*
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFields\Tests\Form\Extension;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Test the post-text extension
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class PostTextNumberExtensionTest extends KernelTestCase
{
/**
*
* @var \Symfony\Component\Form\FormBuilderInterface
*/
private $formBuilder;
public function setUp()
{
self::bootKernel();
$container = self::$kernel->getContainer();
$this->formBuilder = $container->get('form.factory')
->createBuilder('form', null);
}
public function testCreateView()
{
$form = $this->formBuilder->add('test', 'number', array(
'post_text' => 'my text'
))->getForm();
$view = $form->createView();
$this->assertEquals('my text', $view['test']->vars['post_text']);
}
}

View File

@ -0,0 +1,92 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFields\Tests\Service;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
use Chill\CustomFieldsBundle\Entity\CustomField;
/**
* Tests for custom fields helper
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
class CustomFieldsHelperTest extends KernelTestCase
{
/**
*
* @var CustomFieldsHelper
*/
private $cfHelper;
/**
*
* @var CustomField
*/
private $randomCFText;
public function setUp()
{
self::bootKernel();
$container = self::$kernel->getContainer();
$this->cfHelper = $container->get('chill.custom_field.helper');
$this->randomCFText = (new CustomField())
->setSlug('my-slug')
->setActive(true)
->setName(array('fr' => 'my cf'))
->setOptions(array('maxLength' => 1000))
->setType('text')
;
}
public function testRenderCustomField()
{
$data = array(
$this->randomCFText->getSlug() => 'Sample text'
);
$text = $this->cfHelper->renderCustomField($data, $this->randomCFText);
$this->assertContains('Sample text', $text);
}
public function testIsEmptyValue()
{
// not empty value
$data = array(
$this->randomCFText->getSlug() => 'Sample text'
);
$this->assertFalse($this->cfHelper->isEmptyValue($data, $this->randomCFText));
//empty value
$data = array(
$this->randomCFText->getSlug() => ''
);
$this->assertTrue($this->cfHelper->isEmptyValue($data, $this->randomCFText));
}
}

View File

@ -0,0 +1,128 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFields\Tests\Templating\Twig;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldRenderingTwig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
/**
* Test the rendering of twig function which renders custom fields
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
class CustomFieldRenderingTwigTest extends KernelTestCase
{
/**
*
* @var CustomFieldRenderingTwig
*/
private $cfRendering;
/**
*
* @var CustomFieldProvider
*/
private $cfProvider;
public function setUp()
{
self::bootKernel();
$this->cfRendering = self::$kernel->getContainer()
->get('chill.custom_field.twig.custom_fields_rendering')
;
$this->cfProvider = self::$kernel->getContainer()
->get('chill.custom_field.provider');
// set locale to fr
$prophet = new \Prophecy\Prophet;
$request = $prophet->prophesize();
$request->willExtend('Symfony\Component\HttpFoundation\Request');
$request->getLocale()->willReturn('fr');
self::$kernel->getContainer()->get('request_stack')
->push($request->reveal());
}
/**
*
* @return CustomField
*/
private function getSimpleCustomFieldText()
{
return (new CustomField())
->setSlug('test')
->setName(array('fr' => 'Test'))
->setType('text')
->setOrdering(10)
->setOptions(array("maxLength" => 255))
->setActive(true)
;
}
public function testLabelRendering()
{
$cf = $this->getSimpleCustomFieldText();
$text = $this->cfRendering->renderLabel($cf);
$this->assertContains('Test', $text,
"The rendering text should contains the 'test' text");
}
public function testWidgetRendering()
{
$cf = $this->getSimpleCustomFieldText();
$fields = array(
'test' => "My tailor is rich"
);
$text = $this->cfRendering->renderWidget($fields, $cf);
$this->assertContains('My tailor is rich', $text,
"The rendering text should contains the 'test' text");
}
public function testIsEmpty()
{
$cf = $this->getSimpleCustomFieldText();
// value is not empty
$fields = array(
'test' => "My tailor is rich"
);
$result = $this->cfRendering->isEmptyValue($fields, $cf);
$this->assertFalse($result);
// value is empty
$fields = array(
'text' => ''
);
$result = $this->cfRendering->isEmptyValue($fields, $cf);
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,130 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs Libres <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFields\Tests\Templating\Twig;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldsGroupRenderingTwig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
/**
* Test the rendering of a custom fields group through
* the `chill_custom_fields_group_widget`
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
*/
class CustomFieldsGroupRenderingTwigTest extends KernelTestCase
{
/**
*
* @var CustomFieldsGroupRenderingTwig
*/
private $cfRendering;
/**
*
* @var CustomFieldProvider
*/
private $cfProvider;
public function setUp()
{
self::bootKernel();
$this->cfRendering = self::$kernel->getContainer()
->get('chill.custom_field.twig.custom_fields_group_rendering')
;
$this->cfProvider = self::$kernel->getContainer()
->get('chill.custom_field.provider');
// set locale to fr
$prophet = new \Prophecy\Prophet;
$request = $prophet->prophesize();
$request->willExtend('Symfony\Component\HttpFoundation\Request');
$request->getLocale()->willReturn('fr');
self::$kernel->getContainer()->get('request_stack')
->push($request->reveal());
}
/**
*
* @return CustomField
*/
private function getSimpleCustomFieldText($slug, $name)
{
return (new CustomField())
->setSlug($slug)
->setName(array('fr' => $name))
->setType('text')
->setOrdering(10)
->setOptions(array("maxLength" => 255))
->setActive(true)
;
}
/**
*
* @return CustomFieldsGroup
*/
private function getCustomFieldsGroup()
{
return (new CustomFieldsGroup())
->setEntity('\Dummy')
->setName(array("fr" => "A cf group"))
->addCustomField($this->getSimpleCustomFieldText("horses", "Do you like horses ?."))
->addCustomField($this->getSimpleCustomFieldText("sure", "Are you sure ?"))
;
}
public function testRenderingWidget()
{
$cfGroup = $this->getCustomFieldsGroup();
$text = $this->cfRendering->renderWidget(array(
'horses' => 'I like horses',
'sure' => 'Yes !'
), $cfGroup);
$this->assertContains('Do you like horses', $text);
$this->assertContains('I like horses', $text);
$this->assertContains('Are you sure', $text);
$this->assertContains('Yes', $text);
}
public function testRenderingWidgetDoNotShowEmpty()
{
$cfGroup = $this->getCustomFieldsGroup();
$cfGroup->addCustomField($this->getSimpleCustomFieldText('empty', 'Do not answer'));
$text = $this->cfRendering->renderWidget(array(
'horses' => 'I like horses',
'sure' => 'Yes !'
), $cfGroup, 'html', array('show_empty' => false));
$this->assertContains('Do you like horses', $text);
$this->assertContains('I like horses', $text);
$this->assertContains('Are you sure', $text);
$this->assertContains('Yes', $text);
$this->assertNotContains('Do not answer', $text);
}
}

View File

@ -16,8 +16,8 @@
} }
], ],
"require": { "require": {
"php": "~5.5", "php": "~5.5|~7.0",
"symfony/symfony": "~2.7", "symfony/symfony": "~2.8",
"doctrine/orm": "~2.4", "doctrine/orm": "~2.4",
"doctrine/dbal" : "~2.5", "doctrine/dbal" : "~2.5",
"doctrine/common": "~2.4", "doctrine/common": "~2.4",