diff --git a/src/Testing/EmulatesQueries.php b/src/Testing/EmulatesQueries.php index f4a5afd2..c6110878 100644 --- a/src/Testing/EmulatesQueries.php +++ b/src/Testing/EmulatesQueries.php @@ -169,7 +169,7 @@ public function orFilter(Closure $closure) */ public function findEloquentModelByDn($dn) { - return $this->newEloquentQuery()->where('dn', '=', $dn)->first(); + return $this->newEloquentQuery()->where('dn', 'like', $dn)->first(); } /** @@ -260,16 +260,16 @@ protected function addFilterToDatabaseQuery($query, $field, $operator, $value) case '!*': return $query->where('name', '!=', $field); case '=': - return $query->where('name', $operator, $field) - ->whereHas('values', function ($q) use ($operator, $value) { - $q->where('value', $operator, $value); + return $query->where('name', '=', $field) + ->whereHas('values', function ($q) use ($value) { + $q->where('value', 'like', $value); }); case '!': // Fallthrough. case '!=': return $query->where('name', '=', $field) ->whereHas('values', function ($q) use ($value) { - $q->where('value', '!=', $value); + $q->where('value', 'not like', $value); }); case'>=': return $query->where('name', '=', $field) diff --git a/tests/Feature/Emulator/EmulatedQueryTest.php b/tests/Feature/Emulator/EmulatedQueryTest.php index 7c083255..a880a199 100644 --- a/tests/Feature/Emulator/EmulatedQueryTest.php +++ b/tests/Feature/Emulator/EmulatedQueryTest.php @@ -78,6 +78,23 @@ public function test_find() $this->assertEquals($attributes['objectclass'], $record['objectclass']); } + public function test_find_is_case_insensitive() + { + $query = Container::getConnection('default')->query(); + + $this->assertNull($query->find('foo')); + + $dn = 'cn=John Doe,dc=local,dc=com'; + $attributes = ['objectclass' => ['foo', 'bar']]; + + $query->insert($dn, $attributes); + + $record = $query->find('cn=john doe,dc=local,dc=com'); + + $this->assertEquals($dn, $record['dn'][0]); + $this->assertEquals($attributes['objectclass'], $record['objectclass']); + } + public function test_get() { $query = Container::getConnection('default')->query(); @@ -148,7 +165,22 @@ public function test_where() $this->assertEquals('johndoe', $results[0]['samaccountname'][0]); } - public function test_where_with_alternate_casing() + public function test_where_values_are_case_insensitive() + { + $query = Container::getConnection('default')->query(); + + $attributes = ['objectclass' => ['bar', 'baz']]; + + $query->insert($john = 'cn=John Doe,dc=local,dc=com', array_merge($attributes, ['samaccountname' => ['johndoe']])); + + $results = $query->where('samaccountname', '=', 'JOHNdoe')->get(); + + $this->assertCount(1, $results); + $this->assertEquals($john, $results[0]['dn'][0]); + $this->assertEquals('johndoe', $results[0]['samaccountname'][0]); + } + + public function test_where_returns_same_results_with_alternate_attribute_casing() { $query = Container::getConnection('default')->query();