Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P8712
API CRUD test in codeception
Active
Public
Actions
Authored by
daniel
on Jul 5 2019, 12:50 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F29681687: raw.txt
Jul 5 2019, 12:50 PM
2019-07-05 12:50:21 (UTC+0)
Subscribers
•
Clarakosi
<?php
class
CRUDCest
{
public
function
_before
(
ApiTester
$I
)
{
}
// tests
public
function
testCreateEditDelete
(
ApiTester
$I
)
{
$I
->
wantTo
(
'Create, edit, and delete'
);
$I
->
haveHttpHeader
(
'Content-Type'
,
'application/x-www-form-urlencoded'
);
$I
->
sendPOST
(
'api.php'
,
[
'action'
=>
'edit'
,
'title'
=>
'Test'
,
'creatonly'
=>
'true'
,
'format'
=>
'json'
,
'summary'
=>
'some test'
,
'text'
=>
'test text'
,
'token'
=>
'+
\\
'
,
]
);
$I
->
seeResponseCodeIs
(
\Codeception\Util\HttpCode
::
OK
);
// 200
$I
->
seeResponseContainsJson
(
[
'edit'
=>
[
'result'
=>
'Success'
]
]);
$I
->
sendGET
(
'api.php'
,
[
'action'
=>
'parse'
,
'page'
=>
'Test'
,
'format'
=>
'json'
,
]
);
$I
->
seeResponseCodeIs
(
\Codeception\Util\HttpCode
::
OK
);
// 200
$I
->
seeResponseIsJson
();
$I
->
seeResponseMatches
(
'/test text/'
);
$I
->
haveHttpHeader
(
'Content-Type'
,
'application/x-www-form-urlencoded'
);
$I
->
sendPOST
(
'api.php'
,
[
'action'
=>
'edit'
,
'title'
=>
'Test'
,
'format'
=>
'json'
,
'summary'
=>
'some edit'
,
'text'
=>
'edited test text'
,
'token'
=>
'+
\\
'
,
]
);
$I
->
seeResponseCodeIs
(
\Codeception\Util\HttpCode
::
OK
);
// 200
$I
->
seeResponseContainsJson
(
[
'edit'
=>
[
'result'
=>
'Success'
]
]);
$I
->
sendGET
(
'api.php'
,
[
'action'
=>
'parse'
,
'page'
=>
'Test'
,
'format'
=>
'json'
,
]
);
$I
->
seeResponseCodeIs
(
\Codeception\Util\HttpCode
::
OK
);
// 200
$I
->
seeResponseIsJson
();
$I
->
seeResponseMatches
(
'/edited test text/'
);
$I
->
haveHttpHeader
(
'Content-Type'
,
'application/x-www-form-urlencoded'
);
$I
->
sendPOST
(
'api.php'
,
[
'action'
=>
'delete'
,
'title'
=>
'Test'
,
'format'
=>
'json'
,
'token'
=>
'+
\\
'
,
]
);
$I
->
seeResponseCodeIs
(
\Codeception\Util\HttpCode
::
OK
);
// 200
$I
->
seeResponseContainsJson
(
[
'delete'
=>
[
'title'
=>
'Test'
]
]);
$I
->
sendGET
(
'api.php'
,
[
'action'
=>
'parse'
,
'page'
=>
'Test'
,
'format'
=>
'json'
,
]
);
$I
->
seeResponseContainsJson
(
[
'error'
=>
[
'code'
=>
'missingtitle'
]
]);
}
}
Event Timeline
daniel
created this paste.
Jul 5 2019, 12:50 PM
2019-07-05 12:50:21 (UTC+0)
daniel
mentioned this in
T222100: Decide whether creating Phester is actually worth while
.
Jul 5 2019, 1:13 PM
2019-07-05 13:13:14 (UTC+0)
Log In to Comment