Commit 19327ebd by Alexander Makarov

Added tests for Query::filter()

parent 0d3e85ca
......@@ -151,6 +151,35 @@ class QueryTest extends ElasticSearchTestCase
}
public function testFilter()
{
$query = new Query;
$query->filter('id = :id', [':id' => 1]);
$this->assertEquals('id = :id', $query->where);
$this->assertEquals([':id' => 1], $query->params);
$query->andFilter('name = :name', [':name' => 'something']);
$this->assertEquals(['and', 'id = :id', 'name = :name'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something'], $query->params);
$query->orFilter('age = :age', [':age' => '30']);
$this->assertEquals(['or', ['and', 'id = :id', 'name = :name'], 'age = :age'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
$query = new Query;
$query->filter('id = :id', [':id' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->andFilter('name = :name', [':name' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->orFilter('age = :age', [':age' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
}
// TODO test facets
// TODO test complex where() every edge of QueryBuilder
......
......@@ -68,6 +68,48 @@ class QueryTest extends MongoDbTestCase
);
}
public function testFilter()
{
$query = new Query;
$query->filter(['name' => 'name1']);
$this->assertEquals(['name' => 'name1'], $query->where);
$query->andFilter(['address' => 'address1']);
$this->assertEquals(
[
'and',
['name' => 'name1'],
['address' => 'address1']
],
$query->where
);
$query->orFilter(['name' => 'name2']);
$this->assertEquals(
[
'or',
[
'and',
['name' => 'name1'],
['address' => 'address1']
],
['name' => 'name2']
],
$query->where
);
$query = new Query;
$query->filter(['name' => '']);
$this->assertEquals('', $query->where);
$query->andFilter(['address' => '']);
$this->assertEquals([], $query->where);
$query->orFilter(['name' => '']);
$this->assertEquals([], $query->where);
}
public function testOrder()
{
$query = new Query;
......
......@@ -60,6 +60,35 @@ class QueryTest extends SphinxTestCase
$this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
}
public function testFilter()
{
$query = new Query;
$query->filter('id = :id', [':id' => 1]);
$this->assertEquals('id = :id', $query->where);
$this->assertEquals([':id' => 1], $query->params);
$query->andFilter('name = :name', [':name' => 'something']);
$this->assertEquals(['and', 'id = :id', 'name = :name'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something'], $query->params);
$query->orFilter('age = :age', [':age' => '30']);
$this->assertEquals(['or', ['and', 'id = :id', 'name = :name'], 'age = :age'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
$query = new Query;
$query->filter('id = :id', [':id' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->andFilter('name = :name', [':name' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->orFilter('age = :age', [':age' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
}
public function testGroup()
{
$query = new Query;
......
......@@ -49,6 +49,36 @@ class QueryTest extends DatabaseTestCase
$this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
}
public function testFilter()
{
$query = new Query;
$query->filter('id = :id', [':id' => 1]);
$this->assertEquals('id = :id', $query->where);
$this->assertEquals([':id' => 1], $query->params);
$query->andFilter('name = :name', [':name' => 'something']);
$this->assertEquals(['and', 'id = :id', 'name = :name'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something'], $query->params);
$query->orFilter('age = :age', [':age' => '30']);
$this->assertEquals(['or', ['and', 'id = :id', 'name = :name'], 'age = :age'], $query->where);
$this->assertEquals([':id' => 1, ':name' => 'something', ':age' => '30'], $query->params);
$query = new Query();
$query->filter('id = :id', [':id' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->andFilter('name = :name', [':name' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
$query->orFilter('age = :age', [':age' => '']);
$this->assertEquals('', $query->where);
$this->assertEquals([], $query->params);
}
public function testJoin()
{
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment