parent
42991b0756
commit
2b50f6ff10
|
@ -107,6 +107,10 @@ class FilterExpression extends Filter
|
|||
|
||||
public function __toString()
|
||||
{
|
||||
if ($this->isBooleanTrue()) {
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
$expression = is_array($this->expression) ?
|
||||
'( ' . implode(' | ', $this->expression) . ' )' :
|
||||
$this->expression;
|
||||
|
@ -121,6 +125,10 @@ class FilterExpression extends Filter
|
|||
|
||||
public function toQueryString()
|
||||
{
|
||||
if ($this->isBooleanTrue()) {
|
||||
return $this->column;
|
||||
}
|
||||
|
||||
$expression = is_array($this->expression) ?
|
||||
'(' . implode('|', array_map('rawurlencode', $this->expression)) . ')' :
|
||||
rawurlencode($this->expression);
|
||||
|
@ -128,6 +136,11 @@ class FilterExpression extends Filter
|
|||
return $this->column . $this->sign . $expression;
|
||||
}
|
||||
|
||||
protected function isBooleanTrue()
|
||||
{
|
||||
return $this->sign === '=' && $this->expression === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If $var is a scalar, do the same as strtolower() would do.
|
||||
* If $var is an array, map $this->strtolowerRecursive() to its elements.
|
||||
|
|
|
@ -198,6 +198,20 @@ class FilterTest extends BaseTestCase
|
|||
$this->assertNotEquals((string) $c, (string) $d);
|
||||
}
|
||||
|
||||
public function testBooleanExpressionIsRenderedCorrectly()
|
||||
{
|
||||
$filter = Filter::fromQueryString('a&!b');
|
||||
$this->assertEquals(
|
||||
$filter->toQueryString(),
|
||||
'a&!b'
|
||||
);
|
||||
$this->assertEquals(
|
||||
(string) $filter,
|
||||
// TODO: I'd prefer to see 'a & !b' here:
|
||||
'a & (! b)'
|
||||
);
|
||||
}
|
||||
|
||||
public function testLeadingAndTrailingWhitespaces()
|
||||
{
|
||||
$columnWithWhitespaces = Filter::where(' host ', 'localhost');
|
||||
|
|
Loading…
Reference in New Issue