mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Enhance API tester (#4976)
This commit is contained in:
parent
168ab6483c
commit
59be4ad2d0
@ -7,6 +7,7 @@ HumHub Changelog
|
||||
- Fix #4959: Horizontal scrollbar for images
|
||||
- Fix #4898: No streamExcludes option when loading single stream entry
|
||||
- Enh #4960: Added “codeception/module-rest” for testing of REST API modules
|
||||
- Enh #4976: Added REST API Codeception tester
|
||||
- Enh #4967: Module update broken with expired licence key
|
||||
- Enh #4972: Fix enabling to send notification on remove user from group
|
||||
- Fix #4985: Fix Activity Mail QueryParams on console mode
|
||||
|
@ -23,9 +23,9 @@ class MailInviteCest
|
||||
$I->amUser2();
|
||||
$I->amOnSpace1();
|
||||
$I->see('Invite');
|
||||
$I->amGoingTo('invte a user by mail');
|
||||
$I->amGoingTo('invite a user by mail');
|
||||
|
||||
$I->sendAjaxPostRequest(Url::to(['/space/membership/invite', 'cguid' => $I->spaces[0]]), ['InviteForm[inviteExternal]' => 'a@test.de,b@test.de']);
|
||||
$I->sendAjaxPostRequest(Url::to(['/space/membership/invite', 'cguid' => $I->getFixtureSpace(0)->guid]), ['InviteForm[inviteExternal]' => 'a@test.de,b@test.de']);
|
||||
$I->seeEmailIsSent(2);
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ use \Facebook\WebDriver\WebDriverKeys;
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class AcceptanceTester extends \Codeception\Actor
|
||||
class AcceptanceTester extends BaseTester
|
||||
{
|
||||
use _generated\AcceptanceTesterActions;
|
||||
|
||||
@ -61,13 +61,6 @@ class AcceptanceTester extends \Codeception\Actor
|
||||
$this->amUser('User3', '123qwe', $logout);
|
||||
}
|
||||
|
||||
public $spaces = [
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34a',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34b',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34c',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34d',
|
||||
];
|
||||
|
||||
public function amOnSpace1($path = '/space/space', $params = [])
|
||||
{
|
||||
$this->amOnSpace(1, $path, $params);
|
||||
@ -95,7 +88,7 @@ class AcceptanceTester extends \Codeception\Actor
|
||||
}
|
||||
|
||||
if(is_int($guid)) {
|
||||
$guid = $this->spaces[--$guid];
|
||||
$guid = $this->getFixtureSpaceGuid(--$guid);
|
||||
}
|
||||
|
||||
$params['sguid'] = $guid;
|
||||
|
@ -21,7 +21,7 @@ use yii\web\Link;
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class ApiTester extends \Codeception\Actor
|
||||
class ApiTester extends BaseTester
|
||||
{
|
||||
use _generated\ApiTesterActions;
|
||||
|
||||
@ -50,25 +50,61 @@ class ApiTester extends \Codeception\Actor
|
||||
$this->amHttpAuthenticated($user, $password);
|
||||
}
|
||||
|
||||
public function seeSuccessResponseContainsJson($json = [])
|
||||
public function seeCodeResponseContainsJson($code, $json = [])
|
||||
{
|
||||
$this->seeResponseCodeIs(HttpCode::OK);
|
||||
$this->seeResponseCodeIs($code);
|
||||
$this->seeResponseIsJson();
|
||||
$this->seeResponseContainsJson($json);
|
||||
}
|
||||
|
||||
public function seeSuccessResponseContainsJson($json = [])
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::OK, $json);
|
||||
}
|
||||
|
||||
public function seeForbiddenResponseContainsJson($json = [])
|
||||
{
|
||||
$this->seeResponseCodeIs(HttpCode::FORBIDDEN);
|
||||
$this->seeResponseIsJson();
|
||||
$this->seeResponseContainsJson($json);
|
||||
$this->seeCodeResponseContainsJson(HttpCode::FORBIDDEN, $json);
|
||||
}
|
||||
|
||||
public function seeBadResponseContainsJson($json = [])
|
||||
{
|
||||
$this->seeResponseCodeIs(HttpCode::BAD_REQUEST);
|
||||
$this->seeResponseIsJson();
|
||||
$this->seeResponseContainsJson($json);
|
||||
$this->seeCodeResponseContainsJson(HttpCode::BAD_REQUEST, $json);
|
||||
}
|
||||
|
||||
public function seeNotFoundResponseContainsJson($json = [])
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::NOT_FOUND, $json);
|
||||
}
|
||||
|
||||
public function seeServerErrorResponseContainsJson($json = [])
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::INTERNAL_SERVER_ERROR, $json);
|
||||
}
|
||||
|
||||
public function seeSuccessMessage($message)
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::OK, ['message' => $message]);
|
||||
}
|
||||
|
||||
public function seeForbiddenMessage($message)
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::FORBIDDEN, ['message' => $message]);
|
||||
}
|
||||
|
||||
public function seeBadMessage($message)
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::BAD_REQUEST, ['message' => $message]);
|
||||
}
|
||||
|
||||
public function seeNotFoundMessage($message)
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::NOT_FOUND, ['message' => $message]);
|
||||
}
|
||||
|
||||
public function seeServerErrorMessage($message)
|
||||
{
|
||||
$this->seeCodeResponseContainsJson(HttpCode::INTERNAL_SERVER_ERROR, ['message' => $message]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,10 +170,12 @@ class ApiTester extends \Codeception\Actor
|
||||
*/
|
||||
public function seePaginationResponseContainsJson($url, $jsonResults = [], $paginationParams = [])
|
||||
{
|
||||
$jsonResultsCount = count($jsonResults);
|
||||
|
||||
$json = array_merge([
|
||||
'total' => count($jsonResults),
|
||||
'total' => $jsonResultsCount,
|
||||
'page' => 1,
|
||||
'pages' => 1,
|
||||
'pages' => $jsonResultsCount ? 1 : 0,
|
||||
], $paginationParams);
|
||||
|
||||
$json['links'] = $this->getPaginationUrls($url, $json);
|
||||
|
53
protected/humhub/tests/codeception/_support/BaseTester.php
Normal file
53
protected/humhub/tests/codeception/_support/BaseTester.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space\tests\codeception\fixtures\SpaceFixture;
|
||||
|
||||
/**
|
||||
* Base class for testers
|
||||
*
|
||||
* Inherited Methods
|
||||
* @method void haveFixtures($fixtures)
|
||||
* @method Space grabFixture($fixtureName, $index)
|
||||
*/
|
||||
class BaseTester extends \Codeception\Actor
|
||||
{
|
||||
/**
|
||||
* @var Space[]
|
||||
*/
|
||||
private $spaces;
|
||||
|
||||
public function getFixtureSpace(int $index) : ?Space
|
||||
{
|
||||
if (method_exists($this, 'haveFixtures') && method_exists($this, 'grabFixture')) {
|
||||
$this->haveFixtures(['space' => SpaceFixture::class]);
|
||||
return $this->grabFixture('space', $index);
|
||||
} else {
|
||||
// Acceptance tests have no the methods above, try to get spaces from DB instead:
|
||||
if (!isset($this->spaces)) {
|
||||
$this->spaces = Space::find()->orderBy('id')->all();
|
||||
}
|
||||
return isset($this->spaces[$index]) ? $this->spaces[$index] : null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFixtureSpaceGuid(int $index) : string
|
||||
{
|
||||
$space = $this->getFixtureSpace($index);
|
||||
return ($space instanceof Space ? $space->guid : '');
|
||||
}
|
||||
|
||||
public function enableModule($indexOrGuid, $moduleId)
|
||||
{
|
||||
if (is_int($indexOrGuid)) {
|
||||
$space = $this->getFixtureSpace(--$indexOrGuid);
|
||||
} else {
|
||||
$space = Space::findOne(['guid' => $indexOrGuid]);
|
||||
}
|
||||
|
||||
if ($space) {
|
||||
$space->enableModule($moduleId);
|
||||
Yii::$app->moduleManager->flushCache();
|
||||
}
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ use yii\helpers\Url;
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class FunctionalTester extends \Codeception\Actor
|
||||
class FunctionalTester extends BaseTester
|
||||
{
|
||||
|
||||
use _generated\FunctionalTesterActions;
|
||||
@ -235,13 +235,6 @@ class FunctionalTester extends \Codeception\Actor
|
||||
$this->amOnSpace(4, $path, $params, $post);
|
||||
}
|
||||
|
||||
public $spaces = [
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34a',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34b',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34c',
|
||||
'5396d499-20d6-4233-800b-c6c86e5fa34d',
|
||||
];
|
||||
|
||||
public function amOnSpace($guid, $path = '/space/space', $params = [], $post = false)
|
||||
{
|
||||
if(is_bool($params)) {
|
||||
@ -254,9 +247,11 @@ class FunctionalTester extends \Codeception\Actor
|
||||
}
|
||||
|
||||
if(is_int($guid)) {
|
||||
$guid = $this->spaces[--$guid];
|
||||
$guid = $this->getFixtureSpaceGuid(--$guid);
|
||||
} else if($guid instanceof Space) {
|
||||
$guid = $guid->guid;
|
||||
} else {
|
||||
$guid = '';
|
||||
}
|
||||
|
||||
$params['cguid'] = $guid;
|
||||
@ -288,15 +283,4 @@ class FunctionalTester extends \Codeception\Actor
|
||||
tests\codeception\_pages\DashboardPage::openBy($this);
|
||||
}
|
||||
|
||||
public function enableModule($guid, $moduleId)
|
||||
{
|
||||
if(is_int($guid)) {
|
||||
$guid = $this->spaces[--$guid];
|
||||
}
|
||||
|
||||
$space = Space::findOne(['guid' => $guid]);
|
||||
$space->enableModule($moduleId);
|
||||
Yii::$app->moduleManager->flushCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user