forked from directus/v8-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthTest.php
55 lines (43 loc) · 1.4 KB
/
AuthTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use Directus\Api\Routes\Auth as Auth;
use GuzzleHttp\Client;
class AuthTest extends PHPUnit_Framework_TestCase
{
private $http;
public function setUp()
{
$this->http = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/directus-api/public/_/',
'exceptions' => false
]);
}
public function tearDown() {
$this->http = null;
}
public function testAuthentication()
{
$data = [
'form_params' => [
'email' => "admin@example.com",
'password' => "password"
]
];
$response = $this->http->request('POST', 'auth/authenticate', $data);
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(true), true);
$this->assertArrayHasKey('token', $data['data']);
$this->assertTrue(!empty($data['data']['token']));
}
public function testForgotPassword()
{
$data = [
'form_params' => [
'email' => "admin@example.com"
]
];
$response = $this->http->request('POST', 'auth/password/request', $data);
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(true), true);
$this->assertTrue($data['public']);
}
}