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
89ed3c1d
Commit
89ed3c1d
authored
5 years ago
by
Guillaume Heurtier
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #11403 TIME 2:00 added follow/un-follow unit tests
parent
1ae37e90
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/unitTests/app/resource/UserFollowedResourceControllerTest.php
+191
-0
191 additions, 0 deletions
...Tests/app/resource/UserFollowedResourceControllerTest.php
with
191 additions
and
0 deletions
test/unitTests/app/resource/UserFollowedResourceControllerTest.php
0 → 100644
+
191
−
0
View file @
89ed3c1d
<?php
/**
* 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.
*
*/
use
PHPUnit\Framework\TestCase
;
class
UserFollowedResourceControllerTest
extends
TestCase
{
private
static
$id
=
null
;
public
function
testCreate
()
{
$GLOBALS
[
'userId'
]
=
'cchaplin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$resController
=
new
\Resource\controllers\ResController
();
// CREATE
$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
);
$aArgs
=
[
'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 FOLLOW / UNFOLLOW'
,
'typist'
=>
19
,
'priority'
=>
'poiuytre1357nbvc'
,
'follow'
=>
true
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$resController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
self
::
$id
=
$responseBody
->
resId
;
$this
->
assertInternalType
(
'int'
,
self
::
$id
);
// READ
$res
=
\Resource\models\ResModel
::
getById
([
'resId'
=>
self
::
$id
,
'select'
=>
[
'*'
]]);
$this
->
assertInternalType
(
'array'
,
$res
);
$this
->
assertSame
(
'Breaking News : Superman is alive - PHP unit FOLLOW / UNFOLLOW'
,
$res
[
'subject'
]);
$this
->
assertSame
(
102
,
$res
[
'type_id'
]);
$this
->
assertSame
(
'txt'
,
$res
[
'format'
]);
$this
->
assertSame
(
'NEW'
,
$res
[
'status'
]);
$this
->
assertSame
(
19
,
$res
[
'typist'
]);
$this
->
assertNotNull
(
$res
[
'destination'
]);
$this
->
assertNotNull
(
$res
[
'initiator'
]);
$GLOBALS
[
'userId'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testUnFollow
()
{
$GLOBALS
[
'userId'
]
=
'aackermann'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$usersFollowedResourcesController
=
new
\Resource\controllers\UserFollowedResourceController
();
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$usersFollowedResourcesController
->
unFollow
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$id
]);
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
$GLOBALS
[
'userId'
]
=
'ccharles'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$response
=
$usersFollowedResourcesController
->
unFollow
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Document out of perimeter'
,
$responseBody
->
errors
);
$GLOBALS
[
'userId'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testFollow
()
{
$GLOBALS
[
'userId'
]
=
'aackermann'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$usersFollowedResourcesController
=
new
\Resource\controllers\UserFollowedResourceController
();
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$usersFollowedResourcesController
->
follow
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$id
]);
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
$GLOBALS
[
'userId'
]
=
'ccharles'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$response
=
$usersFollowedResourcesController
->
follow
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$id
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
'Document out of perimeter'
,
$responseBody
->
errors
);
$GLOBALS
[
'userId'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testGetList
()
{
$GLOBALS
[
'userId'
]
=
'aackermann'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$resListController
=
new
\Resource\controllers\UserFollowedResourceController
();
// GET
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$resListController
->
getFollowedResources
(
$request
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertInternalType
(
'int'
,
$responseBody
->
countResources
);
$this
->
assertSame
(
1
,
$responseBody
->
countResources
);
$this
->
assertSame
(
1
,
count
(
$responseBody
->
resources
));
$this
->
assertGreaterThanOrEqual
(
1
,
count
(
$responseBody
->
resources
));
$this
->
assertNotNull
(
$responseBody
->
resources
[
0
]
->
priorityColor
);
$this
->
assertNotNull
(
$responseBody
->
resources
[
0
]
->
statusImage
);
$this
->
assertNotNull
(
$responseBody
->
resources
[
0
]
->
statusLabel
);
$this
->
assertInternalType
(
'int'
,
$responseBody
->
resources
[
0
]
->
resId
);
$this
->
assertSame
(
'Breaking News : Superman is alive - PHP unit FOLLOW / UNFOLLOW'
,
$responseBody
->
resources
[
0
]
->
subject
);
$GLOBALS
[
'userId'
]
=
'bblier'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
$resListController
=
new
\Resource\controllers\UserFollowedResourceController
();
// GET
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$resListController
->
getFollowedResources
(
$request
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertInternalType
(
'int'
,
$responseBody
->
countResources
);
$this
->
assertSame
(
0
,
$responseBody
->
countResources
);
$GLOBALS
[
'userId'
]
=
'superadmin'
;
$userInfo
=
\User\models\UserModel
::
getByLogin
([
'login'
=>
$GLOBALS
[
'userId'
],
'select'
=>
[
'id'
]]);
$GLOBALS
[
'id'
]
=
$userInfo
[
'id'
];
}
public
function
testDelete
()
{
// DELETE
\Resource\models\ResModel
::
delete
([
'resId'
=>
self
::
$id
]);
// READ
$res
=
\Resource\models\ResModel
::
getById
([
'resId'
=>
self
::
$id
,
'select'
=>
[
'*'
]]);
$this
->
assertInternalType
(
'array'
,
$res
);
$this
->
assertSame
(
'DEL'
,
$res
[
'status'
]);
}
}
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