1
0
mirror of https://github.com/flarum/core.git synced 2025-02-24 03:05:12 +01:00
php-flarum/tests/_support/ApiHelper.php

36 lines
803 B
PHP
Raw Normal View History

2015-01-19 20:46:14 +10:30
<?php
namespace Codeception\Module;
2015-01-22 14:44:33 +10:30
use Laracasts\TestDummy\Factory;
use Auth;
use DB;
2015-01-19 20:46:14 +10:30
class ApiHelper extends \Codeception\Module
{
2015-01-22 14:44:33 +10:30
public function haveAnAccount($data = [])
{
return Factory::create('Flarum\Core\Users\User', $data);
}
2015-01-19 20:46:14 +10:30
2015-01-23 15:24:38 +10:30
public function login($identification, $password)
2015-01-22 14:44:33 +10:30
{
2015-01-23 15:24:38 +10:30
$this->getModule('REST')->sendPOST('/api/auth/login', ['identification' => $identification, 'password' => $password]);
2015-01-22 14:44:33 +10:30
$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;
}
2015-01-19 20:46:14 +10:30
}