Browse Source

Added unit test for ActiveDataProvider.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
53a1f9608a
  1. 18
      framework/yii/data/ActiveDataProvider.php
  2. 50
      tests/unit/framework/data/ActiveDataProviderTest.php
  3. 1
      tests/unit/framework/db/ActiveRecordTest.php

18
framework/yii/data/ActiveDataProvider.php

@ -18,7 +18,7 @@ use yii\db\Connection;
*
* 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(
@ -32,6 +32,22 @@ use yii\db\Connection;
* $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>
* @since 2.0
*/

50
tests/unit/framework/data/ActiveDataProviderTest.php

@ -0,0 +1,50 @@
<?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()
{
}
}

1
tests/unit/framework/db/ActiveRecordTest.php

@ -14,7 +14,6 @@ class ActiveRecordTest extends DatabaseTestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
ActiveRecord::$db = $this->getConnection();
}

Loading…
Cancel
Save