Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pasteque
pasteque-server
Commits
0eb3b037
Commit
0eb3b037
authored
Dec 19, 2019
by
Karamel
Browse files
Add a composition test and some fixes.
parent
c8b556d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
0eb3b037
...
...
@@ -14,6 +14,7 @@ The semantic of version number is 'Level.Version'. Level is for compatibility be
### Fixed
-
Sqlite support.
-
Compositions from struct (http calls).
## [8.0-alpha11] - 2019-08-26
...
...
src/lib/Model/CompositionGroup.php
View file @
0eb3b037
...
...
@@ -119,9 +119,14 @@ class CompositionGroup extends DoctrineModel
public
function
clearCompositionProducts
()
{
$this
->
getCompositionProducts
()
->
clear
();
}
public
function
addCompositionProduct
s
(
$compositionProduct
)
{
public
function
addCompositionProduct
(
$compositionProduct
)
{
$this
->
compositionProducts
->
add
(
$compositionProduct
);
$compositionProduct
->
setCompositionGroup
(
$this
);
}
public
function
removeCompositionProduct
(
$prd
)
{
$this
->
compositionProducts
->
removeElement
(
$prd
);
$prd
->
setCompositionGroup
(
null
);
}
}
src/lib/Model/CompositionProduct.php
View file @
0eb3b037
...
...
@@ -51,7 +51,7 @@ class CompositionProduct extends DoctrineModel
public
function
getId
()
{
if
(
$this
->
getCompositionGroup
()
===
null
)
{
return
[
'compositionGroup'
=>
$this
->
getCompositionGroup
()
->
getId
()
,
return
[
'compositionGroup'
=>
null
,
'product'
=>
$this
->
getProduct
()
->
getId
()];
}
else
{
return
[
'compositionGroup'
=>
$this
->
getCompositionGroup
()
->
getId
(),
...
...
src/lib/Model/Product.php
View file @
0eb3b037
...
...
@@ -299,6 +299,10 @@ class Product extends DoctrineModel
$this
->
compositionGroups
->
add
(
$compositionGroup
);
$compositionGroup
->
setProduct
(
$this
);
}
public
function
removeCompositionGroup
(
$compositionGroup
)
{
$this
->
compositionGroups
->
removeElement
(
$compositionGroup
);
$compositionGroup
->
setProduct
(
null
);
}
/** Get sell price with tax.
* Virtual field passed along toStruct at current time.*/
...
...
tests/http/HttpProductTest.php
View file @
0eb3b037
...
...
@@ -22,6 +22,8 @@
namespace
Pasteque\Server
;
use
\
Pasteque\Server\Model\Category
;
use
\
Pasteque\Server\Model\CompositionGroup
;
use
\
Pasteque\Server\Model\CompositionProduct
;
use
\
Pasteque\Server\Model\Product
;
use
\
Pasteque\Server\Model\Tax
;
use
\
Pasteque\Server\System\Login
;
...
...
@@ -99,6 +101,49 @@ class HttpProductTest extends TestCase
$this
->
assertEquals
(
1
,
count
(
$dbPrd
));
}
/** @depends testPutOk */
public
function
testPutCompo
()
{
$prd
=
new
Product
();
$prd
->
setCategory
(
$this
->
cat
);
$prd
->
setTax
(
$this
->
tax
);
$prd
->
setReference
(
'ref'
);
$prd
->
setLabel
(
'label'
);
$prd
->
setPriceSell
(
10
);
$this
->
dao
->
write
(
$prd
);
$this
->
dao
->
commit
();
$compo
=
new
Product
();
$compo
->
setCategory
(
$this
->
cat
);
$compo
->
setTax
(
$this
->
tax
);
$compo
->
setReference
(
'compo'
);
$compo
->
setLabel
(
'Compo'
);
$compo
->
setPriceSell
(
15
);
$compo
->
setComposition
(
true
);
$grp
=
new
CompositionGroup
();
$grp
->
setLabel
(
'Group'
);
$grpPrd
=
new
CompositionProduct
();
$grpPrd
->
setProduct
(
$prd
);
$grp
->
addCompositionProduct
(
$grpPrd
);
$compo
->
addCompositionGroup
(
$grp
);
$struct
=
$compo
->
toStruct
();
unset
(
$struct
[
'id'
]);
unset
(
$struct
[
'compositionGroups'
][
0
][
'id'
]);
unset
(
$struct
[
'compositionGroups'
][
0
][
'compositionProducts'
][
0
][
'id'
]);
var_dump
(
$struct
);
curl_setopt
(
$this
->
curl
,
CURLOPT_CUSTOMREQUEST
,
'PUT'
);
curl_setopt
(
$this
->
curl
,
CURLOPT_URL
,
apiUrl
(
sprintf
(
'api/product/%s'
,
urlencode
(
$compo
->
getReference
()))));
curl_setopt
(
$this
->
curl
,
CURLOPT_POST
,
true
);
curl_setopt
(
$this
->
curl
,
CURLOPT_POSTFIELDS
,
json_encode
(
$struct
));
curl_setopt
(
$this
->
curl
,
CURLOPT_HTTPHEADER
,
[
Login
::
TOKEN_HEADER
.
': '
.
static
::
$token
,
'Content-Type: application/json'
]);
$resp
=
curl_exec
(
$this
->
curl
);
$this
->
assertEquals
(
200
,
curl_getinfo
(
$this
->
curl
,
CURLINFO_HTTP_CODE
));
$dbPrd
=
$this
->
dao
->
search
(
Product
::
class
,
new
DAOCondition
(
'reference'
,
'='
,
$compo
->
getReference
()));
$this
->
assertEquals
(
1
,
count
(
$dbPrd
));
}
public
function
testPutId
()
{
$prd
=
new
Product
();
$prd
->
setCategory
(
$this
->
cat
);
...
...
Write
Preview
Supports
Markdown
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