parent
b8b0e8039b
commit
d543163e37
|
@ -11,6 +11,7 @@
|
|||
namespace Propel\Bundle\PropelBundle\Form\EventListener;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
|
@ -56,7 +57,7 @@ class TranslationFormListener implements EventSubscriberInterface
|
|||
$options = array();
|
||||
}
|
||||
|
||||
$type = 'text';
|
||||
$type = TextType::class;
|
||||
if (array_key_exists('type', $options)) {
|
||||
$type = $options['type'];
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class YamlDataDumperTest extends TestCase
|
|||
id: '1'
|
||||
name: 'An important one'
|
||||
author_id: CoolBookAuthor_1
|
||||
complementary_infos: !!php/object:O:8:"stdClass":1:{s:15:"first_word_date";s:10:"2012-01-01";}
|
||||
complementary_infos: !php/object:O:8:"stdClass":1:{s:15:"first_word_date";s:10:"2012-01-01";}
|
||||
|
||||
YAML;
|
||||
|
||||
|
|
|
@ -1,215 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Propel\Bundle\PropelBundle\Tests\Form\ChoiceList;
|
||||
|
||||
use Propel\Bundle\PropelBundle\Form\ChoiceList\ModelChoiceList;
|
||||
use Propel\Bundle\PropelBundle\Tests\Fixtures\Item;
|
||||
use Propel\Bundle\PropelBundle\Tests\Fixtures\ReadOnlyItem;
|
||||
use Propel\Bundle\PropelBundle\Tests\TestCase;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
|
||||
|
||||
class ModelChoiceListTest extends TestCase
|
||||
{
|
||||
const ITEM_CLASS = '\Propel\Bundle\PropelBundle\Tests\Fixtures\Item';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\Form\Form')) {
|
||||
$this->markTestSkipped('The "Form" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
|
||||
$this->markTestSkipped('The "PropertyAccessor" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testEmptyChoicesReturnsEmpty()
|
||||
{
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array()
|
||||
);
|
||||
|
||||
$this->assertSame(array(), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testReadOnlyIsValidChoice()
|
||||
{
|
||||
$item = new ReadOnlyItem();
|
||||
$choiceList = new ModelChoiceList(
|
||||
'\Propel\Bundle\PropelBundle\Tests\Fixtures\ReadOnlyItem',
|
||||
'name',
|
||||
array(
|
||||
$item,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(array(42 => $item), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testFlattenedChoices()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo');
|
||||
$item2 = new Item(2, 'Bar');
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array(
|
||||
$item1,
|
||||
$item2,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(array(1 => $item1, 2 => $item2), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testFlattenedPreferredChoices()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo');
|
||||
$item2 = new Item(2, 'Bar');
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array(
|
||||
$item1,
|
||||
$item2,
|
||||
),
|
||||
null,
|
||||
null,
|
||||
array(
|
||||
$item1
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(array(1 => $item1, 2 => $item2), $choiceList->getChoices());
|
||||
$this->assertEquals(array(1 => new ChoiceView($item1, '1', 'Foo')), $choiceList->getPreferredViews());
|
||||
}
|
||||
|
||||
public function testNestedChoices()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo');
|
||||
$item2 = new Item(2, 'Bar');
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array(
|
||||
'group1' => array($item1),
|
||||
'group2' => array($item2),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(array(1 => $item1, 2 => $item2), $choiceList->getChoices());
|
||||
$this->assertEquals(array(
|
||||
'group1' => array(1 => new ChoiceView($item1, '1', 'Foo')),
|
||||
'group2' => array(2 => new ChoiceView($item2, '2', 'Bar'))
|
||||
), $choiceList->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testGroupBySupportsString()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo', 'Group1');
|
||||
$item2 = new Item(2, 'Bar', 'Group1');
|
||||
$item3 = new Item(3, 'Baz', 'Group2');
|
||||
$item4 = new Item(4, 'Boo!', null);
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array(
|
||||
$item1,
|
||||
$item2,
|
||||
$item3,
|
||||
$item4,
|
||||
),
|
||||
null,
|
||||
'groupName'
|
||||
);
|
||||
|
||||
$this->assertEquals(array(1 => $item1, 2 => $item2, 3 => $item3, 4 => $item4), $choiceList->getChoices());
|
||||
$this->assertEquals(array(
|
||||
'Group1' => array(1 => new ChoiceView($item1, '1', 'Foo'), 2 => new ChoiceView($item2, '2', 'Bar')),
|
||||
'Group2' => array(3 => new ChoiceView($item3, '3', 'Baz')),
|
||||
4 => new ChoiceView($item4, '4', 'Boo!')
|
||||
), $choiceList->getRemainingViews());
|
||||
}
|
||||
|
||||
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo', 'Group1');
|
||||
$item2 = new Item(2, 'Bar', 'Group1');
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array(
|
||||
$item1,
|
||||
$item2,
|
||||
),
|
||||
null,
|
||||
'child.that.does.not.exist'
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
1 => $item1,
|
||||
2 => $item2
|
||||
), $choiceList->getChoices());
|
||||
}
|
||||
|
||||
public function testGetValuesForChoices()
|
||||
{
|
||||
$item1 = new Item(1, 'Foo');
|
||||
$item2 = new Item(2, 'Bar');
|
||||
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
$this->assertEquals(array(1, 2), $choiceList->getValuesForChoices(array($item1, $item2)));
|
||||
$this->assertEquals(array(1, 2), $choiceList->getIndicesForChoices(array($item1, $item2)));
|
||||
}
|
||||
|
||||
public function testDifferentEqualObjectsAreChoosen()
|
||||
{
|
||||
$item = new Item(1, 'Foo');
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array($item)
|
||||
);
|
||||
|
||||
$choosenItem = new Item(1, 'Foo');
|
||||
|
||||
$this->assertEquals(array(1), $choiceList->getIndicesForChoices(array($choosenItem)));
|
||||
}
|
||||
|
||||
public function testGetIndicesForNullChoices()
|
||||
{
|
||||
$item = new Item(1, 'Foo');
|
||||
$choiceList = new ModelChoiceList(
|
||||
self::ITEM_CLASS,
|
||||
'value',
|
||||
array($item)
|
||||
);
|
||||
|
||||
$this->assertEquals(array(), $choiceList->getIndicesForChoices(array(null)));
|
||||
}
|
||||
}
|
|
@ -57,14 +57,14 @@ class CollectionToArrayTransformerTest extends TestCase
|
|||
public function testTransformWithData()
|
||||
{
|
||||
$coll = new ObjectCollection();
|
||||
$coll->setData(array('foo', 'bar'));
|
||||
$coll->setData(array($a = new \stdClass, $b = new \stdClass));
|
||||
|
||||
$result = $this->transformer->transform($coll);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals(2, count($result));
|
||||
$this->assertEquals('foo', $result[0]);
|
||||
$this->assertEquals('bar', $result[1]);
|
||||
$this->assertSame($a, $result[0]);
|
||||
$this->assertSame($b, $result[1]);
|
||||
}
|
||||
|
||||
public function testReverseTransformWithNull()
|
||||
|
@ -93,7 +93,7 @@ class CollectionToArrayTransformerTest extends TestCase
|
|||
|
||||
public function testReverseTransformWithData()
|
||||
{
|
||||
$inputData = array('foo', 'bar');
|
||||
$inputData = array($a = new \stdClass, $b = new \stdClass);
|
||||
|
||||
$result = $this->transformer->reverseTransform($inputData);
|
||||
$data = $result->getData();
|
||||
|
@ -102,8 +102,8 @@ class CollectionToArrayTransformerTest extends TestCase
|
|||
|
||||
$this->assertTrue(is_array($data));
|
||||
$this->assertEquals(2, count($data));
|
||||
$this->assertEquals('foo', $data[0]);
|
||||
$this->assertEquals('bar', $data[1]);
|
||||
$this->assertSame($a, $data[0]);
|
||||
$this->assertSame($b, $data[1]);
|
||||
$this->assertsame($inputData, $data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ use Propel\Bundle\PropelBundle\Tests\Fixtures\Item;
|
|||
use Propel\Bundle\PropelBundle\Form\PropelExtension;
|
||||
use Propel\Bundle\PropelBundle\Tests\Fixtures\TranslatableItemI18n;
|
||||
use Propel\Bundle\PropelBundle\Tests\Fixtures\TranslatableItem;
|
||||
use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class TranslationCollectionTypeTest extends TypeTestCase
|
||||
{
|
||||
|
@ -42,7 +44,7 @@ class TranslationCollectionTypeTest extends TypeTestCase
|
|||
$item->addTranslatableItemI18n(new TranslatableItemI18n(1, 'fr', 'val1'));
|
||||
$item->addTranslatableItemI18n(new TranslatableItemI18n(2, 'en', 'val2'));
|
||||
|
||||
$builder = $this->factory->createBuilder('form', null, array(
|
||||
$builder = $this->factory->createBuilder(FormType::class, null, array(
|
||||
'data_class' => self::TRANSLATION_CLASS
|
||||
));
|
||||
|
||||
|
@ -50,7 +52,7 @@ class TranslationCollectionTypeTest extends TypeTestCase
|
|||
'languages' => array('en', 'fr'),
|
||||
'entry_options' => array(
|
||||
'data_class' => self::TRANSLATABLE_I18N_CLASS,
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => 'textarea'))
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => TextareaType::class))
|
||||
)
|
||||
));
|
||||
$form = $builder->getForm();
|
||||
|
@ -69,7 +71,7 @@ class TranslationCollectionTypeTest extends TypeTestCase
|
|||
|
||||
$columnOptions = $translations['fr']->getConfig()->getOption('columns');
|
||||
$this->assertEquals('value', $columnOptions[0]);
|
||||
$this->assertEquals('textarea', $columnOptions['value2']['type']);
|
||||
$this->assertEquals(TextareaType::class, $columnOptions['value2']['type']);
|
||||
$this->assertEquals('Label', $columnOptions['value2']['label']);
|
||||
}
|
||||
|
||||
|
@ -79,14 +81,14 @@ class TranslationCollectionTypeTest extends TypeTestCase
|
|||
|
||||
$this->assertCount(0, $item->getTranslatableItemI18ns());
|
||||
|
||||
$builder = $this->factory->createBuilder('form', null, array(
|
||||
$builder = $this->factory->createBuilder(FormType::class, null, array(
|
||||
'data_class' => self::TRANSLATION_CLASS
|
||||
));
|
||||
$builder->add('translatableItemI18ns', TranslationCollectionType::class, array(
|
||||
'languages' => array('en', 'fr'),
|
||||
'entry_options' => array(
|
||||
'data_class' => self::TRANSLATABLE_I18N_CLASS,
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => 'textarea'))
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => TextareaType::class))
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -103,14 +105,14 @@ class TranslationCollectionTypeTest extends TypeTestCase
|
|||
{
|
||||
$item = new Item(null, 'val');
|
||||
|
||||
$builder = $this->factory->createBuilder('form', null, array(
|
||||
$builder = $this->factory->createBuilder(FormType::class, null, array(
|
||||
'data_class' => self::NON_TRANSLATION_CLASS
|
||||
));
|
||||
$builder->add('value', TranslationCollectionType::class, array(
|
||||
'languages' => array('en', 'fr'),
|
||||
'entry_options' => array(
|
||||
'data_class' => self::TRANSLATABLE_I18N_CLASS,
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => 'textarea'))
|
||||
'columns' => array('value', 'value2' => array('label' => 'Label', 'type' => TextareaType::class))
|
||||
)
|
||||
));
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
|
||||
"require": {
|
||||
"propel/propel": "dev-master",
|
||||
"symfony/symfony": "^2.8|^3.0"
|
||||
"symfony/symfony": "^2.8|^3.0",
|
||||
"symfony/security-acl": "^2.8|^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.21|^5.0.10",
|
||||
|
|
Loading…
Reference in a new issue