appwrite/tests/e2e/ConsoleTest.php

106 lines
3.1 KiB
PHP
Raw Normal View History

2019-09-14 04:37:37 +00:00
<?php
namespace Tests\E2E;
use Tests\E2E\Client;
use PHPUnit\Framework\TestCase;
class ConsoleTest extends TestCase
{
/**
* @var Client
*/
protected $client = null;
protected $endpoint = 'http://localhost/v1';
2019-09-14 08:33:24 +00:00
protected $demoEmail = '';
protected $demoPassword = '';
2019-09-14 04:37:37 +00:00
public function setUp()
{
2019-09-14 08:33:24 +00:00
$this->client = new Client();
2019-09-14 04:37:37 +00:00
$this->client
->setEndpoint($this->endpoint)
;
2019-09-14 08:33:24 +00:00
$this->demoEmail = 'user.' . rand(0,1000000) . '@appwrite.io';
$this->demoPassword = 'password.' . rand(0,1000000);
2019-09-14 04:37:37 +00:00
}
public function tearDown()
{
$this->client = null;
}
public function testRegisterSuccess()
{
$response = $this->client->call(Client::METHOD_POST, '/auth/register', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
], [
2019-09-14 08:33:24 +00:00
'email' => $this->demoEmail,
'password' => $this->demoPassword,
2019-09-14 05:44:55 +00:00
'redirect' => 'http://localhost/confirm',
2019-09-14 04:37:37 +00:00
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
2019-09-14 08:33:24 +00:00
'name' => 'Demo User',
2019-09-14 04:37:37 +00:00
]);
2019-09-14 08:33:24 +00:00
$this->assertEquals('http://localhost/success', $response['headers']['location']);
2019-09-14 04:37:37 +00:00
$this->assertEquals("\n", $response['body']);
2019-09-14 08:33:24 +00:00
return [
'demoEmail' => $this->demoEmail,
'demoPassword' => $this->demoPassword,
];
2019-09-14 04:37:37 +00:00
}
2019-09-14 08:33:24 +00:00
/**
* @depends testRegisterSuccess
*/
public function testLoginSuccess($data)
2019-09-14 04:37:37 +00:00
{
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
], [
2019-09-14 08:33:24 +00:00
'email' => $data['demoEmail'],
'password' => $data['demoPassword'],
2019-09-14 04:37:37 +00:00
'success' => 'http://localhost/success',
'failure' => 'http://localhost/failure',
]);
2019-09-15 16:50:57 +00:00
$session = $this->client->parseCookie($response['headers']['set-cookie'])['a-session-console'];
var_dump($response['headers']);
$this->assertEquals('http://localhost/success', $response['headers']['location']);
$this->assertEquals("\n", $response['body']);
return ['session' => $session];
}
/**
* @depends testLoginSuccess
*/
public function testLogoutSuccess($data)
{
$response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a-session-console=' . $data['session'],
], []);
2019-09-14 12:47:47 +00:00
2019-09-15 16:50:57 +00:00
var_dump($response);
2019-09-14 04:37:37 +00:00
$this->assertEquals('http://localhost/success', $response['headers']['location']);
$this->assertEquals("\n", $response['body']);
}
2019-09-15 16:50:57 +00:00
// public function testLogoutFailure()
// {
// $response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
// 'origin' => 'http://localhost',
// 'content-type' => 'application/json',
// ], []);
// $this->assertEquals('401', $response['body']['code']);
// }
2019-09-14 04:37:37 +00:00
}