2019-09-14 16:37:37 +12:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
2019-09-17 16:21:20 +12:00
|
|
|
class ConsoleTest extends BaseConsole
|
2019-09-14 16:37:37 +12:00
|
|
|
{
|
|
|
|
public function testRegisterSuccess()
|
|
|
|
{
|
2019-09-16 08:17:10 +12:00
|
|
|
$response = $this->register();
|
2019-09-14 16:37:37 +12:00
|
|
|
|
2019-09-14 20:33:24 +12:00
|
|
|
$this->assertEquals('http://localhost/success', $response['headers']['location']);
|
2019-10-02 05:24:55 +13:00
|
|
|
$this->assertEquals("", $response['body']);
|
2019-09-14 16:37:37 +12:00
|
|
|
|
2019-09-14 20:33:24 +12:00
|
|
|
return [
|
2019-09-16 08:17:10 +12:00
|
|
|
'email' => $this->demoEmail,
|
|
|
|
'password' => $this->demoPassword,
|
2019-09-14 20:33:24 +12:00
|
|
|
];
|
2019-09-14 16:37:37 +12:00
|
|
|
}
|
|
|
|
|
2019-09-14 20:33:24 +12:00
|
|
|
/**
|
|
|
|
* @depends testRegisterSuccess
|
|
|
|
*/
|
|
|
|
public function testLoginSuccess($data)
|
2019-09-14 16:37:37 +12:00
|
|
|
{
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
], [
|
2019-09-16 08:17:10 +12:00
|
|
|
'email' => $data['email'],
|
|
|
|
'password' => $data['password'],
|
2019-09-14 16:37:37 +12:00
|
|
|
'success' => 'http://localhost/success',
|
|
|
|
'failure' => 'http://localhost/failure',
|
|
|
|
]);
|
|
|
|
|
2019-09-16 04:50:57 +12:00
|
|
|
$session = $this->client->parseCookie($response['headers']['set-cookie'])['a-session-console'];
|
2019-09-16 06:56:04 +12:00
|
|
|
|
2019-09-16 04:50:57 +12:00
|
|
|
$this->assertEquals('http://localhost/success', $response['headers']['location']);
|
2019-10-02 05:24:55 +13:00
|
|
|
$this->assertEquals("", $response['body']);
|
2019-09-16 04:50:57 +12:00
|
|
|
|
2019-09-16 07:11:01 +12:00
|
|
|
return [
|
2019-09-16 08:17:10 +12:00
|
|
|
'email' => $data['email'],
|
|
|
|
'password' => $data['password'],
|
2019-09-16 07:11:01 +12:00
|
|
|
'session' => $session
|
|
|
|
];
|
2019-09-16 04:50:57 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLoginSuccess
|
|
|
|
*/
|
2019-09-16 07:11:01 +12:00
|
|
|
public function testAccountSuccess($data)
|
|
|
|
{
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'cookie' => 'a-session-console=' . $data['session'],
|
|
|
|
], []);
|
|
|
|
|
|
|
|
$this->assertEquals('Demo User', $response['body']['name']);
|
2019-09-16 07:25:16 +12:00
|
|
|
$this->assertEquals($data['email'], $response['body']['email']);
|
2019-09-16 07:11:01 +12:00
|
|
|
$this->assertEquals(false, $response['body']['confirm']);
|
|
|
|
$this->assertIsArray($response['body']['roles']);
|
2019-09-16 07:25:16 +12:00
|
|
|
$this->assertIsInt($response['body']['registration']);
|
2019-09-16 07:11:01 +12:00
|
|
|
$this->assertEquals('*', $response['body']['roles'][0]);
|
|
|
|
$this->assertEquals('user:' . $response['body']['$uid'], $response['body']['roles'][1]);
|
|
|
|
$this->assertEquals('role:1', $response['body']['roles'][2]);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAccountSuccess
|
|
|
|
*/
|
2019-09-16 06:56:04 +12:00
|
|
|
public function testLogoutSuccess($data)
|
2019-09-16 04:50:57 +12:00
|
|
|
{
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'cookie' => 'a-session-console=' . $data['session'],
|
|
|
|
], []);
|
2019-09-15 00:47:47 +12:00
|
|
|
|
2019-09-16 06:56:04 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('success', $response['body']['result']);
|
2019-09-14 16:37:37 +12:00
|
|
|
}
|
2019-09-16 04:50:57 +12:00
|
|
|
|
2019-09-16 06:56:04 +12:00
|
|
|
public function testLogoutFailure()
|
|
|
|
{
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
], []);
|
2019-09-16 04:50:57 +12:00
|
|
|
|
2019-09-16 06:56:04 +12:00
|
|
|
$this->assertEquals('401', $response['body']['code']);
|
|
|
|
}
|
2019-09-30 19:13:40 +13:00
|
|
|
}
|