FormSonataNativeCollectionWidgetTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. class FormSonataNativeCollectionWidgetTest extends BaseWidgetTest
  15. {
  16. protected $type = 'form';
  17. public function setUp()
  18. {
  19. parent::setUp();
  20. }
  21. public function prototypeRenderingProvider()
  22. {
  23. return array(
  24. 'shrinkable collection' => array(array('allow_delete' => true)),
  25. 'unshrinkable collection' => array(array('allow_delete' => false)),
  26. );
  27. }
  28. /**
  29. * @dataProvider prototypeRenderingProvider
  30. */
  31. public function testPrototypeIsDeletableNoMatterTheShrinkability(array $options)
  32. {
  33. $choice = $this->factory->create(
  34. $this->getChoiceClass(),
  35. null,
  36. array('allow_add' => true) + $options
  37. );
  38. $html = $this->renderWidget($choice->createView());
  39. $this->assertContains(
  40. 'sonata-collection-delete',
  41. $this->cleanHtmlWhitespace($html)
  42. );
  43. }
  44. protected function getExtensions()
  45. {
  46. $extensions = parent::getExtensions();
  47. $guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
  48. $extension = new TestExtension($guesser);
  49. if (!method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
  50. $extension->addType(new CollectionType());
  51. }
  52. $extension->addTypeExtension(new FormTypeFieldExtension(array(), array(
  53. 'form_type' => 'vertical',
  54. )));
  55. $extensions[] = $extension;
  56. return $extensions;
  57. }
  58. protected function getChoiceClass()
  59. {
  60. return
  61. method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ?
  62. 'Sonata\AdminBundle\Form\Type\CollectionType' :
  63. 'sonata_type_native_collection';
  64. }
  65. }