Skip to content

Commit

Permalink
FilterTest: Test what happens with empty chains next to siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Apr 29, 2022
1 parent afe05fe commit f4080ec
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,19 @@ public function testRendererDrawsRedundantCharsInStrictMode()
"Filter\Renderer doesn't draw parentheses for empty nested chains"
);

$nestedEmptyAllWithConditionOnSameLevel = Filter::all(
Filter::equal('foo', 'bar'),
Filter::all(
Filter::all(),
Filter::equal('bar', 'foo')
)
);
$this->assertEquals(
'(foo=bar&(()&bar=foo))',
(new Renderer($nestedEmptyAllWithConditionOnSameLevel))->setStrict()->render(),
"Filter\Renderer doesn't draw parentheses for empty nested chains with non-empty siblings"
);

$nestedEmptyAny = Filter::all(
Filter::equal('foo', 'bar'),
Filter::any()
Expand All @@ -597,6 +610,19 @@ public function testRendererDrawsRedundantCharsInStrictMode()
(new Renderer($nestedEmptyAny))->setStrict()->render(),
"Filter\Renderer doesn't draw group operator for empty nested OR chains"
);

$nestedEmptyAnyWithConditionOnSameLevel = Filter::all(
Filter::equal('foo', 'bar'),
Filter::all(
Filter::any(),
Filter::equal('bar', 'foo')
)
);
$this->assertEquals(
'(foo=bar&((|)&bar=foo))',
(new Renderer($nestedEmptyAnyWithConditionOnSameLevel))->setStrict()->render(),
"Filter\Renderer doesn't draw group operator for empty nested OR chains with non-empty siblings"
);
}

/**
Expand Down Expand Up @@ -629,10 +655,20 @@ public function testParserRespectsRedundantCharsInStrictMode()
(new Renderer((new Parser('(foo=bar&())'))->setStrict()->parse()))->setStrict()->render(),
"Filter\Parser doesn't respect parentheses for empty nested chains"
);
$this->assertEquals(
'(foo=bar&(()&bar=foo))',
(new Renderer((new Parser('(foo=bar&(()&bar=foo))'))->setStrict()->parse()))->setStrict()->render(),
"Filter\Parser doesn't respect parentheses for empty nested chains with non-empty siblings"
);
$this->assertEquals(
'(foo=bar&(|))',
(new Renderer((new Parser('(foo=bar&(|))'))->setStrict()->parse()))->setStrict()->render(),
"Filter\Parser doesn't respect group operator for empty nested OR chains"
);
$this->assertEquals(
'(foo=bar&((|)&bar=foo))',
(new Renderer((new Parser('(foo=bar&((|)&bar=foo))'))->setStrict()->parse()))->setStrict()->render(),
"Filter\Parser doesn't respect group operator for empty nested OR chains with non-empty siblings"
);
}
}

0 comments on commit f4080ec

Please sign in to comment.