FormSonataNativeCollectionWidgetTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Form\Widget;
  11. use Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension;
  12. use Sonata\AdminBundle\Form\Type\CollectionType;
  13. use Symfony\Component\Form\Tests\Fixtures\TestExtension;
  14. use Symfony\Component\HttpKernel\Kernel;
  15. class FormSonataNativeCollectionWidgetTest extends BaseWidgetTest
  16. {
  17. protected $type = 'form';
  18. public function setUp()
  19. {
  20. parent::setUp();
  21. }
  22. public function prototypeRenderingProvider()
  23. {
  24. return array(
  25. 'shrinkable collection' => array(array('allow_delete' => true)),
  26. 'unshrinkable collection' => array(array('allow_delete' => false)),
  27. );
  28. }
  29. /**
  30. * @dataProvider prototypeRenderingProvider
  31. */
  32. public function testPrototypeIsDeletableNoMatterTheShrinkability(array $options)
  33. {
  34. $choice = $this->factory->create(
  35. $this->getChoiceClass(),
  36. null,
  37. array('allow_add' => true) + $options
  38. );
  39. $html = $this->renderWidget($choice->createView());
  40. $this->assertContains(
  41. 'sonata-collection-delete',
  42. $this->cleanHtmlWhitespace($html)
  43. );
  44. }
  45. protected function getExtensions()
  46. {
  47. $extensions = parent::getExtensions();
  48. $guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
  49. $extension = new TestExtension($guesser);
  50. if (!version_compare(Kernel::VERSION, '2.8.0', '>=')) {
  51. $extension->addType(new CollectionType());
  52. }
  53. $extension->addTypeExtension(new FormTypeFieldExtension(array(), array(
  54. 'form_type' => 'vertical',
  55. )));
  56. $extensions[] = $extension;
  57. return $extensions;
  58. }
  59. protected function getChoiceClass()
  60. {
  61. if (version_compare(Kernel::VERSION, '2.8.0', '>=')) {
  62. return 'Sonata\AdminBundle\Form\Type\CollectionType';
  63. } else {
  64. return 'sonata_type_native_collection';
  65. }
  66. }
  67. }