Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
anis
anis-server
Commits
a7bd85ce
Commit
a7bd85ce
authored
Nov 24, 2020
by
François Agneray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GroupActionTest => ok
parent
17988738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
198 additions
and
1 deletion
+198
-1
tests/Action/GroupActionTest.php
tests/Action/GroupActionTest.php
+197
-0
tests/Action/GroupListActionTest.php
tests/Action/GroupListActionTest.php
+1
-1
No files found.
tests/Action/GroupActionTest.php
0 → 100644
View file @
a7bd85ce
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare
(
strict_types
=
1
);
namespace
App\Tests\Action
;
use
PHPUnit\Framework\TestCase
;
use
Nyholm\Psr7\ServerRequest
;
use
Nyholm\Psr7\Response
;
use
Slim\Exception\HttpNotFoundException
;
use
Slim\Exception\HttpBadRequestException
;
use
App\tests\EntityManagerBuilder
;
use
App\Entity\Group
;
use
App\Entity\Database
;
use
App\Entity\Project
;
use
App\Entity\Instance
;
use
App\Entity\DatasetFamily
;
use
App\Entity\Dataset
;
final
class
GroupActionTest
extends
TestCase
{
private
$action
;
private
$entityManager
;
protected
function
setUp
():
void
{
$this
->
entityManager
=
EntityManagerBuilder
::
getInstance
();
$this
->
action
=
new
\
App\Action\GroupAction
(
$this
->
entityManager
);
}
public
function
testOptionsHttpMethod
():
void
{
$request
=
$this
->
getRequest
(
'OPTIONS'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
$this
->
assertSame
(
$response
->
getHeaderLine
(
'Access-Control-Allow-Methods'
),
'GET, PUT, DELETE, OPTIONS'
);
}
public
function
testGroupIsNotFound
():
void
{
$this
->
expectException
(
HttpNotFoundException
::
class
);
$this
->
expectExceptionMessage
(
'Group with id 1 is not found'
);
$request
=
$this
->
getRequest
(
'GET'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertEquals
(
404
,
(
int
)
$response
->
getStatusCode
());
}
public
function
testGetAGroupById
():
void
{
$group
=
$this
->
addAGroup
();
$request
=
$this
->
getRequest
(
'GET'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertSame
(
json_encode
(
$group
),
(
string
)
$response
->
getBody
());
}
public
function
testEditAGroupEmptyLabelField
():
void
{
$this
->
addAGroup
();
$this
->
expectException
(
HttpBadRequestException
::
class
);
$this
->
expectExceptionMessage
(
'Param label needed to edit the group'
);
$request
=
$this
->
getRequest
(
'PUT'
)
->
withParsedBody
(
array
());
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertEquals
(
400
,
(
int
)
$response
->
getStatusCode
());
}
public
function
testEditAGroupWithoutDataset
():
void
{
$fields
=
array
(
'label'
=>
'New_label'
,
'datasets'
=>
array
()
);
$this
->
addAGroup
();
$request
=
$this
->
getRequest
(
'PUT'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertSame
(
json_encode
(
array_merge
([
'id'
=>
1
],
$fields
)),
(
string
)
$response
->
getBody
());
}
public
function
testEditAGroupWithDataset
():
void
{
$dataset
=
$this
->
addADataset
();
$fields
=
array
(
'label'
=>
'New_label'
,
'datasets'
=>
array
(
$dataset
->
getName
())
);
$this
->
addAGroup
();
$request
=
$this
->
getRequest
(
'PUT'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertSame
(
json_encode
(
array_merge
([
'id'
=>
1
],
$fields
)),
(
string
)
$response
->
getBody
());
}
public
function
testDeleteAGroup
():
void
{
$this
->
addAGroup
();
$request
=
$this
->
getRequest
(
'DELETE'
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
(
'id'
=>
1
));
$this
->
assertSame
(
json_encode
(
array
(
'message'
=>
'Group with id 1 is removed!'
)),
(
string
)
$response
->
getBody
()
);
}
protected
function
tearDown
():
void
{
$this
->
entityManager
->
getConnection
()
->
close
();
}
private
function
getRequest
(
string
$method
):
ServerRequest
{
return
new
ServerRequest
(
$method
,
'/group/1'
,
array
(
'Content-Type'
=>
'application/json'
));
}
private
function
addAGroup
():
Group
{
$group
=
new
Group
();
$group
->
setLabel
(
'Group1'
);
$group
->
setDatasets
(
array
());
$this
->
entityManager
->
persist
(
$group
);
$this
->
entityManager
->
flush
();
return
$group
;
}
private
function
addProject
():
Project
{
$database
=
new
Database
();
$database
->
setLabel
(
'Test1'
);
$database
->
setDbName
(
'test1'
);
$database
->
setType
(
'pgsql'
);
$database
->
setHost
(
'db'
);
$database
->
setPort
(
5432
);
$database
->
setLogin
(
'test'
);
$database
->
setPassword
(
'test'
);
$this
->
entityManager
->
persist
(
$database
);
$project
=
new
Project
(
'anis_project'
);
$project
->
setLabel
(
'Test project'
);
$project
->
setDescription
(
'Test description'
);
$project
->
setLink
(
'http://test.com'
);
$project
->
setManager
(
'User1'
);
$project
->
setDatabase
(
$database
);
$this
->
entityManager
->
persist
(
$project
);
$this
->
entityManager
->
flush
();
return
$project
;
}
private
function
addInstance
():
Instance
{
$instance
=
new
Instance
(
'aspic'
,
'Aspic'
);
$instance
->
setClientUrl
(
'http://cesam.lam.fr/aspic'
);
$this
->
entityManager
->
persist
(
$instance
);
$this
->
entityManager
->
flush
();
return
$instance
;
}
private
function
addDatasetFamily
():
DatasetFamily
{
$instance
=
$this
->
addInstance
();
$family
=
new
DatasetFamily
(
$instance
);
$family
->
setLabel
(
'Default dataset'
);
$family
->
setDisplay
(
10
);
$this
->
entityManager
->
persist
(
$family
);
$this
->
entityManager
->
flush
();
return
$family
;
}
private
function
addADataset
():
Dataset
{
$project
=
$this
->
addProject
();
$family
=
$this
->
addDatasetFamily
();
$dataset
=
new
Dataset
(
'obs_cat'
);
$dataset
->
setTableRef
(
'v_obs_cat'
);
$dataset
->
setLabel
(
'Obscat label'
);
$dataset
->
setDescription
(
'Obscat description'
);
$dataset
->
setDisplay
(
10
);
$dataset
->
setCount
(
10000
);
$dataset
->
setVo
(
false
);
$dataset
->
setDataPath
(
'/mnt/obs_cat'
);
$dataset
->
setPublic
(
true
);
$dataset
->
setProject
(
$project
);
$dataset
->
setDatasetFamily
(
$family
);
$this
->
entityManager
->
persist
(
$dataset
);
$this
->
entityManager
->
flush
();
return
$dataset
;
}
}
tests/Action/GroupListActionTest.php
View file @
a7bd85ce
...
...
@@ -82,7 +82,7 @@ final class GroupListActionTest extends TestCase
$dataset
=
$this
->
addADataset
();
$fields
=
array
(
'label'
=>
'group1'
,
'datasets'
=>
[
$dataset
->
getName
()
]
'datasets'
=>
array
(
$dataset
->
getName
()
)
);
$request
=
$this
->
getRequest
(
'POST'
)
->
withParsedBody
(
$fields
);
$response
=
(
$this
->
action
)(
$request
,
new
Response
(),
array
());
...
...
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