Added FunctionalTester::follow()

Added `HumHubDbTestCase::setProfileField()` and `HumHubDbTestCase::becomeFriendWith()` and `HumHubDbTestCase::follow()`  and`HumHubDbTestCase::enableFriendships()`
This commit is contained in:
buddh4 2018-04-17 17:14:27 +02:00
parent 61f1ccc002
commit 04b60dd69a
2 changed files with 40 additions and 0 deletions

View File

@ -101,8 +101,16 @@ class FunctionalTester extends \Codeception\Actor
Friendship::add(Yii::$app->user->identity, $user);
}
public function follow($username)
{
User::findOne(['username' => $username])->follow();
}
public function setProfileField($field, $value)
{
$output = new \Codeception\Lib\Console\Output([]);
$output->writeln("Set attribute $field : $value");
$user = Yii::$app->user->identity;
$user->profile->setAttributes([$field => $value]);
$user->profile->save();

View File

@ -2,6 +2,7 @@
namespace tests\codeception\_support;
use humhub\modules\friendship\models\Friendship;
use Yii;
use yii\base\Event;
use yii\db\ActiveRecord;
@ -172,6 +173,37 @@ class HumHubDbTestCase extends Test
}
}
public function setProfileField($field, $value, $user)
{
if(is_int($user)) {
$user = User::findOne($user);
} else if (is_string($user)) {
$user = User::findOne(['username' => $user]);
} else if (!$user) {
$user = Yii::$app->user->identity;
}
$user->profile->setAttributes([$field => $value]);
$user->profile->save();
}
public function becomeFriendWith($username)
{
$user = User::findOne(['username' => $username]);
Friendship::add($user, Yii::$app->user->identity);
Friendship::add(Yii::$app->user->identity, $user);
}
public function follow($username)
{
User::findOne(['username' => $username])->follow();
}
public function enableFriendships($enable = true)
{
Yii::$app->getModule('friendship')->settings->set('enable', $enable);
}
public function setGroupPermission($groupId, $permission, $state = BasePermission::STATE_ALLOW)
{
$permissionManger = new PermissionManager();