Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
aa31b56a
Commit
aa31b56a
authored
Jul 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished unit test of ActiveDataProvider.
parent
53a1f960
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
ActiveDataProvider.php
framework/yii/data/ActiveDataProvider.php
+2
-3
ActiveDataProviderTest.php
tests/unit/framework/data/ActiveDataProviderTest.php
+21
-2
No files found.
framework/yii/data/ActiveDataProvider.php
View file @
aa31b56a
...
...
@@ -35,10 +35,9 @@ use yii\db\Connection;
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
*
* ~~~
* $query = new Query;
* $provider = new ActiveDataProvider(array(
* 'query' => new Query(array(
* 'from' => 'tbl_post',
* )),
* 'query' => $query->from('tbl_post'),
* 'pagination' => array(
* 'pageSize' => 20,
* ),
...
...
tests/unit/framework/data/ActiveDataProviderTest.php
View file @
aa31b56a
...
...
@@ -8,6 +8,7 @@
namespace
yiiunit\framework\data
;
use
yii\data\ActiveDataProvider
;
use
yii\db\Query
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\framework\db\DatabaseTestCase
;
use
yiiunit\data\ar\Order
;
...
...
@@ -27,10 +28,12 @@ class ActiveDataProviderTest extends DatabaseTestCase
public
function
testActiveQuery
()
{
$provider
=
new
ActiveDataProvider
(
array
(
'query'
=>
Order
::
find
(),
'query'
=>
Order
::
find
()
->
orderBy
(
'id'
)
,
));
$orders
=
$provider
->
getItems
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
instanceof
Order
);
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$provider
->
getKeys
());
$provider
=
new
ActiveDataProvider
(
array
(
'query'
=>
Order
::
find
(),
...
...
@@ -44,7 +47,23 @@ class ActiveDataProviderTest extends DatabaseTestCase
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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment