Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
56a87a34
Commit
56a87a34
authored
7 years ago
by
Alex ORLUC
Browse files
Options
Downloads
Patches
Plain Diff
test crud in progress
parent
118e1053
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/Test/ActionsControllerTest.php
+105
-132
105 additions, 132 deletions
core/Test/ActionsControllerTest.php
with
105 additions
and
132 deletions
core/Test/ActionsControllerTest.php
+
105
−
132
View file @
56a87a34
<?php
namespace
MaarchTest
;
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
* @brief ActionsControllerTest
* @author dev <dev@maarch.org>
* @ingroup core
*/
require_once
__DIR__
.
'/define.php'
;
namespace
MaarchTest
;
use
PHPUnit\Framework\TestCase
;
//require_once __DIR__.'/define.php';
class
ActionsControllerTest
extends
\PHPUnit_Framework_
TestCase
class
ActionsControllerTest
extends
TestCase
{
public
function
testGetList
()
public
function
testCRUD
()
Giovannoni Laurent
@lgi
·
Jul 26, 2017
test unitaire => faire des tests fonction par fonction stp
test unitaire => faire des tests fonction par fonction stp
Please
register
or
sign in
to reply
{
$actionController
=
new
\Core\Controllers\ActionsController
();
// CREATE
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'POST'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
'keyword'
=>
'indexing'
,
'label_action'
=>
'TEST-LABEL'
,
'id_status'
=>
'_NOSTATUS_'
,
'is_system'
=>
'N'
,
'is_folder_action'
=>
'N'
,
'enabled'
=>
'Y'
,
'action_page'
=>
'index_mlb'
,
'history'
=>
'Y'
,
'origin'
=>
'apps'
,
'create_id'
=>
'N'
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$actionController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$id
=
$responseBody
->
action
->
id
;
$this
->
assertInternalType
(
'int'
,
$id
);
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$actionController
->
getByIdForAdministration
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
$id
,
$responseBody
->
id
);
$this
->
assertSame
(
'indexing'
,
$responseBody
->
keyword
);
$this
->
assertSame
(
'TEST-LABEL'
,
$responseBody
->
label_action
);
$this
->
assertSame
(
'_NOSTATUS_'
,
$responseBody
->
id_status
);
$this
->
assertSame
(
'N'
,
$responseBody
->
is_system
);
$this
->
assertSame
(
'N'
,
$responseBody
->
is_folder_action
);
$this
->
assertSame
(
'Y'
,
$responseBody
->
enabled
);
$this
->
assertSame
(
'index_mlb'
,
$responseBody
->
action_page
);
$this
->
assertSame
(
'Y'
,
$responseBody
->
history
);
$this
->
assertSame
(
'apps'
,
$responseBody
->
origin
);
$this
->
assertSame
(
'N'
,
$responseBody
->
create_id
);
// UPDATE
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'PUT'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
'keyword'
=>
''
,
'label_action'
=>
'TEST-LABEL_UPDATED'
,
'id_status'
=>
'COU'
,
'is_system'
=>
'Y'
,
'is_folder_action'
=>
'Y'
,
'enabled'
=>
'N'
,
'action_page'
=>
'process'
,
'history'
=>
'N'
,
'origin'
=>
'apps'
,
'create_id'
=>
'Y'
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$actionController
->
update
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
_ACTION_UPDATED
,
$responseBody
->
success
);
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$actionController
->
getByIdForAdministration
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
$id
,
$responseBody
->
id
);
$this
->
assertSame
(
''
,
$responseBody
->
keyword
);
$this
->
assertSame
(
'TEST-LABEL_UPDATED'
,
$responseBody
->
label_action
);
$this
->
assertSame
(
'COU'
,
$responseBody
->
id_status
);
$this
->
assertSame
(
'Y'
,
$responseBody
->
is_system
);
$this
->
assertSame
(
'Y'
,
$responseBody
->
is_folder_action
);
$this
->
assertSame
(
'N'
,
$responseBody
->
enabled
);
$this
->
assertSame
(
'process'
,
$responseBody
->
action_page
);
$this
->
assertSame
(
'N'
,
$responseBody
->
history
);
$this
->
assertSame
(
'apps'
,
$responseBody
->
origin
);
$this
->
assertSame
(
'Y'
,
$responseBody
->
create_id
);
// DELETE
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'DELETE'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$actionController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
_ACTION_DELETED
,
$responseBody
->
success
);
}
/*public function testGetList()
{
$action = new \Core\Controllers\ActionsController();
...
...
@@ -64,129 +161,5 @@ class ActionsControllerTest extends \PHPUnit_Framework_TestCase
$compare = '[[{"id":1,"keyword":"redirect","label_action":"Rediriger","id_status":"_NOSTATUS_","is_system":"Y","is_folder_action":"N","enabled":"Y","action_page":"redirect","history":"Y","origin":"entities","create_id":"N","category_id":null}]]';
$this->assertSame((string)$response->getBody(), $compare);
}
public
function
testCreate
()
{
$action
=
new
\Core\Controllers\ActionsController
();
$query
=
'keyword=redirect&'
;
$query
.
=
'label_action=test&'
;
$query
.
=
'id_status=_NOSTATUS_&'
;
$query
.
=
'is_system=Y&'
;
$query
.
=
'is_folder_action=N&'
;
$query
.
=
'enabled=Y&'
;
$query
.
=
'action_page=redirect&'
;
$query
.
=
'history=>Y&'
;
$query
.
=
'origin=entities&'
;
$query
.
=
'create_id=N'
;
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'POST'
,
'QUERY_STRING'
=>
$query
,
]
);
$aArgs
=
[
'keyword'
=>
'test'
,
'label_action'
=>
'test'
,
'id_status'
=>
'ESIG'
,
'is_system'
=>
'Y'
,
'is_folder_action'
=>
'N'
,
'enabled'
=>
'Y'
,
'action_page'
=>
'redirect'
,
'history'
=>
'Y'
,
'origin'
=>
'entities'
,
'create_id'
=>
'N'
];
$client
=
new
\GuzzleHttp\Client
([
'base_uri'
=>
'127.0.0.1/MaarchCourrier/rest/actions'
,
// You can set any number of default request options.
'timeout'
=>
2.0
,
]);
$response
=
$client
->
request
(
'POST'
,
''
,
[
'auth'
=>
[
'superadmin'
,
'superadmin'
],
'form_params'
=>
$aArgs
]);
$compare
=
'[{"keyword":"test","label_action":"test","id_status":"ESIG","is_system":"Y","is_folder_action":"N","enabled":"Y","action_page":"redirect","history":"Y","origin":"entities","create_id":"N","category_id":null}]'
;
$obj
=
json_decode
((
string
)
$response
->
getBody
());
unset
(
$obj
[
0
]
->
id
);
$this
->
assertSame
(
json_encode
(
$obj
),
$compare
);
}
public
function
testDelete
()
{
$action
=
new
\Core\Controllers\ActionsController
();
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'DELETE'
,
]
);
$aArgs
=
[
'id'
=>
'5'
];
$client
=
new
\GuzzleHttp\Client
([
'base_uri'
=>
'127.0.0.1/MaarchCourrier/rest/actions/'
,
// You can set any number of default request options.
'timeout'
=>
2.0
,
]);
$response
=
$client
->
request
(
'DELETE'
,
''
.
$aArgs
[
'id'
],
[
'auth'
=>
[
'superadmin'
,
'superadmin'
],
'form_params'
=>
$aArgs
]);
$this
->
assertSame
((
string
)
$response
->
getBody
(),
'[true]'
);
}
public
function
testUpdate
()
{
$action
=
new
\Core\Controllers\ActionsController
();
$query
=
'id=19&'
;
$query
.
=
'keyword=test&'
;
$query
.
=
'label_action=Test AFTER update&'
;
$query
.
=
'id_status=ESIG&'
;
$query
.
=
'is_folder_action=N&'
;
$query
.
=
'action_page=redirect&'
;
$query
.
=
'history=Y&'
;
$aArgs
=
[
'id'
=>
'19'
,
'keyword'
=>
'test'
,
'label_action'
=>
'Test AFTER update'
,
'id_status'
=>
'ESIG'
,
'is_folder_action'
=>
'N'
,
'action_page'
=>
'redirect'
,
'history'
=>
'Y'
];
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'PUT'
,
'QUERY_STRING'
=>
$query
,
]
);
$client
=
new
\GuzzleHttp\Client
([
'base_uri'
=>
'127.0.0.1/MaarchCourrier/rest/actions/'
,
// You can set any number of default request options.
'timeout'
=>
2.0
,
]);
$response
=
$client
->
request
(
'PUT'
,
''
.
$aArgs
[
'id'
],
[
'auth'
=>
[
'superadmin'
,
'superadmin'
],
'form_params'
=>
$aArgs
]);
$compare
=
'[[{"id":19,"keyword":"test","label_action":"Test AFTER update","id_status":"ESIG","is_system":"N","is_folder_action":"N","enabled":"Y","action_page":"redirect","history":"Y","origin":"apps","create_id":"N","category_id":null}]]'
;
$this
->
assertSame
((
string
)
$response
->
getBody
(),
$compare
);
}
}*/
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment