BaseFieldDescriptionTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of the Sonata 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\Admin;
  11. use Sonata\AdminBundle\Admin\BaseFieldDescription;
  12. class BaseFieldDescriptionTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testSetName()
  15. {
  16. $description = new FieldDescription();
  17. $description->setName('foo');
  18. $this->assertEquals('foo', $description->getFieldName());
  19. $this->assertEquals('foo', $description->getName());
  20. }
  21. public function testOptions()
  22. {
  23. $description = new FieldDescription();
  24. $description->setOption('foo', 'bar');
  25. $this->assertNull($description->getOption('bar'));
  26. $this->assertEquals('bar', $description->getOption('foo'));
  27. $description->mergeOptions(array('settings' => array('value_1', 'value_2')));
  28. $description->mergeOptions(array('settings' => array('value_1', 'value_3')));
  29. $this->assertEquals(array('value_1', 'value_2', 'value_1', 'value_3'), $description->getOption('settings'));
  30. $description->mergeOption('settings', array('value_4'));
  31. $this->assertEquals(array('value_1', 'value_2', 'value_1', 'value_3', 'value_4'), $description->getOption('settings'));
  32. $description->mergeOption('bar', array('hello'));
  33. $this->assertCount(1, $description->getOption('bar'));
  34. }
  35. /**
  36. * @expectedException RuntimeException
  37. */
  38. public function testExceptionOnNonArrayOption()
  39. {
  40. $description = new FieldDescription();
  41. $description->setOption('bar', 'hello');
  42. $description->mergeOption('bar', array('exception'));
  43. }
  44. }
  45. class FieldDescription extends BaseFieldDescription
  46. {
  47. function setAssociationMapping($associationMapping)
  48. {
  49. // TODO: Implement setAssociationMapping() method.
  50. }
  51. function getTargetEntity()
  52. {
  53. // TODO: Implement getTargetEntity() method.
  54. }
  55. function setFieldMapping($fieldMapping)
  56. {
  57. // TODO: Implement setFieldMapping() method.
  58. }
  59. function isIdentifier()
  60. {
  61. // TODO: Implement isIdentifier() method.
  62. }
  63. }