FilterTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\DoctrineORMAdminBundle\Tests\Filter;
  11. use Sonata\DoctrineORMAdminBundle\Filter\Filter;
  12. class FilterTest_Filter extends Filter
  13. {
  14. /**
  15. * Apply the filter to the QueryBuilder instance
  16. *
  17. * @param $queryBuilder
  18. * @param string $alias
  19. * @param string $field
  20. * @param string $value
  21. * @return void
  22. */
  23. public function filter($queryBuilder, $alias, $field, $value)
  24. {
  25. // TODO: Implement filter() method.
  26. }
  27. public function getDefaultOptions()
  28. {
  29. return array('option1' => 2);
  30. }
  31. public function getRenderSettings()
  32. {
  33. return array('sonata_type_filter_default', array(
  34. 'type' => $this->getFieldType(),
  35. 'options' => $this->getFieldOptions()
  36. ));
  37. }
  38. }
  39. class FilterTest extends \PHPUnit_Framework_TestCase
  40. {
  41. public function testFieldDescription()
  42. {
  43. $filter = new FilterTest_Filter();
  44. $this->assertEquals(array('option1' => 2), $filter->getDefaultOptions());
  45. $this->assertEquals(null, $filter->getOption('1'));
  46. $filter->initialize('field_name', array('field_options' => array('class' => 'FooBar')));
  47. $this->assertEquals(2, $filter->getOption('option1'));
  48. $this->assertEquals(null, $filter->getOption('foo'));
  49. $this->assertEquals('bar', $filter->getOption('foo', 'bar'));
  50. $this->assertEquals('field_name', $filter->getName());
  51. $this->assertEquals('text', $filter->getFieldType());
  52. $this->assertEquals(array('class' => 'FooBar'), $filter->getFieldOptions());
  53. }
  54. public function testValues()
  55. {
  56. $filter = new FilterTest_Filter();
  57. $this->assertEmpty($filter->getValue());
  58. $filter->setValue(42);
  59. $this->assertEquals(42, $filter->getValue());
  60. }
  61. /**
  62. * @expectedException RuntimeException
  63. */
  64. public function testExceptionOnEmptyFieldName()
  65. {
  66. $filter = new FilterTest_Filter();
  67. $filter->getFieldName();
  68. }
  69. }