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
e76a4fe1
Verified
Commit
e76a4fe1
authored
7 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
[REFACTORING] test right + res tu
parent
a809b206
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/Test/ResControllerTest.php
+0
-304
0 additions, 304 deletions
core/Test/ResControllerTest.php
src/app/resource/controllers/ResController.php
+3
-1
3 additions, 1 deletion
src/app/resource/controllers/ResController.php
with
3 additions
and
305 deletions
core/Test/ResControllerTest.php
+
0
−
304
View file @
e76a4fe1
<?php
namespace
MaarchTest
;
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
...
...
@@ -9,311 +7,9 @@ namespace MaarchTest;
*
*/
namespace
MaarchTest
;
use
PHPUnit\Framework\TestCase
;
class
ResControllerTest
extends
TestCase
{
public
function
testPrepareStorage
()
{
$action
=
new
\Core\Controllers\ResController
();
$data
=
[];
array_push
(
$data
,
array
(
'column'
=>
'custom_t1'
,
'value'
=>
'TEST'
,
'type'
=>
'string'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'custom_t10'
,
'value'
=>
'lgi@maarch.org'
,
'type'
=>
'string'
,
)
);
$aArgs
=
[
'data'
=>
$data
,
'docserverId'
=>
'FASTHD_MAN'
,
'status'
=>
'new'
,
'fileFormat'
=>
'pdf'
,
];
$response
=
$action
->
prepareStorage
(
$aArgs
);
$this
->
assertArrayHasKey
(
'column'
,
$response
[
0
]);
}
public
function
testStoreResource
()
{
$action
=
new
\Core\Controllers\ResController
();
$path
=
$_SESSION
[
'config'
][
'tmppath'
]
.
'/test/'
;
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
);
}
$fileSource
=
'test_source.txt'
;
if
(
file_exists
(
$path
.
$fileSource
))
{
unlink
(
$path
.
$fileSource
);
}
$fp
=
fopen
(
$path
.
$fileSource
,
'a'
);
fwrite
(
$fp
,
'a unit test'
);
fclose
(
$fp
);
$fileContent
=
file_get_contents
(
$path
.
$fileSource
,
FILE_BINARY
);
$encodedFile
=
base64_encode
(
$fileContent
);
$data
=
[];
array_push
(
$data
,
array
(
'column'
=>
'subject'
,
'value'
=>
'UNIT TEST'
,
'type'
=>
'string'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'type_id'
,
'value'
=>
110
,
'type'
=>
'integer'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'custom_t1'
,
'value'
=>
'TEST'
,
'type'
=>
'string'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'custom_t10'
,
'value'
=>
'lgi@maarch.org'
,
'type'
=>
'string'
,
)
);
$aArgs
=
[
'encodedFile'
=>
$encodedFile
,
'data'
=>
$data
,
'collId'
=>
'letterbox_coll'
,
'table'
=>
'res_letterbox'
,
'fileFormat'
=>
'txt'
,
'status'
=>
'new'
,
];
$response
=
$action
->
storeResource
(
$aArgs
);
$this
->
assertGreaterThanOrEqual
(
0
,
$response
[
0
]);
}
public
function
testDelete
()
{
$action
=
new
\Core\Controllers\ResController
();
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'DELETE'
,
]
);
$resId
=
\Core\Models\ResModel
::
getLastId
([
'select'
=>
[
'res_id'
]]);
$aArgs
=
[
'id'
=>
$resId
[
0
][
'res_id'
]
];
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
new
\Slim\Http\Response
();
$response
=
$action
->
delete
(
$request
,
$response
,
$aArgs
);
$this
->
assertSame
((
string
)
$response
->
getBody
(),
'[true]'
);
}
public
function
testCreate
()
{
$action
=
new
\Core\Controllers\ResController
();
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'POST'
,
]
);
$path
=
$_SESSION
[
'config'
][
'tmppath'
]
.
'/test/'
;
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
);
}
$fileSource
=
'test_source.txt'
;
if
(
file_exists
(
$path
.
$fileSource
))
{
unlink
(
$path
.
$fileSource
);
}
$fp
=
fopen
(
$path
.
$fileSource
,
'a'
);
fwrite
(
$fp
,
'a unit test'
);
fclose
(
$fp
);
$fileContent
=
file_get_contents
(
$path
.
$fileSource
,
FILE_BINARY
);
$encodedFile
=
base64_encode
(
$fileContent
);
//echo $encodedFile . PHP_EOL;exit;
$data
=
[];
array_push
(
$data
,
array
(
'column'
=>
'subject'
,
'value'
=>
'UNIT TEST from slim'
,
'type'
=>
'string'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'type_id'
,
'value'
=>
110
,
'type'
=>
'integer'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'custom_t1'
,
'value'
=>
'TEST'
,
'type'
=>
'string'
,
)
);
array_push
(
$data
,
array
(
'column'
=>
'custom_t10'
,
'value'
=>
'lgi@maarch.org'
,
'type'
=>
'string'
,
)
);
//print_r(json_encode($data));
//sample in json : [{"column":"subject","value":"UNIT T
//EST from slim","type":"string"},{"column":"type_id","value":110,"type":"integer"},
//{"column":"custom_t1","value":"TES
//T","type":"string"},{"column":"custom_t10","value":"lgi@maarch.org","type":"string"}]
$aArgs
=
[
'encodedFile'
=>
$encodedFile
,
'data'
=>
$data
,
'collId'
=>
'letterbox_coll'
,
'table'
=>
'res_letterbox'
,
'fileFormat'
=>
'txt'
,
'status'
=>
'new'
,
];
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
new
\Slim\Http\Response
();
$response
=
$action
->
create
(
$request
,
$response
,
$aArgs
);
$this
->
assertGreaterThan
(
1
,
json_decode
(
$response
->
getBody
())
->
resId
);
}
public
function
testDeleteRes
()
{
$action
=
new
\Core\Controllers\ResController
();
$resId
=
\Core\Models\ResModel
::
getLastId
([
'select'
=>
[
'res_id'
]]);
$aArgs
=
[
'id'
=>
$resId
[
0
][
'res_id'
]
];
$response
=
$action
->
deleteRes
(
$aArgs
);
$this
->
assertTrue
(
$response
);
}
public
function
testUpdate
()
{
$action
=
new
\Core\Controllers\ResController
();
$environment
=
\Slim\Http\Environment
::
mock
(
[
'REQUEST_METHOD'
=>
'POST'
,
]
);
$data
=
[];
array_push
(
$data
,
array
(
'column'
=>
'status'
,
'value'
=>
'NEW'
,
'type'
=>
'string'
,
)
);
$resId
=
\Core\Models\ResModel
::
getLastId
([
'select'
=>
[
'res_id'
]]);
$aArgs
=
[
'table'
=>
'res_letterbox'
,
'res_id'
=>
$resId
[
0
][
'res_id'
],
'data'
=>
$data
,
];
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
new
\Slim\Http\Response
();
$response
=
$action
->
update
(
$request
,
$response
,
$aArgs
);
//print_r(json_decode($response->getBody())[0]->res_id);exit;
$this
->
assertGreaterThan
(
1
,
json_decode
(
$response
->
getBody
())[
0
]
->
res_id
);
}
public
function
testUpdateResource
()
{
$action
=
new
\Core\Controllers\ResController
();
$data
=
[];
array_push
(
$data
,
array
(
'column'
=>
'status'
,
'value'
=>
'NEW'
,
'type'
=>
'string'
,
)
);
$resId
=
\Core\Models\ResModel
::
getLastId
([
'select'
=>
[
'res_id'
]]);
$aArgs
=
[
'table'
=>
'res_letterbox'
,
'res_id'
=>
$resId
[
0
][
'res_id'
],
'data'
=>
$data
,
];
$response
=
$action
->
updateResource
(
$aArgs
);
//print_r($response);exit;
$this
->
assertGreaterThan
(
1
,
$response
);
}
}
This diff is collapsed.
Click to expand it.
src/app/resource/controllers/ResController.php
+
3
−
1
View file @
e76a4fe1
...
...
@@ -171,7 +171,9 @@ class ResController
ValidatorModel
::
stringType
(
$aArgs
,
[
'userId'
]);
ValidatorModel
::
intVal
(
$aArgs
,
[
'resId'
]);
if
(
$aArgs
[
'userId'
]
==
'superadmin'
)
{
return
true
;
}
$groups
=
UserModel
::
getGroupsByUserId
([
'userId'
=>
$aArgs
[
'userId'
]]);
$groupsClause
=
''
;
foreach
(
$groups
as
$key
=>
$group
)
{
...
...
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