FilterTest.php 2.6 KB

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