mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,21 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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/>.
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests\Config;
|
||||
@@ -23,48 +12,49 @@ namespace Chill\CustomFieldsBundle\Tests\Config;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Test the option Customizables_entities
|
||||
* Test the option Customizables_entities.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ConfigCustomizablesEntitiesTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* Test that the config does work if the option
|
||||
* chill_custom_fields.customizables_entities IS NOT present
|
||||
*
|
||||
* In this case, parameter 'chill_custom_fields.customizables_entities'
|
||||
* should be an empty array in container
|
||||
*/
|
||||
public function testNotPresentInConfig()
|
||||
{
|
||||
self::bootKernel(array('environment' => 'test'));
|
||||
$customizableEntities = static::$kernel->getContainer()
|
||||
->getParameter('chill_custom_fields.customizables_entities');
|
||||
|
||||
$this->assertInternalType('array', $customizableEntities);
|
||||
$this->assertCount(1, $customizableEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the 'chill_custom_fields.customizables_entities' is filled
|
||||
* correctly with a minimal configuration.
|
||||
*
|
||||
*
|
||||
* @internal use a custom config environment
|
||||
*/
|
||||
public function testNotEmptyConfig()
|
||||
{
|
||||
self::bootKernel(array('environment' => 'test_customizable_entities_test_not_empty_config'));
|
||||
self::bootKernel(['environment' => 'test_customizable_entities_test_not_empty_config']);
|
||||
$customizableEntities = static::$kernel->getContainer()
|
||||
->getParameter('chill_custom_fields.customizables_entities');
|
||||
|
||||
->getParameter('chill_custom_fields.customizables_entities');
|
||||
|
||||
$this->assertInternalType('array', $customizableEntities);
|
||||
$this->assertCount(2, $customizableEntities);
|
||||
|
||||
foreach($customizableEntities as $key => $config) {
|
||||
|
||||
foreach ($customizableEntities as $key => $config) {
|
||||
$this->assertInternalType('array', $config);
|
||||
$this->assertArrayHasKey('name', $config);
|
||||
$this->assertArrayHasKey('class', $config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the config does work if the option
|
||||
* chill_custom_fields.customizables_entities IS NOT present.
|
||||
*
|
||||
* In this case, parameter 'chill_custom_fields.customizables_entities'
|
||||
* should be an empty array in container
|
||||
*/
|
||||
public function testNotPresentInConfig()
|
||||
{
|
||||
self::bootKernel(['environment' => 'test']);
|
||||
$customizableEntities = static::$kernel->getContainer()
|
||||
->getParameter('chill_custom_fields.customizables_entities');
|
||||
|
||||
$this->assertInternalType('array', $customizableEntities);
|
||||
$this->assertCount(1, $customizableEntities);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldControllerTest extends WebTestCase
|
||||
{
|
||||
/*
|
||||
@@ -51,5 +62,5 @@ class CustomFieldControllerTest extends WebTestCase
|
||||
$this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
@@ -1,21 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Client;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldsGroupControllerTest extends WebTestCase
|
||||
{
|
||||
|
||||
public function testCompleteScenario()
|
||||
{
|
||||
self::bootKernel(array('environment' => 'test_customizable_entities_test_not_empty_config'));
|
||||
self::bootKernel(['environment' => 'test_customizable_entities_test_not_empty_config']);
|
||||
// Create a new client to browse the application
|
||||
$client = static::createClient(array(), array(
|
||||
$client = static::createClient([], [
|
||||
'PHP_AUTH_USER' => 'admin',
|
||||
'PHP_AUTH_PW' => 'olala',
|
||||
));
|
||||
'PHP_AUTH_PW' => 'olala',
|
||||
]);
|
||||
|
||||
//create the entity
|
||||
$this->createCustomFieldsGroup($client);
|
||||
@@ -28,47 +38,59 @@ class CustomFieldsGroupControllerTest extends WebTestCase
|
||||
{
|
||||
// Create a new entry in the database
|
||||
$crawler = $client->request('GET', '/fr/admin/customfieldsgroup/');
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(),
|
||||
"Unexpected HTTP status code for GET /customfieldsgroup/");
|
||||
|
||||
$this->assertEquals(
|
||||
200,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
'Unexpected HTTP status code for GET /customfieldsgroup/'
|
||||
);
|
||||
|
||||
$crawler = $client->click($crawler->selectLink('Créer un nouveau groupe')->link());
|
||||
|
||||
|
||||
// Fill in the form and submit it
|
||||
$form = $crawler->selectButton('Créer')->form(array(
|
||||
'custom_fields_group[name][fr]' => 'Test',
|
||||
'custom_fields_group[entity]' => 'Chill\PersonBundle\Entity\Person'
|
||||
));
|
||||
$form = $crawler->selectButton('Créer')->form([
|
||||
'custom_fields_group[name][fr]' => 'Test',
|
||||
'custom_fields_group[entity]' => 'Chill\PersonBundle\Entity\Person',
|
||||
]);
|
||||
|
||||
$crawler = $client->submit($form);
|
||||
|
||||
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check data in the show view
|
||||
$this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(),
|
||||
'Missing element td:contains("Test")');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('td:contains("Test")')->count(),
|
||||
'Missing element td:contains("Test")'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function editCustomFieldsGroup(Client $client)
|
||||
{
|
||||
$crawler = $client->request('GET', '/fr/admin/customfieldsgroup/');
|
||||
$links = $crawler->selectLink('Modifier');
|
||||
|
||||
$this->assertGreaterThan(0, $links->count(),
|
||||
"We can't find a 'Modifier' link on the index page");
|
||||
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$links->count(),
|
||||
"We can't find a 'Modifier' link on the index page"
|
||||
);
|
||||
$crawler = $client->click($links->last()->link());
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$form = $crawler->selectButton('Mettre à jour')->form(array(
|
||||
'custom_fields_group[name][fr]' => 'Foo',
|
||||
));
|
||||
|
||||
$form = $crawler->selectButton('Mettre à jour')->form([
|
||||
'custom_fields_group[name][fr]' => 'Foo',
|
||||
]);
|
||||
|
||||
$client->submit($form);
|
||||
$crawler = $client->followRedirect();
|
||||
|
||||
// Check the element contains an attribute with value equals "Foo"
|
||||
$this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(),
|
||||
'Missing element [value="Foo"]');
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
$crawler->filter('[value="Foo"]')->count(),
|
||||
'Missing element [value="Foo"]'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,86 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 Champs-Libres Coopérative <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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
/**
|
||||
* Give useful method to prepare tests regarding custom fields
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Give useful method to prepare tests regarding custom fields.
|
||||
*/
|
||||
trait CustomFieldTestHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Prepare a crawler containing the rendering of a customField
|
||||
*
|
||||
* Prepare a crawler containing the rendering of a customField.
|
||||
*
|
||||
* @internal This method will mock a customFieldGroup containing $field, and
|
||||
* rendering the customfield, using Type\CustomFieldType, to a simple form row
|
||||
*
|
||||
* @param CustomField $field
|
||||
* @param KernelTestCase $testCase
|
||||
* @param KernelInterface $kernel
|
||||
*
|
||||
* @param type $locale
|
||||
*
|
||||
* @return Crawler
|
||||
*/
|
||||
public function getCrawlerForField(CustomField $field, $locale = 'en')
|
||||
{
|
||||
$kernel = static::$kernel;
|
||||
|
||||
|
||||
//check a kernel is accessible
|
||||
$customFieldsGroup = $this->createMock('Chill\CustomFieldsBundle\Entity\CustomFieldsGroup');
|
||||
$customFieldsGroup->expects($this->once())
|
||||
->method('getActiveCustomFields')
|
||||
->will($this->returnValue(array($field)));
|
||||
|
||||
->will($this->returnValue([$field]));
|
||||
|
||||
$request = $this->createMock('Symfony\Component\HttpFoundation\Request');
|
||||
$request->expects($this->any())
|
||||
->method('getLocale')
|
||||
->will($this->returnValue($locale));
|
||||
|
||||
$kernel->getContainer()->get('request_stack')->push($request);
|
||||
|
||||
|
||||
$builder = $kernel->getContainer()->get('form.factory')->createBuilder();
|
||||
$form = $builder->add('tested', 'custom_field',
|
||||
array('group' => $customFieldsGroup))
|
||||
$form = $builder->add(
|
||||
'tested',
|
||||
'custom_field',
|
||||
['group' => $customFieldsGroup]
|
||||
)
|
||||
->getForm();
|
||||
|
||||
|
||||
$kernel->getContainer()->get('twig.loader')
|
||||
->addPath($kernel->getContainer()->getParameter('kernel.root_dir').
|
||||
->addPath($kernel->getContainer()->getParameter('kernel.root_dir') .
|
||||
'/Resources/views/', $namespace = 'test');
|
||||
|
||||
$content = $kernel
|
||||
->getContainer()->get('templating')
|
||||
->render('@test/CustomField/simple_form_render.html.twig', array(
|
||||
->render('@test/CustomField/simple_form_render.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'inputKeys' => array('tested')
|
||||
));
|
||||
'inputKeys' => ['tested'],
|
||||
]);
|
||||
|
||||
$crawler = new Crawler();
|
||||
$crawler->addHtmlContent($content);
|
||||
|
||||
|
||||
return $crawler;
|
||||
}
|
||||
}
|
||||
|
@@ -1,69 +1,443 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* This class cover the test of CustomFieldChoice.
|
||||
*
|
||||
* Function currently covered:
|
||||
*
|
||||
*
|
||||
* Function currently covered:
|
||||
*
|
||||
* - deserialize
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldsChoiceTest extends KernelTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\CustomFieldsBundle\Service\CustomFieldProvider
|
||||
*/
|
||||
private $cfProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice
|
||||
*/
|
||||
private $cfChoice;
|
||||
|
||||
|
||||
/**
|
||||
* @var \Chill\CustomFieldsBundle\Service\CustomFieldProvider
|
||||
*/
|
||||
private $cfProvider;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
|
||||
|
||||
$this->cfProvider = static::$kernel->getContainer()
|
||||
->get('chill.custom_field.provider');
|
||||
->get('chill.custom_field.provider');
|
||||
$this->cfChoice = $this->cfProvider->getCustomFieldByType('choice');
|
||||
}
|
||||
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* provide empty data in different possible representations.
|
||||
* Those data are supposed to be deserialized.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emptyDataProvider()
|
||||
{
|
||||
return [
|
||||
// 0
|
||||
[
|
||||
// signle
|
||||
'',
|
||||
],
|
||||
// 1
|
||||
[
|
||||
// single
|
||||
null,
|
||||
],
|
||||
// 2
|
||||
[
|
||||
// signle with allow other
|
||||
['_other' => 'something', '_choices' => ''],
|
||||
],
|
||||
// 3
|
||||
[
|
||||
// multiple
|
||||
[],
|
||||
],
|
||||
// 4
|
||||
[
|
||||
// multiple with allow other
|
||||
['_other' => 'something', '_choices' => []],
|
||||
],
|
||||
// 5
|
||||
[
|
||||
// multiple with allow other
|
||||
['_other' => '', '_choices' => []],
|
||||
],
|
||||
// 6
|
||||
[
|
||||
// empty
|
||||
['_other' => null, '_choices' => null],
|
||||
],
|
||||
// 7
|
||||
[
|
||||
// empty
|
||||
[null],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function serializedRepresentationDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
// multiple => false, allow_other => false
|
||||
'my-value',
|
||||
],
|
||||
[
|
||||
// multiple => true, allow_ther => false
|
||||
['my-value'],
|
||||
],
|
||||
[
|
||||
// multiple => false, allow_other => true, current value not in other
|
||||
['_other' => '', '_choices' => 'my-value'],
|
||||
],
|
||||
[
|
||||
// multiple => true, allow_other => true, current value not in other
|
||||
['_other' => '', '_choices' => ['my-value']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* This test does not covers the case when the selected value is `_other`
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(
|
||||
['_other' => '', '_choices' => ['my-value']],
|
||||
$deserialized
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* This test covers :
|
||||
* - the case when the selected value is `_other`
|
||||
* - result is null
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
// selected value is _other
|
||||
// from single to multiple
|
||||
$data = ['_other' => 'something', '_choices' => '_other'];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(
|
||||
['_other' => 'something', '_choices' => ['_other']],
|
||||
$deserialized
|
||||
);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = ['_other' => 'something', '_choices' => ['_other', 'something']];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(
|
||||
['_other' => 'something', '_choices' => ['_other', 'something']],
|
||||
$deserialized
|
||||
);
|
||||
|
||||
// test with null value
|
||||
// from single to multiple
|
||||
$data = ['_other' => '', '_choices' => ''];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(
|
||||
['_other' => '', '_choices' => ['']],
|
||||
$deserialized
|
||||
);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = ['_other' => '', '_choices' => []];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(
|
||||
['_other' => '', '_choices' => []],
|
||||
$deserialized
|
||||
);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => null], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => [null]], $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => ''], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => ['']], $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize([null], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => [null]], $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* **without** an "allow_other" field.
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithoutOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(['my-value'], $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* **without** an "allow_other" field.
|
||||
*
|
||||
* Covered cases :
|
||||
* - NULL values
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithoutOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
// from single to multiple
|
||||
$data = 'my-value';
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['my-value'], $deserialized);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = ['my-value'];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['my-value'], $deserialized);
|
||||
|
||||
// from multiple
|
||||
$data = [null];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame([null], $deserialized);
|
||||
|
||||
$data = ['_other' => null, '_choices' => [null]];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame([null], $deserialized);
|
||||
|
||||
//from single
|
||||
$data = ['_other' => null, '_choices' => null];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame([null], $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to a single text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* If the value is in _other, the _other value should be in the _other field.
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => false,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(['_other' => '', '_choices' => 'my-value'], $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Other cases :.
|
||||
*
|
||||
* - Test if the selected value is '_other
|
||||
* - Test with null data
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => false,
|
||||
]);
|
||||
|
||||
// from a single to a single
|
||||
$data = ['_other' => 'something', '_choices' => '_other'];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => '_other'], $deserialized);
|
||||
|
||||
// from a multiple to a single
|
||||
$data = ['_other' => 'something', '_choices' => ['some', '_other']];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => '_other'], $deserialized);
|
||||
|
||||
//test with null data
|
||||
//from a single to a single :
|
||||
$data = ['_other' => 'something', '_choices' => null];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => null], $deserialized);
|
||||
|
||||
$data = ['_other' => 'something', '_choices' => ''];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => ''], $deserialized);
|
||||
|
||||
// from a multiple to a signle
|
||||
$data = ['_other' => 'something', '_choices' => []];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => ''], $deserialized);
|
||||
|
||||
$data = ['_other' => 'something', '_choices' => ['']];
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(['_other' => 'something', '_choices' => ''], $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => null], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => null], $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => ''], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => ''], $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize([null], $customField);
|
||||
$this->assertSame(['_other' => '', '_choices' => null], $deserialized);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
//
|
||||
// test function deserialize
|
||||
//
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to a single text.
|
||||
*
|
||||
* If the value is in _other, the _other value should not be returned.
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithoutOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => false,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame('my-value', $deserialized);
|
||||
}
|
||||
|
||||
public function testDeserializeSingleChoiceWithoutOtherDataIsNull()
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => false,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(null, $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize('', $customField);
|
||||
$this->assertSame('', $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize([null], $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => null], $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(['_other' => null, '_choices' => ''], $customField);
|
||||
$this->assertSame('', $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize([null], $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider emptyDataProvider
|
||||
*
|
||||
* @param mixed $data deserialized data
|
||||
*/
|
||||
public function testIsEmptyValueEmpty($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
$isEmpty = $this->cfChoice->isEmptyValue($data, $customField);
|
||||
|
||||
$this->assertTrue($isEmpty);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
//
|
||||
// test function isEmptyValue
|
||||
//
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* test the not empty with the not-empty data provider.
|
||||
*
|
||||
* @param mixed $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testIsEmptyValueNotEmpty($data)
|
||||
{
|
||||
$customField = $this->generateCustomField([
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true,
|
||||
]);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$isEmpty = $this->cfChoice->isEmptyValue($deserialized, $customField);
|
||||
|
||||
$this->assertFalse($isEmpty);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return CustomField
|
||||
*/
|
||||
private function generateCustomField($options)
|
||||
@@ -72,397 +446,6 @@ class CustomFieldsChoiceTest extends KernelTestCase
|
||||
->setActive(true)
|
||||
->setSlug('slug')
|
||||
->setOptions($options)
|
||||
->setType('choice')
|
||||
;
|
||||
->setType('choice');
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
//
|
||||
// test function deserialize
|
||||
//
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to a single text.
|
||||
*
|
||||
* If the value is in _other, the _other value should not be returned.
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithoutOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => false
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame('my-value', $deserialized);
|
||||
}
|
||||
|
||||
|
||||
public function testDeserializeSingleChoiceWithoutOtherDataIsNull()
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => false
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(null, $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize('', $customField);
|
||||
$this->assertSame('', $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array(null), $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => null), $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => ''), $customField);
|
||||
$this->assertSame('', $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array(null), $customField);
|
||||
$this->assertSame(null, $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to a single text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* If the value is in _other, the _other value should be in the _other field.
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => false
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => '', '_choices' => 'my-value'), $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Other cases :
|
||||
*
|
||||
* - Test if the selected value is '_other
|
||||
* - Test with null data
|
||||
*
|
||||
* @param type $data
|
||||
*/
|
||||
public function testDeserializeSingleChoiceWithOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => false
|
||||
));
|
||||
|
||||
// from a single to a single
|
||||
$data = array('_other' => 'something', '_choices' => '_other');
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => '_other'), $deserialized);
|
||||
|
||||
|
||||
// from a multiple to a single
|
||||
$data = array('_other' => 'something', '_choices' => array('some', '_other'));
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => '_other'), $deserialized);
|
||||
|
||||
//test with null data
|
||||
//from a single to a single :
|
||||
$data = array('_other' => 'something', '_choices' => null);
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => null), $deserialized);
|
||||
|
||||
$data = array('_other' => 'something', '_choices' => '');
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => ''), $deserialized);
|
||||
|
||||
// from a multiple to a signle
|
||||
$data = array('_other' => 'something', '_choices' => array());
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => ''), $deserialized);
|
||||
|
||||
$data = array('_other' => 'something', '_choices' => array(''));
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => ''), $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => null), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => null), $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => ''), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => ''), $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array(null), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => null), $deserialized);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* This test does not covers the case when the selected value is `_other`
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => '', '_choices' => array('my-value')),
|
||||
$deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* with an "allow_other" field.
|
||||
*
|
||||
* This test covers :
|
||||
* - the case when the selected value is `_other`
|
||||
* - result is null
|
||||
*
|
||||
* @param type $data
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => true,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
// selected value is _other
|
||||
// from single to multiple
|
||||
$data = array('_other' => 'something', '_choices' => '_other');
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => array('_other')),
|
||||
$deserialized);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = array('_other' => 'something', '_choices' => array('_other', 'something'));
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => 'something', '_choices' => array('_other', 'something')),
|
||||
$deserialized);
|
||||
|
||||
// test with null value
|
||||
// from single to multiple
|
||||
$data = array('_other' => '', '_choices' => '');
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => '', '_choices' => array('')),
|
||||
$deserialized);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = array('_other' => '', '_choices' => array());
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('_other' => '', '_choices' => array()),
|
||||
$deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => null), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => array(null)), $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array('_other' => null, '_choices' => ''), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => array('')), $deserialized);
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize(array(null), $customField);
|
||||
$this->assertSame(array('_other' => '', '_choices' => array(null)), $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* **without** an "allow_other" field.
|
||||
*
|
||||
*
|
||||
* @param type $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithoutOther($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
|
||||
$this->assertSame(array('my-value'), $deserialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the representation of the data is deserialized to an array text
|
||||
* **without** an "allow_other" field.
|
||||
*
|
||||
* Covered cases :
|
||||
* - NULL values
|
||||
*
|
||||
*
|
||||
* @param type $data
|
||||
*/
|
||||
public function testDeserializeMultipleChoiceWithoutOtherOtherCases()
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
// from single to multiple
|
||||
$data = 'my-value';
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('my-value'), $deserialized);
|
||||
|
||||
// from multiple to multiple
|
||||
$data = array('my-value');
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array('my-value'), $deserialized);
|
||||
|
||||
// from multiple
|
||||
$data = array(null);
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array(null), $deserialized);
|
||||
|
||||
$data = array('_other' => null, '_choices' => array(null));
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array(null), $deserialized);
|
||||
|
||||
//from single
|
||||
$data = array('_other' => null, '_choices' => null);
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$this->assertSame(array(null), $deserialized);
|
||||
}
|
||||
|
||||
public function serializedRepresentationDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
// multiple => false, allow_other => false
|
||||
'my-value'
|
||||
),
|
||||
array(
|
||||
// multiple => true, allow_ther => false
|
||||
array('my-value')
|
||||
),
|
||||
array(
|
||||
// multiple => false, allow_other => true, current value not in other
|
||||
array('_other' => '', '_choices' => 'my-value')
|
||||
),
|
||||
array(
|
||||
// multiple => true, allow_other => true, current value not in other
|
||||
array('_other' => '', '_choices'=> array('my-value'))
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////
|
||||
//
|
||||
// test function isEmptyValue
|
||||
//
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* test the not empty with the not-empty data provider
|
||||
*
|
||||
* @param mixed $data
|
||||
* @dataProvider serializedRepresentationDataProvider
|
||||
*/
|
||||
public function testIsEmptyValueNotEmpty($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
$deserialized = $this->cfChoice->deserialize($data, $customField);
|
||||
$isEmpty = $this->cfChoice->isEmptyValue($deserialized, $customField);
|
||||
|
||||
$this->assertFalse($isEmpty);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider emptyDataProvider
|
||||
* @param mixed $data deserialized data
|
||||
*/
|
||||
public function testIsEmptyValueEmpty($data)
|
||||
{
|
||||
$customField = $this->generateCustomField(array(
|
||||
CustomFieldChoice::ALLOW_OTHER => false,
|
||||
CustomFieldChoice::MULTIPLE => true
|
||||
));
|
||||
|
||||
$isEmpty = $this->cfChoice->isEmptyValue($data, $customField);
|
||||
|
||||
$this->assertTrue($isEmpty);
|
||||
}
|
||||
|
||||
/**
|
||||
* provide empty data in different possible representations.
|
||||
* Those data are supposed to be deserialized.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emptyDataProvider()
|
||||
{
|
||||
return array(
|
||||
// 0
|
||||
array(
|
||||
// signle
|
||||
''
|
||||
),
|
||||
// 1
|
||||
array(
|
||||
// single
|
||||
null
|
||||
),
|
||||
// 2
|
||||
array(
|
||||
// signle with allow other
|
||||
array('_other' => 'something', '_choices' => '')
|
||||
),
|
||||
// 3
|
||||
array(
|
||||
// multiple
|
||||
array()
|
||||
),
|
||||
// 4
|
||||
array(
|
||||
// multiple with allow other
|
||||
array('_other' => 'something', '_choices' => array())
|
||||
),
|
||||
// 5
|
||||
array(
|
||||
// multiple with allow other
|
||||
array('_other' => '', '_choices' => array())
|
||||
),
|
||||
// 6
|
||||
array(
|
||||
// empty
|
||||
array('_other' => null, '_choices' => null)
|
||||
),
|
||||
// 7
|
||||
array(
|
||||
// empty
|
||||
array(null)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,45 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests;
|
||||
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldNumber;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
use Chill\CustomFieldsBundle\Form\CustomFieldsGroupType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Test CustomFieldsNumber
|
||||
* Test CustomFieldsNumber.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldNumber
|
||||
*/
|
||||
private $customFieldNumber;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var FormBuilderInterface
|
||||
*/
|
||||
private $formBuilder;
|
||||
@@ -49,26 +36,135 @@ class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTes
|
||||
self::bootKernel();
|
||||
|
||||
$this->customFieldNumber = self::$kernel->getContainer()
|
||||
->get('chill.custom_field.number');
|
||||
->get('chill.custom_field.number');
|
||||
|
||||
$this->formBuilder = self::$kernel->getContainer()
|
||||
->get('form.factory')
|
||||
->createBuilder('form', null, array(
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token'
|
||||
));
|
||||
->get('form.factory')
|
||||
->createBuilder('form', null, [
|
||||
'csrf_protection' => false,
|
||||
'csrf_field_name' => '_token',
|
||||
]);
|
||||
|
||||
$request = new \Symfony\Component\HttpFoundation\Request();
|
||||
$request->setLocale('fr');
|
||||
|
||||
self::$kernel->getContainer()
|
||||
->get('request_stack')
|
||||
->push($request);
|
||||
->get('request_stack')
|
||||
->push($request);
|
||||
}
|
||||
|
||||
public function testCreateInvalidFormValueGreaterThanMaximum()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber([
|
||||
'min' => null,
|
||||
'max' => 10,
|
||||
'scale' => null,
|
||||
'post_text' => null,
|
||||
]);
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(['default' => 100]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertFalse($form->isValid());
|
||||
$this->assertEquals(1, count($form['default']->getErrors()));
|
||||
}
|
||||
|
||||
public function testCreateInvalidFormValueLowerThanMinimum()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber([
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null,
|
||||
]);
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(['default' => 100]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertFalse($form->isValid());
|
||||
$this->assertEquals(1, count($form['default']->getErrors()));
|
||||
}
|
||||
|
||||
public function testCreateValidForm()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber([
|
||||
'min' => null,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null,
|
||||
]);
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(['default' => 10]);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals(10, $form['default']->getData());
|
||||
}
|
||||
|
||||
public function testRequiredFieldIsFalse()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber([
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null,
|
||||
]);
|
||||
$cf->setRequired(false);
|
||||
|
||||
$cfGroup = (new \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup())
|
||||
->addCustomField($cf);
|
||||
|
||||
$form = static::$kernel->getContainer()->get('form.factory')
|
||||
->createBuilder(\Chill\CustomFieldsBundle\Form\Type\CustomFieldType::class, [], [
|
||||
'group' => $cfGroup,
|
||||
])
|
||||
->getForm();
|
||||
|
||||
$this->assertFalse(
|
||||
$form['default']->isRequired(),
|
||||
'The field should not be required'
|
||||
);
|
||||
}
|
||||
|
||||
public function testRequiredFieldIsTrue()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber([
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null,
|
||||
]);
|
||||
$cf->setRequired(true);
|
||||
|
||||
$cfGroup = (new \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup())
|
||||
->addCustomField($cf);
|
||||
|
||||
$form = static::$kernel->getContainer()->get('form.factory')
|
||||
->createBuilder(\Chill\CustomFieldsBundle\Form\Type\CustomFieldType::class, [], [
|
||||
'group' => $cfGroup,
|
||||
])
|
||||
->getForm();
|
||||
|
||||
$this->assertTrue(
|
||||
$form['default']->isRequired(),
|
||||
'The field should be required'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed[] $options
|
||||
*
|
||||
* @return CustomField
|
||||
*/
|
||||
private function createCustomFieldNumber($options)
|
||||
@@ -78,114 +174,7 @@ class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTes
|
||||
->setActive(true)
|
||||
->setOrdering(10)
|
||||
->setSlug('default')
|
||||
->setName(array('fr' => 'default'))
|
||||
->setName(['fr' => 'default'])
|
||||
->setOptions($options);
|
||||
}
|
||||
|
||||
public function testCreateValidForm()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber(array(
|
||||
'min' => null,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null
|
||||
));
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(array('default' => 10));
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertEquals(10, $form['default']->getData());
|
||||
}
|
||||
|
||||
public function testCreateInvalidFormValueGreaterThanMaximum()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber(array(
|
||||
'min' => null,
|
||||
'max' => 10,
|
||||
'scale' => null,
|
||||
'post_text' => null
|
||||
));
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(array('default' => 100));
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertFalse($form->isValid());
|
||||
$this->assertEquals(1, count($form['default']->getErrors()));
|
||||
}
|
||||
|
||||
public function testCreateInvalidFormValueLowerThanMinimum()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber(array(
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null
|
||||
));
|
||||
|
||||
$this->customFieldNumber->buildForm($this->formBuilder, $cf);
|
||||
|
||||
$form = $this->formBuilder->getForm();
|
||||
|
||||
$form->submit(array('default' => 100));
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertFalse($form->isValid());
|
||||
$this->assertEquals(1, count($form['default']->getErrors()));
|
||||
}
|
||||
|
||||
public function testRequiredFieldIsFalse()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber(array(
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null
|
||||
));
|
||||
$cf->setRequired(false);
|
||||
|
||||
$cfGroup = (new \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup())
|
||||
->addCustomField($cf);
|
||||
|
||||
$form = static::$kernel->getContainer()->get('form.factory')
|
||||
->createBuilder(\Chill\CustomFieldsBundle\Form\Type\CustomFieldType::class, array(), array(
|
||||
'group' => $cfGroup
|
||||
))
|
||||
->getForm();
|
||||
|
||||
$this->assertFalse($form['default']->isRequired(),
|
||||
"The field should not be required");
|
||||
}
|
||||
|
||||
public function testRequiredFieldIsTrue()
|
||||
{
|
||||
$cf = $this->createCustomFieldNumber(array(
|
||||
'min' => 1000,
|
||||
'max' => null,
|
||||
'scale' => null,
|
||||
'post_text' => null
|
||||
));
|
||||
$cf->setRequired(true);
|
||||
|
||||
$cfGroup = (new \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup())
|
||||
->addCustomField($cf);
|
||||
|
||||
$form = static::$kernel->getContainer()->get('form.factory')
|
||||
->createBuilder(\Chill\CustomFieldsBundle\Form\Type\CustomFieldType::class, array(), array(
|
||||
'group' => $cfGroup
|
||||
))
|
||||
->getForm();
|
||||
|
||||
$this->assertTrue($form['default']->isRequired(),
|
||||
"The field should be required");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,106 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2014 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldText;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Chill\CustomFieldsBundle\Tests\CustomFieldTestHelper;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldsTextTest extends WebTestCase
|
||||
{
|
||||
use CustomFieldTestHelper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Chill\CustomFieldsBundle\Service\CustomFieldProvider
|
||||
* @var \Chill\CustomFieldsBundle\Service\CustomFieldProvider
|
||||
*/
|
||||
private $customFieldProvider;
|
||||
|
||||
use CustomFieldTestHelper;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
static::bootKernel();
|
||||
$this->customFieldProvider = static::$kernel->getContainer()
|
||||
->get('chill.custom_field.provider');
|
||||
}
|
||||
|
||||
|
||||
public function testCustomFieldsTextExists()
|
||||
{
|
||||
$customField = $this->customFieldProvider->getCustomFieldByType('text');
|
||||
|
||||
$this->assertInstanceOf('Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface',
|
||||
$customField);
|
||||
$this->assertInstanceOf('Chill\CustomFieldsBundle\CustomFields\CustomFieldText',
|
||||
$customField);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface',
|
||||
$customField
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
'Chill\CustomFieldsBundle\CustomFields\CustomFieldText',
|
||||
$customField
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testFormTextNew()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/admin/customfield/new?type=text');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $crawler->selectButton('custom_field_choice_submit')->form();
|
||||
$this->assertTrue($form->has('custom_field_choice[options][maxLength]'));
|
||||
}
|
||||
|
||||
public function testPublicFormRenderingLengthLessThan256()
|
||||
{
|
||||
$customField = new CustomField();
|
||||
$customField->setType('text')
|
||||
->setOptions(array(CustomFieldText::MAX_LENGTH => 255))
|
||||
->setOptions([CustomFieldText::MAX_LENGTH => 255])
|
||||
->setSlug('slug')
|
||||
->setOrdering(10)
|
||||
->setActive(true)
|
||||
->setName(array('en' => 'my label'));
|
||||
|
||||
->setName(['en' => 'my label']);
|
||||
|
||||
$crawler = $this->getCrawlerForField($customField);
|
||||
|
||||
$this->assertCount(1, $crawler->filter("input[type=text]"));
|
||||
$this->assertCount(1, $crawler->filter("label:contains('my label')"));
|
||||
|
||||
$this->assertCount(1, $crawler->filter('input[type=text]'));
|
||||
$this->assertCount(1, $crawler->filter("label:contains('my label')"));
|
||||
}
|
||||
|
||||
|
||||
public function testPublicFormRenderingLengthMoreThan25()
|
||||
{
|
||||
$customField = new CustomField();
|
||||
$customField->setType('text')
|
||||
->setOptions(array(CustomFieldText::MAX_LENGTH => 256))
|
||||
->setOptions([CustomFieldText::MAX_LENGTH => 256])
|
||||
->setSlug('slug')
|
||||
->setOrdering(10)
|
||||
->setActive(true)
|
||||
->setName(array('en' => 'my label'));
|
||||
|
||||
->setName(['en' => 'my label']);
|
||||
|
||||
$crawler = $this->getCrawlerForField($customField);
|
||||
|
||||
$this->assertCount(1, $crawler->filter("textarea"));
|
||||
$this->assertCount(1, $crawler->filter("label:contains('my label')"));
|
||||
|
||||
$this->assertCount(1, $crawler->filter('textarea'));
|
||||
$this->assertCount(1, $crawler->filter("label:contains('my label')"));
|
||||
}
|
||||
|
||||
public function testFormTextNew()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request('GET', '/fr/admin/customfield/new?type=text');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $crawler->selectButton('custom_field_choice_submit')->form();
|
||||
$this->assertTrue($form->has('custom_field_choice[options][maxLength]'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFields\Tests\Form\Extension;
|
||||
@@ -23,14 +13,14 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
|
||||
/**
|
||||
* Test the post-text extension
|
||||
* Test the post-text extension.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PostTextIntegerExtensionTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
*/
|
||||
private $formBuilder;
|
||||
@@ -42,18 +32,17 @@ class PostTextIntegerExtensionTest extends KernelTestCase
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->formBuilder = $container->get('form.factory')
|
||||
->createBuilder('form', null);
|
||||
->createBuilder('form', null);
|
||||
}
|
||||
|
||||
public function testCreateView()
|
||||
{
|
||||
$form = $this->formBuilder->add('test', IntegerType::class, array(
|
||||
'post_text' => 'my text'
|
||||
))->getForm();
|
||||
$form = $this->formBuilder->add('test', IntegerType::class, [
|
||||
'post_text' => 'my text',
|
||||
])->getForm();
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertEquals('my text', $view['test']->vars['post_text']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFields\Tests\Form\Extension;
|
||||
@@ -23,14 +13,14 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
|
||||
/**
|
||||
* Test the post-text extension
|
||||
* Test the post-text extension.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PostTextNumberExtensionTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \Symfony\Component\Form\FormBuilderInterface
|
||||
*/
|
||||
private $formBuilder;
|
||||
@@ -42,18 +32,17 @@ class PostTextNumberExtensionTest extends KernelTestCase
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->formBuilder = $container->get('form.factory')
|
||||
->createBuilder('form', null);
|
||||
->createBuilder('form', null);
|
||||
}
|
||||
|
||||
public function testCreateView()
|
||||
{
|
||||
$form = $this->formBuilder->add('test', NumberType::class, array(
|
||||
'post_text' => 'my text'
|
||||
))->getForm();
|
||||
$form = $this->formBuilder->add('test', NumberType::class, [
|
||||
'post_text' => 'my text',
|
||||
])->getForm();
|
||||
|
||||
$view = $form->createView();
|
||||
|
||||
$this->assertEquals('my text', $view['test']->vars['post_text']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,21 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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/>.
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Tests;
|
||||
@@ -24,22 +13,22 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Test that routes are correctly loaded
|
||||
* Test that routes are correctly loaded.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class RoutingLoaderTest extends WebTestCase
|
||||
{
|
||||
public function testRoutesAreLoaded()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request('GET','/fr/admin/customfield/');
|
||||
|
||||
|
||||
$client->request('GET', '/fr/admin/customfield/');
|
||||
|
||||
$this->assertEquals(
|
||||
Response::HTTP_OK,
|
||||
$client->getResponse()->getStatusCode()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,92 +1,77 @@
|
||||
<?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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFields\Tests\Service;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Tests for custom fields helper
|
||||
* Tests for custom fields helper.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
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')
|
||||
;
|
||||
->setSlug('my-slug')
|
||||
->setActive(true)
|
||||
->setName(['fr' => 'my cf'])
|
||||
->setOptions(['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'
|
||||
);
|
||||
|
||||
$data = [
|
||||
$this->randomCFText->getSlug() => 'Sample text',
|
||||
];
|
||||
|
||||
$this->assertFalse($this->cfHelper->isEmptyValue($data, $this->randomCFText));
|
||||
|
||||
|
||||
//empty value
|
||||
$data = array(
|
||||
$this->randomCFText->getSlug() => ''
|
||||
);
|
||||
|
||||
$data = [
|
||||
$this->randomCFText->getSlug() => '',
|
||||
];
|
||||
|
||||
$this->assertTrue($this->cfHelper->isEmptyValue($data, $this->randomCFText));
|
||||
}
|
||||
|
||||
|
||||
public function testRenderCustomField()
|
||||
{
|
||||
$data = [
|
||||
$this->randomCFText->getSlug() => 'Sample text',
|
||||
];
|
||||
|
||||
$text = $this->cfHelper->renderCustomField($data, $this->randomCFText);
|
||||
|
||||
$this->assertContains('Sample text', $text);
|
||||
}
|
||||
}
|
||||
|
@@ -1,128 +1,118 @@
|
||||
<?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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldRenderingTwig;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Test the rendering of twig function which renders custom fields
|
||||
* 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>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldRenderingTwigTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldRenderingTwig
|
||||
*/
|
||||
private $cfRendering;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldProvider
|
||||
*/
|
||||
private $cfProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @var CustomFieldRenderingTwig
|
||||
*/
|
||||
private $cfRendering;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->cfRendering = self::$kernel->getContainer()
|
||||
->get('chill.custom_field.twig.custom_fields_rendering')
|
||||
;
|
||||
|
||||
->get('chill.custom_field.twig.custom_fields_rendering');
|
||||
|
||||
$this->cfProvider = self::$kernel->getContainer()
|
||||
->get('chill.custom_field.provider');
|
||||
|
||||
->get('chill.custom_field.provider');
|
||||
|
||||
// set locale to fr
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$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());
|
||||
->push($request->reveal());
|
||||
}
|
||||
|
||||
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$cf = $this->getSimpleCustomFieldText();
|
||||
|
||||
// value is not empty
|
||||
$fields = [
|
||||
'test' => 'My tailor is rich',
|
||||
];
|
||||
|
||||
$result = $this->cfRendering->isEmptyValue($fields, $cf);
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
// value is empty
|
||||
$fields = [
|
||||
'text' => '',
|
||||
];
|
||||
|
||||
$result = $this->cfRendering->isEmptyValue($fields, $cf);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
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 = [
|
||||
'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"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
->setName(['fr' => 'Test'])
|
||||
->setType('text')
|
||||
->setOrdering(10)
|
||||
->setOptions(['maxLength' => 255])
|
||||
->setActive(true);
|
||||
}
|
||||
}
|
||||
|
@@ -1,130 +1,115 @@
|
||||
<?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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
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;
|
||||
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldsGroupRenderingTwig;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* Test the rendering of a custom fields group through
|
||||
* the `chill_custom_fields_group_widget`
|
||||
* the `chill_custom_fields_group_widget`.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Champs Libres <info@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class CustomFieldsGroupRenderingTwigTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldsGroupRenderingTwig
|
||||
*/
|
||||
private $cfRendering;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CustomFieldProvider
|
||||
*/
|
||||
private $cfProvider;
|
||||
|
||||
|
||||
/**
|
||||
* @var CustomFieldsGroupRenderingTwig
|
||||
*/
|
||||
private $cfRendering;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->cfRendering = self::$kernel->getContainer()
|
||||
->get('chill.custom_field.twig.custom_fields_group_rendering')
|
||||
;
|
||||
|
||||
->get('chill.custom_field.twig.custom_fields_group_rendering');
|
||||
|
||||
$this->cfProvider = self::$kernel->getContainer()
|
||||
->get('chill.custom_field.provider');
|
||||
|
||||
->get('chill.custom_field.provider');
|
||||
|
||||
// set locale to fr
|
||||
$prophet = new \Prophecy\Prophet;
|
||||
$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());
|
||||
->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);
|
||||
|
||||
|
||||
$text = $this->cfRendering->renderWidget([
|
||||
'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));
|
||||
|
||||
|
||||
$text = $this->cfRendering->renderWidget([
|
||||
'horses' => 'I like horses',
|
||||
'sure' => 'Yes !',
|
||||
], $cfGroup, 'html', ['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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CustomFieldsGroup
|
||||
*/
|
||||
private function getCustomFieldsGroup()
|
||||
{
|
||||
return (new CustomFieldsGroup())
|
||||
->setEntity('\Dummy')
|
||||
->setName(['fr' => 'A cf group'])
|
||||
->addCustomField($this->getSimpleCustomFieldText('horses', 'Do you like horses ?.'))
|
||||
->addCustomField($this->getSimpleCustomFieldText('sure', 'Are you sure ?'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $slug
|
||||
* @param mixed $name
|
||||
*
|
||||
* @return CustomField
|
||||
*/
|
||||
private function getSimpleCustomFieldText($slug, $name)
|
||||
{
|
||||
return (new CustomField())
|
||||
->setSlug($slug)
|
||||
->setName(['fr' => $name])
|
||||
->setType('text')
|
||||
->setOrdering(10)
|
||||
->setOptions(['maxLength' => 255])
|
||||
->setActive(true);
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,14 @@
|
||||
<?php
|
||||
|
||||
if (!is_file($autoloadFile = __DIR__.'/../vendor/autoload.php')) {
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) {
|
||||
throw new \LogicException('Could not find autoload.php in vendor/. Did you run "composer install --dev"?');
|
||||
}
|
||||
|
||||
require $autoloadFile;
|
||||
|
||||
|
Reference in New Issue
Block a user