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
cfe6e86c
Commit
cfe6e86c
authored
4 years ago
by
Guillaume Heurtier
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #13676 TIME 4:25 finish improve template tests
parent
20f6569f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/template/controllers/TemplateController.php
+1
-1
1 addition, 1 deletion
src/app/template/controllers/TemplateController.php
test/unitTests/app/template/TemplateControllerTest.php
+234
-2
234 additions, 2 deletions
test/unitTests/app/template/TemplateControllerTest.php
with
235 additions
and
3 deletions
src/app/template/controllers/TemplateController.php
+
1
−
1
View file @
cfe6e86c
...
@@ -476,7 +476,7 @@ class TemplateController
...
@@ -476,7 +476,7 @@ class TemplateController
return
$response
->
withJson
([
'templates'
=>
$templates
]);
return
$response
->
withJson
([
'templates'
=>
$templates
]);
}
}
public
static
function
mergeEmailTemplate
(
Request
$request
,
Response
$response
,
array
$args
)
public
function
mergeEmailTemplate
(
Request
$request
,
Response
$response
,
array
$args
)
{
{
if
(
!
Validator
::
intVal
()
->
validate
(
$args
[
'id'
]))
{
if
(
!
Validator
::
intVal
()
->
validate
(
$args
[
'id'
]))
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Route param id is not an integer'
]);
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Route param id is not an integer'
]);
...
...
This diff is collapsed.
Click to expand it.
test/unitTests/app/template/TemplateControllerTest.php
+
234
−
2
View file @
cfe6e86c
...
@@ -16,6 +16,7 @@ class TemplateControllerTest extends TestCase
...
@@ -16,6 +16,7 @@ class TemplateControllerTest extends TestCase
private
static
$idDuplicated
=
null
;
private
static
$idDuplicated
=
null
;
private
static
$idDuplicated2
=
null
;
private
static
$idDuplicated2
=
null
;
private
static
$idAcknowledgementReceipt
=
null
;
private
static
$idAcknowledgementReceipt
=
null
;
private
static
$resId
=
null
;
public
function
testCreate
()
public
function
testCreate
()
...
@@ -36,7 +37,7 @@ class TemplateControllerTest extends TestCase
...
@@ -36,7 +37,7 @@ class TemplateControllerTest extends TestCase
'content'
=>
'Content of this template'
,
'content'
=>
'Content of this template'
,
],
],
'datasource'
=>
'letterbox_attachment'
,
'datasource'
=>
'letterbox_attachment'
,
'entities'
=>
[
'DGS'
,
'COU'
]
'entities'
=>
[
'DGS'
,
'COU'
,
'PSF'
]
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
...
@@ -317,7 +318,7 @@ class TemplateControllerTest extends TestCase
...
@@ -317,7 +318,7 @@ class TemplateControllerTest extends TestCase
'file'
=>
[
'file'
=>
[
'content'
=>
'Content of this template'
,
'content'
=>
'Content of this template'
,
],
],
'entities'
=>
[
'TST_AR'
]
'entities'
=>
[
'TST_AR'
,
'PSF'
]
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
...
@@ -558,6 +559,227 @@ class TemplateControllerTest extends TestCase
...
@@ -558,6 +559,227 @@ class TemplateControllerTest extends TestCase
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
}
public
function
testGetContentById
()
{
$templates
=
new
\Template\controllers\TemplateController
();
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$templates
->
getContentById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id2
]);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertIsString
(
$responseBody
[
'encodedDocument'
]);
// Fail
$response
=
$templates
->
getContentById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id2
*
1000
]);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
'Template does not exist'
,
$responseBody
[
'errors'
]);
$response
=
$templates
->
getContentById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id
]);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
'Template has no office content'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'bbain'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$response
=
$templates
->
getContentById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id2
*
1000
]);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
'Service forbidden'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testGetByResId
()
{
$templates
=
new
\Template\controllers\TemplateController
();
$resController
=
new
\Resource\controllers\ResController
();
// CREATE
$GLOBALS
[
'login'
]
=
'cchaplin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'POST'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$fileContent
=
file_get_contents
(
'test/unitTests/samples/test.txt'
);
$encodedFile
=
base64_encode
(
$fileContent
);
$argsMailNew
=
[
'modelId'
=>
1
,
'status'
=>
'NEW'
,
'encodedFile'
=>
$encodedFile
,
'format'
=>
'txt'
,
'confidentiality'
=>
false
,
'documentDate'
=>
'2019-01-01 17:18:47'
,
'arrivalDate'
=>
'2019-01-01 17:18:47'
,
'processLimitDate'
=>
'2029-01-01'
,
'doctype'
=>
102
,
'destination'
=>
15
,
'initiator'
=>
15
,
'subject'
=>
'Breaking News : Superman is alive - PHP unit'
,
'typist'
=>
19
,
'priority'
=>
'poiuytre1357nbvc'
,
'followed'
=>
true
,
'diffusionList'
=>
[
[
'id'
=>
11
,
'type'
=>
'user'
,
'mode'
=>
'dest'
]
]
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$argsMailNew
,
$request
);
$response
=
$resController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
self
::
$resId
=
$responseBody
[
'resId'
];
$this
->
assertIsInt
(
self
::
$resId
);
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$queryParams
=
[
'attachmentType'
=>
'response_project'
];
$fullRequest
=
$request
->
withQueryParams
(
$queryParams
);
$response
=
$templates
->
getByResId
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
]);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertIsArray
(
$responseBody
[
'templates'
]);
$this
->
assertNotEmpty
(
$responseBody
[
'templates'
]);
$this
->
assertSame
(
1042
,
$responseBody
[
'templates'
][
0
][
'id'
]);
$this
->
assertSame
(
'PR - Demande de Place en crèche'
,
$responseBody
[
'templates'
][
0
][
'label'
]);
$this
->
assertSame
(
'docx'
,
$responseBody
[
'templates'
][
0
][
'extension'
]);
$this
->
assertSame
(
false
,
$responseBody
[
'templates'
][
0
][
'exists'
]);
$this
->
assertSame
(
'response_project'
,
$responseBody
[
'templates'
][
0
][
'attachmentType'
]);
// Fail
$response
=
$templates
->
getByResId
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
'wrong format'
]);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
'Route resId is not an integer'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'bbain'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$response
=
$templates
->
getByResId
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
*
1000
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Document out of perimeter'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testGetEmailTemplatesByResId
()
{
$templates
=
new
\Template\controllers\TemplateController
();
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$templates
->
getEmailTemplatesByResId
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
]);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertIsArray
(
$responseBody
[
'templates'
]);
$this
->
assertNotEmpty
(
$responseBody
[
'templates'
]);
$this
->
assertSame
(
1043
,
$responseBody
[
'templates'
][
0
][
'id'
]);
$this
->
assertSame
(
'AR TYPE SIMPLE- Courriel Manuel'
,
$responseBody
[
'templates'
][
0
][
'label'
]);
// Fail
$GLOBALS
[
'login'
]
=
'bbain'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$response
=
$templates
->
getEmailTemplatesByResId
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
*
1000
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Document out of perimeter'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testMergeEmailTemplate
()
{
$GLOBALS
[
'login'
]
=
'aackermann'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$templates
=
new
\Template\controllers\TemplateController
();
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$body
=
[
'data'
=>
[
'resId'
=>
self
::
$resId
]
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$body
,
$request
);
$response
=
$templates
->
mergeEmailTemplate
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Content of this template'
,
$responseBody
[
'mergedDocument'
]);
// Fail
$response
=
$templates
->
mergeEmailTemplate
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
'wrong format'
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Route param id is not an integer'
,
$responseBody
[
'errors'
]);
$response
=
$templates
->
mergeEmailTemplate
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id
*
1000
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Template does not exist'
,
$responseBody
[
'errors'
]);
$response
=
$templates
->
mergeEmailTemplate
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$id
]);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
(),
true
);
$this
->
assertSame
(
'Body param resId is missing'
,
$responseBody
[
'errors'
]);
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testDelete
()
public
function
testDelete
()
{
{
$templates
=
new
\Template\controllers\TemplateController
();
$templates
=
new
\Template\controllers\TemplateController
();
...
@@ -641,6 +863,16 @@ class TemplateControllerTest extends TestCase
...
@@ -641,6 +863,16 @@ class TemplateControllerTest extends TestCase
$GLOBALS
[
'login'
]
=
'superadmin'
;
$GLOBALS
[
'login'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'login'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
// Delete resource
\Resource\models\ResModel
::
delete
([
'where'
=>
[
'res_id = ?'
],
'data'
=>
[
self
::
$resId
]
]);
$res
=
\Resource\models\ResModel
::
getById
([
'resId'
=>
self
::
$resId
,
'select'
=>
[
'*'
]]);
$this
->
assertIsArray
(
$res
);
$this
->
assertEmpty
(
$res
);
}
}
public
function
testInitTemplate
()
public
function
testInitTemplate
()
...
...
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