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
9ee76322
Commit
9ee76322
authored
Sep 16, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added failing test cases for #3725
parent
583c660c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
0 deletions
+131
-0
Customer.php
tests/unit/data/ar/Customer.php
+11
-0
Customer.php
tests/unit/data/ar/elasticsearch/Customer.php
+10
-0
Customer.php
tests/unit/data/ar/redis/Customer.php
+16
-0
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+94
-0
No files found.
tests/unit/data/ar/Customer.php
View file @
9ee76322
...
...
@@ -36,6 +36,17 @@ class Customer extends ActiveRecord
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
orderBy
(
'id'
);
}
public
function
getExpensiveOrders
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
andWhere
(
'total > 50'
)
->
orderBy
(
'id'
);
}
public
function
getExpensiveOrdersWithNullFK
()
{
return
$this
->
hasMany
(
OrderWithNullFK
::
className
(),
[
'customer_id'
=>
'id'
])
->
andWhere
(
'total > 50'
)
->
orderBy
(
'id'
);
}
public
function
getOrdersWithNullFK
()
{
return
$this
->
hasMany
(
OrderWithNullFK
::
className
(),
[
'customer_id'
=>
'id'
])
->
orderBy
(
'id'
);
...
...
tests/unit/data/ar/elasticsearch/Customer.php
View file @
9ee76322
...
...
@@ -35,6 +35,16 @@ class Customer extends ActiveRecord
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
orderBy
(
'created_at'
);
}
public
function
getExpensiveOrders
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
filter
([
'range'
=>
[
'total'
=>
[
'gte'
=>
50
]]])
->
orderBy
(
'id'
);
}
public
function
getExpensiveOrdersWithNullFK
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
filter
([
'range'
=>
[
'total'
=>
[
'gte'
=>
50
]]])
->
orderBy
(
'id'
);
}
public
function
getOrdersWithNullFK
()
{
return
$this
->
hasMany
(
OrderWithNullFK
::
className
(),
[
'customer_id'
=>
'id'
])
->
orderBy
(
'created_at'
);
...
...
tests/unit/data/ar/redis/Customer.php
View file @
9ee76322
...
...
@@ -30,6 +30,22 @@ class Customer extends ActiveRecord
/**
* @return \yii\redis\ActiveQuery
*/
public
function
getExpensiveOrders
()
{
return
$this
->
hasMany
(
Order
::
className
(),
[
'customer_id'
=>
'id'
])
->
andWhere
(
"tonumber(redis.call('HGET','order' .. ':a:' .. pk, 'total')) > 50"
);
}
/**
* @return \yii\redis\ActiveQuery
*/
public
function
getExpensiveOrdersWithNullFK
()
{
return
$this
->
hasMany
(
OrderWithNullFK
::
className
(),
[
'customer_id'
=>
'id'
])
->
andWhere
(
"tonumber(redis.call('HGET','order' .. ':a:' .. pk, 'total')) > 50"
);
}
/**
* @return \yii\redis\ActiveQuery
*/
public
function
getOrdersWithNullFK
()
{
return
$this
->
hasMany
(
OrderWithNullFK
::
className
(),
[
'customer_id'
=>
'id'
]);
...
...
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
9ee76322
...
...
@@ -728,6 +728,54 @@ trait ActiveRecordTestTrait
$this
->
assertEquals
(
2
,
count
(
$order
->
orderItems
));
}
public
function
testUnlinkAndConditionSetNull
()
{
/* @var $this TestCase|ActiveRecordTestTrait */
/* @var $customerClass \yii\db\ActiveRecordInterface */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\ActiveRecordInterface */
$orderClass
=
$this
->
getOrderClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
// removing a model that is not related should not work
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
$customer
->
unlink
(
'expensiveOrdersWithNullFK'
,
$customer
->
orders
[
2
],
false
);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
}
public
function
testUnlinkAndConditionDelete
()
{
/* @var $this TestCase|ActiveRecordTestTrait */
/* @var $customerClass \yii\db\ActiveRecordInterface */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\ActiveRecordInterface */
$orderClass
=
$this
->
getOrderClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
// removing a model that is not related should not work
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrders
));
$customer
->
unlink
(
'expensiveOrders'
,
$customer
->
orders
[
2
],
true
);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrders
));
}
public
function
testUnlinkAll
()
{
/* @var $customerClass \yii\db\ActiveRecordInterface */
...
...
@@ -794,6 +842,52 @@ trait ActiveRecordTestTrait
// via table is covered in \yiiunit\framework\db\ActiveRecordTest::testUnlinkAllViaTable()
}
public
function
testUnlinkAllAndConditionSetNull
()
{
/* @var $this TestCase|ActiveRecordTestTrait */
/* @var $customerClass \yii\db\BaseActiveRecord */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\BaseActiveRecord */
$orderClass
=
$this
->
getOrderClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
$this
->
assertEquals
(
3
,
$orderClass
::
find
()
->
count
());
$customer
->
unlinkAll
(
'expensiveOrdersWithNullFK'
);
$this
->
assertEquals
(
2
,
count
(
$customer
->
ordersWithNullFK
));
$this
->
assertEquals
(
0
,
count
(
$customer
->
expensiveOrdersWithNullFK
));
$this
->
assertEquals
(
3
,
$orderClass
::
find
()
->
count
());
}
public
function
testUnlinkAllAndConditionDelete
()
{
/* @var $this TestCase|ActiveRecordTestTrait */
/* @var $customerClass \yii\db\BaseActiveRecord */
$customerClass
=
$this
->
getCustomerClass
();
/* @var $orderClass \yii\db\BaseActiveRecord */
$orderClass
=
$this
->
getOrderClass
();
// in this test all orders are owned by customer 1
$orderClass
::
updateAll
([
'customer_id'
=>
1
]);
$this
->
afterSave
();
$customer
=
$customerClass
::
findOne
(
1
);
$this
->
assertEquals
(
3
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customer
->
expensiveOrders
));
$this
->
assertEquals
(
3
,
$orderClass
::
find
()
->
count
());
$customer
->
unlinkAll
(
'expensiveOrders'
,
true
);
$this
->
assertEquals
(
2
,
count
(
$customer
->
orders
));
$this
->
assertEquals
(
0
,
count
(
$customer
->
expensiveOrders
));
$this
->
assertEquals
(
2
,
$orderClass
::
find
()
->
count
());
}
public
static
$afterSaveNewRecord
;
public
static
$afterSaveInsert
;
...
...
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