|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter; |
|
13
|
|
|
|
|
14
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\NumberFilter; |
|
15
|
|
|
use Sonata\AdminBundle\Form\Type\Filter\NumberType; |
|
16
|
|
|
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; |
|
17
|
|
|
|
|
18
|
|
|
class NumberFilterTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testFilterEmpty() |
|
21
|
|
|
{ |
|
22
|
|
|
$filter = new NumberFilter; |
|
23
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
24
|
|
|
|
|
25
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
26
|
|
|
|
|
27
|
|
|
$filter->filter($builder, 'alias', 'field', null); |
|
28
|
|
|
$filter->filter($builder, 'alias', 'field', 'asds'); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertEquals(array(), $builder->query); |
|
|
|
|
|
|
31
|
|
|
$this->assertEquals(false, $filter->isActive()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testFilterInvalidOperator() |
|
35
|
|
|
{ |
|
36
|
|
|
$filter = new NumberFilter; |
|
37
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
38
|
|
|
|
|
39
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
40
|
|
|
|
|
41
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => 'foo')); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals(array(), $builder->query); |
|
|
|
|
|
|
44
|
|
|
$this->assertEquals(false, $filter->isActive()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testFilter() |
|
48
|
|
|
{ |
|
49
|
|
|
$filter = new NumberFilter; |
|
50
|
|
|
$filter->initialize('field_name', array('field_options' => array('class' => 'FooBar'))); |
|
51
|
|
|
|
|
52
|
|
|
$builder = new ProxyQuery(new QueryBuilder); |
|
53
|
|
|
|
|
54
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_EQUAL, 'value' => 42)); |
|
|
|
|
|
|
55
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_GREATER_EQUAL, 'value' => 42)); |
|
|
|
|
|
|
56
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_GREATER_THAN, 'value' => 42)); |
|
|
|
|
|
|
57
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_LESS_EQUAL, 'value' => 42)); |
|
|
|
|
|
|
58
|
|
|
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_LESS_THAN, 'value' => 42)); |
|
|
|
|
|
|
59
|
|
|
$filter->filter($builder, 'alias', 'field', array('value' => 42)); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$expected = array( |
|
62
|
|
|
'alias.field = :field_name_0', |
|
63
|
|
|
'alias.field >= :field_name_1', |
|
64
|
|
|
'alias.field > :field_name_2', |
|
65
|
|
|
'alias.field <= :field_name_3', |
|
66
|
|
|
'alias.field < :field_name_4', |
|
67
|
|
|
'alias.field = :field_name_5', |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals($expected, $builder->query); |
|
|
|
|
|
|
71
|
|
|
$this->assertEquals(true, $filter->isActive()); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.