Skip to content

Commit

Permalink
bug #75 fix nested errors did not throw Exception (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

|Q            |A  |
|---          |---|
|Bug Fix?     |yes|
|New Feature? |no |
|BC Breaks?   |no |
|Deprecations?|no |
|Fixed Tickets|   |
|License      |MIT|

A SearchCondition with nested groups was not checked for errors.
Tests need to be updated prevent regressions.

Commits
-------

42e6374 fix nested errors did not throw Exception
  • Loading branch information
sstok committed Jul 5, 2015
2 parents 252ff38 + 42e6374 commit de3b509
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Input/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function process(ProcessorConfig $config, $input)
$config->getFieldSet(), $valuesGroup
);

if ($condition->getValuesGroup()->hasErrors()) {
if ($condition->getValuesGroup()->hasErrors(true)) {
throw new InvalidSearchConditionException($condition);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Input/FilterQueryInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function process(ProcessorConfig $config, $input)
$this->parse($config, $input)
);

if ($condition->getValuesGroup()->hasErrors()) {
if ($condition->getValuesGroup()->hasErrors(true)) {
throw new InvalidSearchConditionException($condition);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Input/XmlInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function process(ProcessorConfig $config, $input)
$valuesGroup
);

if ($condition->getValuesGroup()->hasErrors()) {
if ($condition->getValuesGroup()->hasErrors(true)) {
throw new InvalidSearchConditionException($condition);
}

Expand Down
30 changes: 30 additions & 0 deletions tests/Input/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,4 +707,34 @@ public function provideInvalidValueTests()
),
);
}

public function provideNestedErrorsTests()
{
return array(
array(
array(
'groups' => array(
array(
'groups' => array(
array(
'fields' => array(
'date' => array(
'single-values' => array('value'),
),
),
),
array(
'fields' => array(
'date' => array(
'single-values' => array('value', 'value2'),
),
),
),
),
),
),
),
),
);
}
}
9 changes: 9 additions & 0 deletions tests/Input/FilterQueryInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,13 @@ public function provideInvalidValueTests()
),
);
}

public function provideNestedErrorsTests()
{
return array(
array('date: 1;'),
array('(date: 1;)'),
array('((((((date: 1;))))))'),
);
}
}
21 changes: 21 additions & 0 deletions tests/Input/InputProcessorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,27 @@ public function it_errors_when_transformation_fails($input, $fieldName, array $e
*/
abstract public function provideInvalidValueTests();

/**
* @param mixed $input
*
* @test
* @dataProvider provideNestedErrorsTests
*/
public function it_checks_nested_fields($input)
{
$processor = $this->getProcessor();
$config = new ProcessorConfig($this->getFieldSet());

$this->setExpectedException('\Rollerworks\Component\Search\Exception\InvalidSearchConditionException');

$processor->process($config, $input);
}

/**
* @return array[]
*/
abstract public function provideNestedErrorsTests();

protected function detectSystemException(\Exception $exception)
{
if (!$exception instanceof ExceptionInterface) {
Expand Down
25 changes: 25 additions & 0 deletions tests/Input/JsonInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,29 @@ public function provideInvalidValueTests()
),
);
}

public function provideNestedErrorsTests()
{
return array(
array(
json_encode(
array(
'groups' => array(
array(
'groups' => array(
array(
'fields' => array(
'date' => array(
'single-values' => array('value', 'value2'),
),
),
),
),
),
),
)
),
),
);
}
}
22 changes: 22 additions & 0 deletions tests/Input/XmlInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1119,4 +1119,26 @@ public function provideInvalidValueTests()
),
);
}

public function provideNestedErrorsTests()
{
return array(
array(
'<?xml version="1.0" encoding="UTF-8"'.'?'.'>
<search>
<fields>
<field name="field1">
<single-values>
<value>value</value>
<value>value2</value>
<value>value3</value>
<value>value4</value>
<value>value5</value>
</single-values>
</field>
</fields>
</search>',
),
);
}
}

0 comments on commit de3b509

Please sign in to comment.