Skip to content

Commit

Permalink
Add "containsCaseInsensitive" as new custom where operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Edujugon committed Apr 11, 2018
1 parent 5f6f985 commit 0b46590
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Custom:
* !==
* ===
* contains
* containsCaseInsensitive
```
[['name','!=','john'],['id','!=',7]]
[['name','contains','john']]
Expand Down
5 changes: 5 additions & 0 deletions src/XMLMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ protected function customCondition($element, $val)
$found = false;
}
break;
case 'containsCaseInsensitive':
if (stripos($this->fetchAttr($val[0], $element), $val[2]) === false) {
$found = false;
}
break;
default:
$found = false;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/XMLMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ public function find_attribute_by_where_contains()
$this->assertEquals('edujugon',$this->mapper->findAttributeWhere('name',[['dev','contains','edu']]));
}

/** @test */
public function find_attribute_by_where_contains_case_sensitive()
{
$xml = '<xml id="33"><content att="something"><first><second><edu><e><d><u><edu></edu></u></d></e></edu><my-value name="edujugon" id="1" dev="eduardo"></my-value></second></first></content></xml>';

$this->mapper->loadXML($xml);

$this->assertNull($this->mapper->findAttributeWhere('name',[['dev','contains','Edu']]));
}

/** @test */
public function find_attribute_by_where_contains_case_insensitive()
{
$xml = '<xml id="33"><content att="something"><first><second><edu><e><d><u><edu></edu></u></d></e></edu><my-value name="edujugon" id="1" dev="eduardo"></my-value></second></first></content></xml>';

$this->mapper->loadXML($xml);

$this->assertEquals('edujugon',$this->mapper->findAttributeWhere('name',[['dev','containsCaseInsensitive','Edu']]));
}

/** @test */
public function find_attribute_by_where_with_multiple_extras()
{
Expand Down

0 comments on commit 0b46590

Please sign in to comment.