mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-18 15:31:06 +08:00
Finished unit test of ActiveDataProvider.
This commit is contained in:
@@ -35,10 +35,9 @@ use yii\db\Connection;
|
|||||||
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
|
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
|
||||||
*
|
*
|
||||||
* ~~~
|
* ~~~
|
||||||
|
* $query = new Query;
|
||||||
* $provider = new ActiveDataProvider(array(
|
* $provider = new ActiveDataProvider(array(
|
||||||
* 'query' => new Query(array(
|
* 'query' => $query->from('tbl_post'),
|
||||||
* 'from' => 'tbl_post',
|
|
||||||
* )),
|
|
||||||
* 'pagination' => array(
|
* 'pagination' => array(
|
||||||
* 'pageSize' => 20,
|
* 'pageSize' => 20,
|
||||||
* ),
|
* ),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
namespace yiiunit\framework\data;
|
namespace yiiunit\framework\data;
|
||||||
|
|
||||||
use yii\data\ActiveDataProvider;
|
use yii\data\ActiveDataProvider;
|
||||||
|
use yii\db\Query;
|
||||||
use yiiunit\data\ar\ActiveRecord;
|
use yiiunit\data\ar\ActiveRecord;
|
||||||
use yiiunit\framework\db\DatabaseTestCase;
|
use yiiunit\framework\db\DatabaseTestCase;
|
||||||
use yiiunit\data\ar\Order;
|
use yiiunit\data\ar\Order;
|
||||||
@@ -27,10 +28,12 @@ class ActiveDataProviderTest extends DatabaseTestCase
|
|||||||
public function testActiveQuery()
|
public function testActiveQuery()
|
||||||
{
|
{
|
||||||
$provider = new ActiveDataProvider(array(
|
$provider = new ActiveDataProvider(array(
|
||||||
'query' => Order::find(),
|
'query' => Order::find()->orderBy('id'),
|
||||||
));
|
));
|
||||||
$orders = $provider->getItems();
|
$orders = $provider->getItems();
|
||||||
$this->assertEquals(3, count($orders));
|
$this->assertEquals(3, count($orders));
|
||||||
|
$this->assertTrue($orders[0] instanceof Order);
|
||||||
|
$this->assertEquals(array(1, 2, 3), $provider->getKeys());
|
||||||
|
|
||||||
$provider = new ActiveDataProvider(array(
|
$provider = new ActiveDataProvider(array(
|
||||||
'query' => Order::find(),
|
'query' => Order::find(),
|
||||||
@@ -44,7 +47,23 @@ class ActiveDataProviderTest extends DatabaseTestCase
|
|||||||
|
|
||||||
public function testQuery()
|
public function testQuery()
|
||||||
{
|
{
|
||||||
|
$query = new Query;
|
||||||
|
$provider = new ActiveDataProvider(array(
|
||||||
|
'query' => $query->from('tbl_order')->orderBy('id'),
|
||||||
|
));
|
||||||
|
$orders = $provider->getItems();
|
||||||
|
$this->assertEquals(3, count($orders));
|
||||||
|
$this->assertTrue(is_array($orders[0]));
|
||||||
|
$this->assertEquals(array(0, 1, 2), $provider->getKeys());
|
||||||
|
|
||||||
|
$query = new Query;
|
||||||
|
$provider = new ActiveDataProvider(array(
|
||||||
|
'query' => $query->from('tbl_order'),
|
||||||
|
'pagination' => array(
|
||||||
|
'pageSize' => 2,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$orders = $provider->getItems();
|
||||||
|
$this->assertEquals(2, count($orders));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user