You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.1 KiB
97 lines
2.1 KiB
11 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\mongodb;
|
||
11 years ago
|
|
||
11 years ago
|
use yii\mongodb\Query;
|
||
11 years ago
|
|
||
|
/**
|
||
|
* @group mongo
|
||
|
*/
|
||
11 years ago
|
class QueryTest extends MongoDbTestCase
|
||
11 years ago
|
{
|
||
|
public function testSelect()
|
||
|
{
|
||
|
// default
|
||
|
$query = new Query;
|
||
|
$select = [];
|
||
|
$query->select($select);
|
||
|
$this->assertEquals($select, $query->select);
|
||
|
|
||
|
$query = new Query;
|
||
|
$select = ['name', 'something'];
|
||
|
$query->select($select);
|
||
|
$this->assertEquals($select, $query->select);
|
||
|
}
|
||
|
|
||
|
public function testFrom()
|
||
|
{
|
||
|
$query = new Query;
|
||
|
$from = 'customer';
|
||
|
$query->from($from);
|
||
|
$this->assertEquals($from, $query->from);
|
||
|
|
||
|
$query = new Query;
|
||
|
$from = ['', 'customer'];
|
||
|
$query->from($from);
|
||
|
$this->assertEquals($from, $query->from);
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testWhere()
|
||
|
{
|
||
|
$query = new Query;
|
||
|
$query->where(['name' => 'name1']);
|
||
|
$this->assertEquals(['name' => 'name1'], $query->where);
|
||
|
|
||
|
$query->andWhere(['address' => 'address1']);
|
||
|
$this->assertEquals(
|
||
|
[
|
||
11 years ago
|
'and',
|
||
|
['name' => 'name1'],
|
||
|
['address' => 'address1']
|
||
11 years ago
|
],
|
||
|
$query->where
|
||
|
);
|
||
|
|
||
|
$query->orWhere(['name' => 'name2']);
|
||
|
$this->assertEquals(
|
||
|
[
|
||
11 years ago
|
'or',
|
||
|
[
|
||
|
'and',
|
||
|
['name' => 'name1'],
|
||
|
['address' => 'address1']
|
||
11 years ago
|
],
|
||
11 years ago
|
['name' => 'name2']
|
||
11 years ago
|
|
||
|
],
|
||
|
$query->where
|
||
|
);
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testOrder()
|
||
|
{
|
||
|
$query = new Query;
|
||
|
$query->orderBy('team');
|
||
|
$this->assertEquals(['team' => SORT_ASC], $query->orderBy);
|
||
|
|
||
|
$query->addOrderBy('company');
|
||
|
$this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC], $query->orderBy);
|
||
|
|
||
|
$query->addOrderBy('age');
|
||
|
$this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_ASC], $query->orderBy);
|
||
|
|
||
|
$query->addOrderBy(['age' => SORT_DESC]);
|
||
|
$this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_DESC], $query->orderBy);
|
||
|
|
||
|
$query->addOrderBy('age ASC, company DESC');
|
||
|
$this->assertEquals(['team' => SORT_ASC, 'company' => SORT_DESC, 'age' => SORT_ASC], $query->orderBy);
|
||
|
}
|
||
|
|
||
|
public function testLimitOffset()
|
||
|
{
|
||
|
$query = new Query;
|
||
|
$query->limit(10)->offset(5);
|
||
|
$this->assertEquals(10, $query->limit);
|
||
|
$this->assertEquals(5, $query->offset);
|
||
|
}
|
||
|
}
|