mirror of
https://github.com/flarum/framework.git
synced 2025-01-26 14:30:46 +08:00
36 lines
803 B
PHP
36 lines
803 B
PHP
<?php
|
|
namespace Codeception\Module;
|
|
|
|
use Laracasts\TestDummy\Factory;
|
|
use Auth;
|
|
use DB;
|
|
|
|
class ApiHelper extends \Codeception\Module
|
|
{
|
|
public function haveAnAccount($data = [])
|
|
{
|
|
return Factory::create('Flarum\Core\Users\User', $data);
|
|
}
|
|
|
|
public function login($identification, $password)
|
|
{
|
|
$this->getModule('REST')->sendPOST('/api/auth/login', ['identification' => $identification, 'password' => $password]);
|
|
|
|
$response = json_decode($this->getModule('REST')->grabResponse(), true);
|
|
if ($response && is_array($response) && isset($response['token'])) {
|
|
return $response['token'];
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function amAuthenticated()
|
|
{
|
|
$user = $this->haveAnAccount();
|
|
$user->groups()->attach(3); // Add member group
|
|
Auth::onceUsingId($user->id);
|
|
|
|
return $user;
|
|
}
|
|
}
|