Skip to content

Commit

Permalink
Update number filter to match the string behavior on undefined type
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Aug 27, 2011
1 parent f6ea822 commit cf8361a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Filter/ORM/NumberFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ class NumberFilter extends Filter
*/
public function filter($queryBuilder, $alias, $field, $data)
{
if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) {
if (!$data || !is_array($data) || !array_key_exists('value', $data)) {
return;
}

$operator = $this->getOperator((int) $data['type']);
$type = isset($data['type']) ? $data['type'] : false;

$operator = $this->getOperator($type);

if (!$operator) {
return;
$operator = '=';
}

// c.name > '1' => c.name OPERATOR :FIELDNAME
Expand Down
4 changes: 3 additions & 1 deletion Tests/Filter/ORM/NumberFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public function testFilter()
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_GREATER_THAN, 'value' => 42));
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_LESS_EQUAL, 'value' => 42));
$filter->filter($builder, 'alias', 'field', array('type' => NumberType::TYPE_LESS_THAN, 'value' => 42));
$filter->filter($builder, 'alias', 'field', array('value' => 42));

$expected = array(
'alias.field = :field_name',
'alias.field >= :field_name',
'alias.field > :field_name',
'alias.field <= :field_name',
'alias.field < :field_name'
'alias.field < :field_name',
'alias.field = :field_name',
);

$this->assertEquals($expected, $builder->query);
Expand Down

0 comments on commit cf8361a

Please sign in to comment.