Skip to content

Commit

Permalink
bug #81 fix exporter component supporting (NOT_)EQUALS (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|

Commits
-------

277b338 fix exporter component supporting (NOT_)EQUALS
539b55b update filter_query.rst
  • Loading branch information
sstok committed Aug 11, 2015
2 parents 68e1fcf + 539b55b commit 0b8142d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
2 changes: 2 additions & 0 deletions doc/input/filter_query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ Supported operators are:
* ``~>`` (starts with)
* ``~<`` (ends with)
* ``~?`` (regex matching)
* ``~=`` (equals)

And not the excluding equivalent.

* ``~!*`` (does not contain)
* ``~!>`` (does not start with)
* ``~!<`` (does not end with)
* ``~!?`` (does not match regex)
* ``~!=`` (equals)

Example: ``field: ~>foo, ~*"bar", ~?"^foo|bar$";``

Expand Down
17 changes: 6 additions & 11 deletions src/Exporter/AbstractExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ protected function getPatternMatchType(PatternMatch $patternMatch)
{
$type = '';

if (
in_array(
$patternMatch->getType(),
[
PatternMatch::PATTERN_NOT_CONTAINS,
PatternMatch::PATTERN_NOT_STARTS_WITH,
PatternMatch::PATTERN_NOT_ENDS_WITH,
PatternMatch::PATTERN_NOT_REGEX,
], true
)
) {
if ($patternMatch->isExclusive()) {
$type .= 'NOT_';
}

Expand All @@ -112,6 +102,11 @@ protected function getPatternMatchType(PatternMatch $patternMatch)
$type .= 'REGEX';
break;

case PatternMatch::PATTERN_EQUALS:
case PatternMatch::PATTERN_NOT_EQUALS:
$type .= 'EQUALS';
break;

default:
throw new \RuntimeException(
sprintf(
Expand Down
5 changes: 5 additions & 0 deletions src/Exporter/FilterQueryExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ private function getPatternMatchOperator(PatternMatch $patternMatch)
$operator .= '?';
break;

case PatternMatch::PATTERN_EQUALS:
case PatternMatch::PATTERN_NOT_EQUALS:
$operator .= '=';
break;

default:
throw new \RuntimeException(
sprintf(
Expand Down
4 changes: 4 additions & 0 deletions tests/Exporter/ArrayExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public function provideMatcherValuesTest()
['type' => 'REGEX', 'value' => '^foo|bar?', 'case-insensitive' => false],
['type' => 'NOT_CONTAINS', 'value' => 'value4', 'case-insensitive' => false],
['type' => 'NOT_CONTAINS', 'value' => 'value5', 'case-insensitive' => true],
['type' => 'EQUALS', 'value' => 'value9', 'case-insensitive' => false],
['type' => 'NOT_EQUALS', 'value' => 'value10', 'case-insensitive' => false],
['type' => 'EQUALS', 'value' => 'value11', 'case-insensitive' => true],
['type' => 'NOT_EQUALS', 'value' => 'value12', 'case-insensitive' => true],
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Exporter/FilterQueryExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function provideComparisonValuesTest()

public function provideMatcherValuesTest()
{
return 'name: ~*value, ~i>value2, ~<value3, ~?"^foo|bar?", ~!*value4, ~i!*value5;';
return 'name: ~*value, ~i>value2, ~<value3, ~?"^foo|bar?", ~!*value4, ~i!*value5, ~=value9, ~!=value10, ~i=value11, ~i!=value12;';
}

public function provideGroupTest()
Expand Down
4 changes: 4 additions & 0 deletions tests/Exporter/JsonExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public function provideMatcherValuesTest()
['type' => 'REGEX', 'value' => '^foo|bar?', 'case-insensitive' => false],
['type' => 'NOT_CONTAINS', 'value' => 'value4', 'case-insensitive' => false],
['type' => 'NOT_CONTAINS', 'value' => 'value5', 'case-insensitive' => true],
['type' => 'EQUALS', 'value' => 'value9', 'case-insensitive' => false],
['type' => 'NOT_EQUALS', 'value' => 'value10', 'case-insensitive' => false],
['type' => 'EQUALS', 'value' => 'value11', 'case-insensitive' => true],
['type' => 'NOT_EQUALS', 'value' => 'value12', 'case-insensitive' => true],
],
],
],
Expand Down
4 changes: 4 additions & 0 deletions tests/Exporter/SearchConditionExporterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ public function it_exporters_matchers()
$values->addPatternMatch(new PatternMatch('^foo|bar?', PatternMatch::PATTERN_REGEX));
$values->addPatternMatch(new PatternMatch('value4', PatternMatch::PATTERN_NOT_CONTAINS));
$values->addPatternMatch(new PatternMatch('value5', PatternMatch::PATTERN_NOT_CONTAINS, true));
$values->addPatternMatch(new PatternMatch('value9', PatternMatch::PATTERN_EQUALS));
$values->addPatternMatch(new PatternMatch('value10', PatternMatch::PATTERN_NOT_EQUALS));
$values->addPatternMatch(new PatternMatch('value11', PatternMatch::PATTERN_EQUALS, true));
$values->addPatternMatch(new PatternMatch('value12', PatternMatch::PATTERN_NOT_EQUALS, true));
$expectedGroup->addField('name', $values);

$condition = new SearchCondition($config->getFieldSet(), $expectedGroup);
Expand Down
4 changes: 4 additions & 0 deletions tests/Exporter/XmlExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public function provideMatcherValuesTest()
<pattern-matcher type="regex" case-insensitive="false">^foo|bar?</pattern-matcher>
<pattern-matcher type="not_contains" case-insensitive="false">value4</pattern-matcher>
<pattern-matcher type="not_contains" case-insensitive="true">value5</pattern-matcher>
<pattern-matcher type="equals" case-insensitive="false">value9</pattern-matcher>
<pattern-matcher type="not_equals" case-insensitive="false">value10</pattern-matcher>
<pattern-matcher type="equals" case-insensitive="true">value11</pattern-matcher>
<pattern-matcher type="not_equals" case-insensitive="true">value12</pattern-matcher>
</pattern-matchers>
</field>
</fields>
Expand Down

0 comments on commit 0b8142d

Please sign in to comment.