|
@@ -12,45 +12,23 @@
|
|
|
namespace Sonata\AdminBundle\Tests\Filter;
|
|
|
|
|
|
use Sonata\AdminBundle\Filter\Filter;
|
|
|
-use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
|
|
|
-
|
|
|
-class FilterTest_Filter extends Filter
|
|
|
-{
|
|
|
- public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $value)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public function apply($query, $value)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public function getDefaultOptions()
|
|
|
- {
|
|
|
- return array(
|
|
|
- 'foo' => 'bar'
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- public function getRenderSettings()
|
|
|
- {
|
|
|
- }
|
|
|
-}
|
|
|
+use Sonata\AdminBundle\Tests\Fixtures\Filter\FooFilter;
|
|
|
|
|
|
class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
public function testFilter()
|
|
|
{
|
|
|
- $filter = new FilterTest_Filter;
|
|
|
+ $filter = new FooFilter();
|
|
|
|
|
|
$this->assertEquals('text', $filter->getFieldType());
|
|
|
$this->assertEquals(array('required' => false), $filter->getFieldOptions());
|
|
|
$this->assertNull($filter->getLabel());
|
|
|
|
|
|
$options = array(
|
|
|
- 'label' => 'foo',
|
|
|
- 'field_type' => 'integer',
|
|
|
+ 'label' => 'foo',
|
|
|
+ 'field_type' => 'integer',
|
|
|
'field_options' => array('required' => true),
|
|
|
- 'field_name' => 'name'
|
|
|
+ 'field_name' => 'name'
|
|
|
);
|
|
|
|
|
|
$filter->setOptions($options);
|
|
@@ -75,9 +53,9 @@ class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
public function testInitialize()
|
|
|
{
|
|
|
- $filter = new FilterTest_Filter;
|
|
|
+ $filter = new FooFilter();
|
|
|
$filter->initialize('name', array(
|
|
|
- 'field_name' => 'bar'
|
|
|
+ 'field_name' => 'bar'
|
|
|
));
|
|
|
|
|
|
$this->assertEquals('name', $filter->getName());
|
|
@@ -87,7 +65,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
public function testLabel()
|
|
|
{
|
|
|
- $filter = new FilterTest_Filter;
|
|
|
+ $filter = new FooFilter();
|
|
|
$filter->setLabel('foo');
|
|
|
|
|
|
$this->assertEquals('foo', $filter->getLabel());
|
|
@@ -98,7 +76,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
public function testExceptionOnNonDefinedFieldName()
|
|
|
{
|
|
|
- $filter = new FilterTest_Filter;
|
|
|
+ $filter = new FooFilter();
|
|
|
|
|
|
$filter->getFieldName();
|
|
|
}
|
|
@@ -111,7 +89,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
public function testIsActive($expected, $value)
|
|
|
{
|
|
|
- $filter = new FilterTest_Filter;
|
|
|
+ $filter = new FooFilter();
|
|
|
$filter->setValue($value);
|
|
|
|
|
|
$this->assertEquals($expected, $filter->isActive());
|
|
@@ -127,4 +105,106 @@ class FilterTest extends \PHPUnit_Framework_TestCase
|
|
|
array(true, array('value' => "active")),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ public function testGetTranslationDomain()
|
|
|
+ {
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $this->assertEquals(null, $filter->getTranslationDomain());
|
|
|
+ $filter->setOption('translation_domain', 'baz');
|
|
|
+ $this->assertEquals('baz', $filter->getTranslationDomain());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetFieldMappingException()
|
|
|
+ {
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $filter->initialize('foo');
|
|
|
+
|
|
|
+ try {
|
|
|
+ $filter->getFieldMapping();
|
|
|
+ } catch (\RuntimeException $e) {
|
|
|
+ $this->assertContains('The option `field_mapping` must be set for field: `foo`', $e->getMessage());
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetFieldMapping()
|
|
|
+ {
|
|
|
+ $fieldMapping = array(
|
|
|
+ 'fieldName' => 'username',
|
|
|
+ 'type' => 'string',
|
|
|
+ 'columnName' => 'username',
|
|
|
+ 'length' => 200,
|
|
|
+ 'unique' => true,
|
|
|
+ 'nullable' => false,
|
|
|
+ 'declared' => 'Foo\Bar\User'
|
|
|
+ );
|
|
|
+
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $filter->setOption('field_mapping', $fieldMapping);
|
|
|
+ $this->assertEquals($fieldMapping, $filter->getFieldMapping());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetParentAssociationMappings()
|
|
|
+ {
|
|
|
+ $parentAssociationMapping = array(
|
|
|
+ 0 => array('fieldName' => 'user',
|
|
|
+ 'targetEntity' => 'Foo\Bar\User',
|
|
|
+ 'joinColumns' =>
|
|
|
+ array(
|
|
|
+ 0 =>
|
|
|
+ array(
|
|
|
+ 'name' => 'user_id',
|
|
|
+ 'referencedColumnName' => 'user_id',
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'type' => 2,
|
|
|
+ 'mappedBy' => null,
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $this->assertEquals(array(), $filter->getParentAssociationMappings());
|
|
|
+ $filter->setOption('parent_association_mappings', $parentAssociationMapping);
|
|
|
+ $this->assertEquals($parentAssociationMapping, $filter->getParentAssociationMappings());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetAssociationMappingException()
|
|
|
+ {
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $filter->initialize('foo');
|
|
|
+ try {
|
|
|
+ $filter->getAssociationMapping();
|
|
|
+ } catch (\RuntimeException $e) {
|
|
|
+ $this->assertContains('The option `association_mapping` must be set for field: `foo`', $e->getMessage());
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGetAssociationMapping()
|
|
|
+ {
|
|
|
+ $associationMapping = array(
|
|
|
+ 'fieldName' => 'user',
|
|
|
+ 'targetEntity' => 'Foo\Bar\User',
|
|
|
+ 'joinColumns' =>
|
|
|
+ array(
|
|
|
+ 0 =>
|
|
|
+ array(
|
|
|
+ 'name' => 'user_id',
|
|
|
+ 'referencedColumnName' => 'user_id',
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'type' => 2,
|
|
|
+ 'mappedBy' => null,
|
|
|
+ );
|
|
|
+
|
|
|
+ $filter = new FooFilter();
|
|
|
+ $filter->setOption('association_mapping', $associationMapping);
|
|
|
+ $this->assertEquals($associationMapping, $filter->getAssociationMapping());
|
|
|
+ }
|
|
|
}
|