Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120823877
PackageTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
PackageTest.php
View Options
<?php
namespace
Tests\Feature
;
use
App\Package
;
use
App\PackageSku
;
use
App\Sku
;
use
Tests\TestCase
;
class
PackageTest
extends
TestCase
{
protected
function
setUp
():
void
{
parent
::
setUp
();
Package
::
where
(
'title'
,
'test-package'
)->
delete
();
}
protected
function
tearDown
():
void
{
Package
::
where
(
'title'
,
'test-package'
)->
delete
();
parent
::
tearDown
();
}
/**
* Test for a package's cost.
*/
public
function
testCost
():
void
{
$skuGroupware
=
Sku
::
withEnvTenantContext
()->
where
(
'title'
,
'groupware'
)->
first
();
// cost: 490
$skuMailbox
=
Sku
::
withEnvTenantContext
()->
where
(
'title'
,
'mailbox'
)->
first
();
// cost: 500
$skuStorage
=
Sku
::
withEnvTenantContext
()->
where
(
'title'
,
'storage'
)->
first
();
// cost: 25
$package
=
Package
::
create
([
'title'
=>
'test-package'
,
'name'
=>
'Test Account'
,
'description'
=>
'Test account.'
,
'discount_rate'
=>
0
,
]);
// WARNING: saveMany() sets package_skus.cost = skus.cost, the next line will reset it to NULL
$package
->
skus
()->
saveMany
([
$skuMailbox
,
$skuGroupware
,
$skuStorage
,
]);
PackageSku
::
where
(
'package_id'
,
$package
->
id
)->
update
([
'cost'
=>
null
]);
// Test a package w/o any extra parameters
$this
->
assertSame
(
490
+
500
,
$package
->
cost
());
// Test a package with pivot's qty
$package
->
skus
()->
updateExistingPivot
(
$skuStorage
,
[
'qty'
=>
6
],
false
);
$package
->
refresh
();
$this
->
assertSame
(
490
+
500
+
25
,
$package
->
cost
());
// Test a package with pivot's cost
$package
->
skus
()->
updateExistingPivot
(
$skuStorage
,
[
'cost'
=>
100
],
false
);
$package
->
refresh
();
$this
->
assertSame
(
490
+
500
+
100
,
$package
->
cost
());
// Test a package with discount_rate
$package
->
discount_rate
=
30
;
$package
->
save
();
$package
->
skus
()->
updateExistingPivot
(
$skuMailbox
,
[
'qty'
=>
2
],
false
);
$package
->
refresh
();
$this
->
assertSame
((
int
)
(
round
(
490
*
0.7
)
+
2
*
round
(
500
*
0.7
)
+
100
),
$package
->
cost
());
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Apr 24, 10:13 AM (2 d, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18844476
Default Alt Text
PackageTest.php (2 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline