diff --git a/tests/SimpleQueryParserTest.php b/tests/SimpleQueryParserTest.php index 91c1cae..45b8883 100644 --- a/tests/SimpleQueryParserTest.php +++ b/tests/SimpleQueryParserTest.php @@ -40,6 +40,45 @@ public function it_returns_valid_filters_when_not_empty_request() $this->assertEquals($filters, $parser->getFilters()); } + /** @test */ + public function it_include_filter_with_empty_value_when_empty_value() + { + $request = m::mock('Illuminate\Http\Request'); + $request->shouldReceive('except')->once()->with('sort')->andReturn([ + 'id' => '', + 'email' => ' test@example.com ', + 'something' => [' foo ', 'bar', 'baz'], + ]); + + $filters = new Collection([ + new Filter('id', ''), + new Filter('email', ' test@example.com '), + new Filter('something', [' foo ', 'bar', 'baz']), + ]); + + $parser = new SimpleQueryParser($request, new Collection()); + $this->assertEquals($filters, $parser->getFilters()); + } + + /** @test */ + public function it_doest_not_include_filter_with_empty_value_when_empty_value_with_property_set() + { + $request = m::mock('Illuminate\Http\Request'); + $request->shouldReceive('except')->once()->with('sort')->andReturn([ + 'id' => '', + 'email' => ' test@example.com ', + 'something' => [' foo ', 'bar', 'baz'], + ]); + + $filters = new Collection([ + new Filter('email', ' test@example.com '), + new Filter('something', [' foo ', 'bar', 'baz']), + ]); + + $parser = new IgnoreEmptyQueryParser($request, new Collection()); + $this->assertEquals($filters, $parser->getFilters()); + } + /** @test */ public function it_returns_empty_sorts_when_empty_request() { @@ -142,3 +181,10 @@ public function it_returns_valid_sorts_when_array_with_duplicated_fields() $this->assertEquals($sorts, $parser->getSorts()); } } + +// stubs + +class IgnoreEmptyQueryParser extends SimpleQueryParser +{ + protected $ignoreEmptyFilters = true; +}