From 99f7d5eca4b17810d98ba14fd4f46f6440cc4ebc Mon Sep 17 00:00:00 2001 From: buddh4 Date: Wed, 4 Apr 2018 11:40:23 +0200 Subject: [PATCH] Enh: Added further `FunctionalTester` utilities --- protected/humhub/docs/CHANGELOG.md | 2 +- .../codeception/_support/FunctionalTester.php | 88 ++++++++++++++++++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 9796313105..34eec29595 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -27,7 +27,7 @@ migrate your code to SpreadsheetExport. PHPOffice is replaced by PHPSpreadsheet. - Fix: User model namespace issue in `humhub/modules/user/components/UrlRule` - Enh: Raised notification over view pagination size to 20 - Enh: Added `humhub/modules/space/models/Module::flushCache()` and `humhub/modules/space/behaviours/SpaceModelModules::flushCache()` in order to flush the space module cache - +- Enh: Added further `FunctionalTester` utilities 1.2.4 (December 13, 2017) -------------------------- diff --git a/protected/humhub/tests/codeception/_support/FunctionalTester.php b/protected/humhub/tests/codeception/_support/FunctionalTester.php index 72133dc26c..8329cdc7d8 100644 --- a/protected/humhub/tests/codeception/_support/FunctionalTester.php +++ b/protected/humhub/tests/codeception/_support/FunctionalTester.php @@ -1,6 +1,9 @@ logout(); + } + LoginPage::openBy($this)->login('admin', 'test'); $this->see('Dashboard'); $this->see('Administration'); @@ -73,7 +80,86 @@ class FunctionalTester extends \Codeception\Actor public function logout() { + $this->amGoingTo('logout'); \Yii::$app->user->logout(true); } + public function enableFriendships($enable = true) + { + Yii::$app->getModule('friendship')->settings->set('enable', $enable); + } + + public function switchIdentity($username) + { + Yii::$app->user->switchIdentity(User::findOne(['username' => $username])); + } + + public function amFriendWith($username) + { + $user = User::findOne(['username' => $username]); + Friendship::add($user, Yii::$app->user->identity); + Friendship::add(Yii::$app->user->identity, $user); + } + + public function setProfileField($field, $value) + { + $user = Yii::$app->user->identity; + $user->profile->setAttributes([$field => $value]); + $user->profile->save(); + } + + public function amOnSpace1($path = '/space/space', $params = []) + { + $this->amOnSpace(1, $path, $params); + } + + public function amOnSpace2($path = '/space/space', $params = []) + { + $this->amOnSpace(2, $path, $params); + } + + public function amOnSpace3($path = '/space/space', $params = []) + { + $this->amOnSpace(3, $path, $params); + } + + public function amOnSpace4($path = '/space/space', $params = []) + { + $this->amOnSpace(4, $path, $params); + } + + 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 = []) + { + if(!$path) { + $path = '/space/space'; + } + + if(is_int($guid)) { + $guid = $this->spaces[--$guid]; + } + + $params['sguid'] = $guid; + + $this->amOnRoute($path, $params); + } + + 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(); + \humhub\modules\space\models\Module::flushCache(); + } + }