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
9448c3d4
Commit
9448c3d4
authored
Nov 13, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added unit tests for active dataprovider and fixed query tests
parent
65338972
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
154 additions
and
8 deletions
+154
-8
ActiveRelationTrait.php
framework/yii/ar/ActiveRelationTrait.php
+2
-2
ActiveDataProviderTest.php
tests/unit/framework/data/ActiveDataProviderTest.php
+74
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+16
-0
QueryTest.php
tests/unit/framework/db/QueryTest.php
+6
-6
CubridActiveDataProviderTest.php
...unit/framework/db/cubrid/CubridActiveDataProviderTest.php
+14
-0
MssqlActiveDataProviderTest.php
...s/unit/framework/db/mssql/MssqlActiveDataProviderTest.php
+14
-0
PostgreSQLActiveDataProviderTest.php
...t/framework/db/pgsql/PostgreSQLActiveDataProviderTest.php
+14
-0
SqliteActiveDataProviderTest.php
...unit/framework/db/sqlite/SqliteActiveDataProviderTest.php
+14
-0
No files found.
framework/yii/ar/ActiveRelationTrait.php
View file @
9448c3d4
...
...
@@ -97,13 +97,13 @@ trait ActiveRelationTrait
if
(
$this
->
via
instanceof
self
)
{
// via pivot table
/** @var ActiveRelation $viaQuery */
/** @var ActiveRelation
Trait
$viaQuery */
$viaQuery
=
$this
->
via
;
$viaModels
=
$viaQuery
->
findPivotRows
(
$primaryModels
);
$this
->
filterByModels
(
$viaModels
);
}
elseif
(
is_array
(
$this
->
via
))
{
// via relation
/** @var ActiveRelation $viaQuery */
/** @var ActiveRelation
Trait
$viaQuery */
list
(
$viaName
,
$viaQuery
)
=
$this
->
via
;
$viaQuery
->
primaryModel
=
null
;
$viaModels
=
$viaQuery
->
findWith
(
$viaName
,
$primaryModels
);
...
...
tests/unit/framework/data/ActiveDataProviderTest.php
View file @
9448c3d4
...
...
@@ -10,6 +10,8 @@ namespace yiiunit\framework\data;
use
yii\data\ActiveDataProvider
;
use
yii\db\Query
;
use
yiiunit\data\ar\ActiveRecord
;
use
yiiunit\data\ar\Customer
;
use
yiiunit\data\ar\Item
;
use
yiiunit\framework\db\DatabaseTestCase
;
use
yiiunit\data\ar\Order
;
...
...
@@ -18,6 +20,7 @@ use yiiunit\data\ar\Order;
* @since 2.0
*
* @group data
* @group db
*/
class
ActiveDataProviderTest
extends
DatabaseTestCase
{
...
...
@@ -35,6 +38,8 @@ class ActiveDataProviderTest extends DatabaseTestCase
$orders
=
$provider
->
getModels
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
instanceof
Order
);
$this
->
assertTrue
(
$orders
[
1
]
instanceof
Order
);
$this
->
assertTrue
(
$orders
[
2
]
instanceof
Order
);
$this
->
assertEquals
([
1
,
2
,
3
],
$provider
->
getKeys
());
$provider
=
new
ActiveDataProvider
([
...
...
@@ -47,6 +52,75 @@ class ActiveDataProviderTest extends DatabaseTestCase
$this
->
assertEquals
(
2
,
count
(
$orders
));
}
public
function
testActiveRelation
()
{
/** @var Customer $customer */
$customer
=
Customer
::
find
(
2
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$customer
->
getOrders
(),
]);
$orders
=
$provider
->
getModels
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
instanceof
Order
);
$this
->
assertTrue
(
$orders
[
1
]
instanceof
Order
);
$this
->
assertEquals
([
2
,
3
],
$provider
->
getKeys
());
$provider
=
new
ActiveDataProvider
([
'query'
=>
$customer
->
getOrders
(),
'pagination'
=>
[
'pageSize'
=>
1
,
]
]);
$orders
=
$provider
->
getModels
();
$this
->
assertEquals
(
1
,
count
(
$orders
));
}
public
function
testActiveRelationVia
()
{
/** @var Order $order */
$order
=
Order
::
find
(
2
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$order
->
getItems
(),
]);
$items
=
$provider
->
getModels
();
$this
->
assertEquals
(
3
,
count
(
$items
));
$this
->
assertTrue
(
$items
[
0
]
instanceof
Item
);
$this
->
assertTrue
(
$items
[
1
]
instanceof
Item
);
$this
->
assertTrue
(
$items
[
2
]
instanceof
Item
);
$this
->
assertEquals
([
3
,
4
,
5
],
$provider
->
getKeys
());
$provider
=
new
ActiveDataProvider
([
'query'
=>
$order
->
getItems
(),
'pagination'
=>
[
'pageSize'
=>
2
,
]
]);
$items
=
$provider
->
getModels
();
$this
->
assertEquals
(
2
,
count
(
$items
));
}
public
function
testActiveRelationViaTable
()
{
/** @var Order $order */
$order
=
Order
::
find
(
1
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$order
->
getBooks
(),
]);
$items
=
$provider
->
getModels
();
$this
->
assertEquals
(
2
,
count
(
$items
));
$this
->
assertTrue
(
$items
[
0
]
instanceof
Item
);
$this
->
assertTrue
(
$items
[
1
]
instanceof
Item
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$order
->
getBooks
(),
'pagination'
=>
[
'pageSize'
=>
1
,
]
]);
$items
=
$provider
->
getModels
();
$this
->
assertEquals
(
1
,
count
(
$items
));
}
public
function
testQuery
()
{
$query
=
new
Query
;
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
9448c3d4
...
...
@@ -119,10 +119,19 @@ class ActiveRecordTest extends DatabaseTestCase
{
/** @var Customer $customer */
$customer
=
Customer
::
find
(
2
);
$this
->
assertFalse
(
$customer
->
isRelationPopulated
(
'orders'
));
$orders
=
$customer
->
orders
;
$this
->
assertTrue
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
2
,
count
(
$orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
populatedRelations
));
/** @var Customer $customer */
$customer
=
Customer
::
find
(
2
);
$this
->
assertFalse
(
$customer
->
isRelationPopulated
(
'orders'
));
$orders
=
$customer
->
getOrders
()
->
where
(
'id=3'
)
->
all
();
$this
->
assertFalse
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
0
,
count
(
$customer
->
populatedRelations
));
$this
->
assertEquals
(
1
,
count
(
$orders
));
$this
->
assertEquals
(
3
,
$orders
[
0
]
->
id
);
}
...
...
@@ -131,8 +140,15 @@ class ActiveRecordTest extends DatabaseTestCase
{
$customers
=
Customer
::
find
()
->
with
(
'orders'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$customers
));
$this
->
assertTrue
(
$customers
[
0
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertTrue
(
$customers
[
1
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
1
,
count
(
$customers
[
0
]
->
orders
));
$this
->
assertEquals
(
2
,
count
(
$customers
[
1
]
->
orders
));
$customer
=
Customer
::
find
()
->
with
(
'orders'
)
->
one
();
$this
->
assertTrue
(
$customer
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
populatedRelations
));
}
public
function
testFindLazyVia
()
...
...
tests/unit/framework/db/QueryTest.php
View file @
9448c3d4
...
...
@@ -86,19 +86,19 @@ class QueryTest extends DatabaseTestCase
{
$query
=
new
Query
;
$query
->
orderBy
(
'team'
);
$this
->
assertEquals
([
'team'
=>
false
],
$query
->
orderBy
);
$this
->
assertEquals
([
'team'
=>
SORT_ASC
],
$query
->
orderBy
);
$query
->
addOrderBy
(
'company'
);
$this
->
assertEquals
([
'team'
=>
false
,
'company'
=>
false
],
$query
->
orderBy
);
$this
->
assertEquals
([
'team'
=>
SORT_ASC
,
'company'
=>
SORT_ASC
],
$query
->
orderBy
);
$query
->
addOrderBy
(
'age'
);
$this
->
assertEquals
([
'team'
=>
false
,
'company'
=>
false
,
'age'
=>
false
],
$query
->
orderBy
);
$this
->
assertEquals
([
'team'
=>
SORT_ASC
,
'company'
=>
SORT_ASC
,
'age'
=>
SORT_ASC
],
$query
->
orderBy
);
$query
->
addOrderBy
([
'age'
=>
true
]);
$this
->
assertEquals
([
'team'
=>
false
,
'company'
=>
false
,
'age'
=>
true
],
$query
->
orderBy
);
$query
->
addOrderBy
([
'age'
=>
SORT_DESC
]);
$this
->
assertEquals
([
'team'
=>
SORT_ASC
,
'company'
=>
SORT_ASC
,
'age'
=>
SORT_DESC
],
$query
->
orderBy
);
$query
->
addOrderBy
(
'age ASC, company DESC'
);
$this
->
assertEquals
([
'team'
=>
false
,
'company'
=>
true
,
'age'
=>
false
],
$query
->
orderBy
);
$this
->
assertEquals
([
'team'
=>
SORT_ASC
,
'company'
=>
SORT_DESC
,
'age'
=>
SORT_ASC
],
$query
->
orderBy
);
}
public
function
testLimitOffset
()
...
...
tests/unit/framework/db/cubrid/CubridActiveDataProviderTest.php
0 → 100644
View file @
9448c3d4
<?php
namespace
yiiunit\framework\db\cubrid
;
use
yiiunit\framework\data\ActiveDataProviderTest
;
/**
* @group db
* @group cubrid
* @group data
*/
class
CubridActiveDataProviderTest
extends
ActiveDataProviderTest
{
public
$driverName
=
'cubrid'
;
}
tests/unit/framework/db/mssql/MssqlActiveDataProviderTest.php
0 → 100644
View file @
9448c3d4
<?php
namespace
yiiunit\framework\db\mssql
;
use
yiiunit\framework\data\ActiveDataProviderTest
;
/**
* @group db
* @group mssql
* @group data
*/
class
MssqlActiveDataProviderTest
extends
ActiveDataProviderTest
{
public
$driverName
=
'sqlsrv'
;
}
tests/unit/framework/db/pgsql/PostgreSQLActiveDataProviderTest.php
0 → 100644
View file @
9448c3d4
<?php
namespace
yiiunit\framework\db\pgsql
;
use
yiiunit\framework\data\ActiveDataProviderTest
;
/**
* @group db
* @group pgsql
* @group data
*/
class
PostgreSQLActiveDataProviderTest
extends
ActiveDataProviderTest
{
public
$driverName
=
'pgsql'
;
}
tests/unit/framework/db/sqlite/SqliteActiveDataProviderTest.php
0 → 100644
View file @
9448c3d4
<?php
namespace
yiiunit\framework\db\sqlite
;
use
yiiunit\framework\data\ActiveDataProviderTest
;
/**
* @group db
* @group sqlite
* @group data
*/
class
SqliteActiveDataProviderTest
extends
ActiveDataProviderTest
{
public
$driverName
=
'sqlite'
;
}
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