FormSonataNativeCollectionWidgetTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\Type\CollectionType;
  12. use Symfony\Component\Form\Tests\Fixtures\TestExtension;
  13. use Symfony\Component\HttpKernel\Kernel;
  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. if (!version_compare(Kernel::VERSION, '2.8.0', '>=')) {
  48. $guesser = $this->getMock('Symfony\Component\Form\FormTypeGuesserInterface');
  49. $extension = new TestExtension($guesser);
  50. $extension->addType(new CollectionType());
  51. $extensions[] = $extension;
  52. }
  53. return $extensions;
  54. }
  55. protected function getChoiceClass()
  56. {
  57. if (version_compare(Kernel::VERSION, '2.8.0', '>=')) {
  58. return 'Sonata\AdminBundle\Form\Type\CollectionType';
  59. } else {
  60. return 'sonata_type_native_collection';
  61. }
  62. }
  63. }