2020-01-12 02:58:02 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Scopes;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
abstract class Scope extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Client
|
|
|
|
*/
|
|
|
|
protected $client = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $endpoint = 'http://localhost/v1';
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->client = new Client();
|
|
|
|
|
|
|
|
$this->client
|
|
|
|
->setEndpoint($this->endpoint)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
$this->client = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getLastEmail():array
|
|
|
|
{
|
2020-06-14 20:12:26 +12:00
|
|
|
sleep(10);
|
2020-10-31 08:53:27 +13:00
|
|
|
|
2021-01-04 10:22:41 +13:00
|
|
|
$emails = json_decode(file_get_contents('http://maildev:1080/email'), true);
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
if ($emails && is_array($emails)) {
|
2020-01-12 02:58:02 +13:00
|
|
|
return end($emails);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-10-31 08:53:27 +13:00
|
|
|
protected function getLastRequest():array
|
|
|
|
{
|
2020-11-21 10:03:14 +13:00
|
|
|
sleep(5);
|
2020-10-31 08:53:27 +13:00
|
|
|
|
2021-01-04 10:22:41 +13:00
|
|
|
$resquest = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true);
|
2020-10-31 08:53:27 +13:00
|
|
|
$resquest['data'] = json_decode($resquest['data'], true);
|
|
|
|
|
|
|
|
return $resquest;
|
|
|
|
}
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
abstract public function getHeaders():array;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
abstract public function getProject():array;
|
2020-01-13 10:28:26 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $root = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getRoot(): array
|
|
|
|
{
|
2020-10-28 08:48:38 +13:00
|
|
|
if ((self::$root)) {
|
2020-01-13 10:28:26 +13:00
|
|
|
return self::$root;
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = uniqid().'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
$root = $this->client->call(Client::METHOD_POST, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $root['headers']['status-code']);
|
|
|
|
|
|
|
|
$session = $this->client->call(Client::METHOD_POST, '/account/sessions', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2020-07-03 09:48:02 +12:00
|
|
|
$session = $this->client->parseCookie((string)$session['headers']['set-cookie'])['a_session_console'];
|
2020-01-13 10:28:26 +13:00
|
|
|
|
|
|
|
self::$root = [
|
2020-02-17 20:16:11 +13:00
|
|
|
'$id' => $root['body']['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
'name' => $root['body']['name'],
|
2020-01-17 03:06:28 +13:00
|
|
|
'email' => $root['body']['email'],
|
2020-01-13 10:28:26 +13:00
|
|
|
'session' => $session,
|
|
|
|
];
|
|
|
|
|
|
|
|
return self::$root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $user = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getUser(): array
|
|
|
|
{
|
2020-10-28 08:48:38 +13:00
|
|
|
if (isset(self::$user[$this->getProject()['$id']])) {
|
2020-02-17 20:16:11 +13:00
|
|
|
return self::$user[$this->getProject()['$id']];
|
2020-01-13 10:28:26 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
$email = uniqid().'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/account', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
], [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $user['headers']['status-code']);
|
|
|
|
|
|
|
|
$session = $this->client->call(Client::METHOD_POST, '/account/sessions', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
], [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2020-07-03 09:48:02 +12:00
|
|
|
$session = $this->client->parseCookie((string)$session['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
2020-01-13 10:28:26 +13:00
|
|
|
|
2020-02-17 20:16:11 +13:00
|
|
|
self::$user[$this->getProject()['$id']] = [
|
|
|
|
'$id' => $user['body']['$id'],
|
2020-01-13 10:28:26 +13:00
|
|
|
'name' => $user['body']['name'],
|
2020-01-17 03:06:28 +13:00
|
|
|
'email' => $user['body']['email'],
|
2020-01-13 10:28:26 +13:00
|
|
|
'session' => $session,
|
|
|
|
];
|
|
|
|
|
2020-02-17 20:16:11 +13:00
|
|
|
return self::$user[$this->getProject()['$id']];
|
2020-01-13 10:28:26 +13:00
|
|
|
}
|
|
|
|
}
|