From 53a1f9608ad2f7e6de8b831466a2530f5fb9a254 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 9 Jul 2013 08:47:19 -0400 Subject: [PATCH] Added unit test for ActiveDataProvider. --- framework/yii/data/ActiveDataProvider.php | 18 +++++++- .../unit/framework/data/ActiveDataProviderTest.php | 50 ++++++++++++++++++++++ tests/unit/framework/db/ActiveRecordTest.php | 1 - 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests/unit/framework/data/ActiveDataProviderTest.php diff --git a/framework/yii/data/ActiveDataProvider.php b/framework/yii/data/ActiveDataProvider.php index 44158a7..29f9fab 100644 --- a/framework/yii/data/ActiveDataProvider.php +++ b/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 * @since 2.0 */ diff --git a/tests/unit/framework/data/ActiveDataProviderTest.php b/tests/unit/framework/data/ActiveDataProviderTest.php new file mode 100644 index 0000000..61b8256 --- /dev/null +++ b/tests/unit/framework/data/ActiveDataProviderTest.php @@ -0,0 +1,50 @@ + + * @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() + { + + + } +} diff --git a/tests/unit/framework/db/ActiveRecordTest.php b/tests/unit/framework/db/ActiveRecordTest.php index c23377d..b089ece 100644 --- a/tests/unit/framework/db/ActiveRecordTest.php +++ b/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(); }