Commit 53a1f960 by Qiang Xue

Added unit test for ActiveDataProvider.

parent 3996c799
...@@ -18,7 +18,7 @@ use yii\db\Connection; ...@@ -18,7 +18,7 @@ use yii\db\Connection;
* *
* ActiveDataProvider provides data by performing DB queries using [[query]]. * ActiveDataProvider provides data by performing DB queries using [[query]].
* *
* The following is an example of using ActiveDataProvider: * The following is an example of using ActiveDataProvider to provide ActiveRecord instances:
* *
* ~~~ * ~~~
* $provider = new ActiveDataProvider(array( * $provider = new ActiveDataProvider(array(
...@@ -32,6 +32,22 @@ use yii\db\Connection; ...@@ -32,6 +32,22 @@ use yii\db\Connection;
* $posts = $provider->getItems(); * $posts = $provider->getItems();
* ~~~ * ~~~
* *
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
*
* ~~~
* $provider = new ActiveDataProvider(array(
* 'query' => new Query(array(
* 'from' => 'tbl_post',
* )),
* 'pagination' => array(
* 'pageSize' => 20,
* ),
* ));
*
* // get the posts in the current page
* $posts = $provider->getItems();
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\data;
use yii\data\ActiveDataProvider;
use yiiunit\data\ar\ActiveRecord;
use yiiunit\framework\db\DatabaseTestCase;
use yiiunit\data\ar\Order;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveDataProviderTest extends DatabaseTestCase
{
protected function setUp()
{
parent::setUp();
ActiveRecord::$db = $this->getConnection();
}
public function testActiveQuery()
{
$provider = new ActiveDataProvider(array(
'query' => Order::find(),
));
$orders = $provider->getItems();
$this->assertEquals(3, count($orders));
$provider = new ActiveDataProvider(array(
'query' => Order::find(),
'pagination' => array(
'pageSize' => 2,
)
));
$orders = $provider->getItems();
$this->assertEquals(2, count($orders));
}
public function testQuery()
{
}
}
...@@ -14,7 +14,6 @@ class ActiveRecordTest extends DatabaseTestCase ...@@ -14,7 +14,6 @@ class ActiveRecordTest extends DatabaseTestCase
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
$this->mockApplication();
ActiveRecord::$db = $this->getConnection(); ActiveRecord::$db = $this->getConnection();
} }
......
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