diff --git a/tests/old/AccountTest.php b/tests/old/AccountTest.php deleted file mode 100644 index 739250dce..000000000 --- a/tests/old/AccountTest.php +++ /dev/null @@ -1,930 +0,0 @@ -demo(); } -} - -class AccountTest extends Base -{ - use TraitDemo; - - public function demo() { - var_dump(4321); - } - - public function testCreateAccount():array - { - $email = uniqid().'user@localhost.test'; - $password = 'password'; - $name = 'User Name'; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password, - 'name' => $name, - ]); - - $uid = $response['body']['$uid']; - - $this->assertEquals($response['headers']['status-code'], 201); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']['$uid']); - $this->assertIsNumeric($response['body']['registration']); - $this->assertEquals($response['body']['email'], $email); - $this->assertEquals($response['body']['name'], $name); - - /** - * Test for FAILURE - */ - $response = $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($response['headers']['status-code'], 409); - - return [ - 'uid' => $uid, - 'email' => $email, - 'password' => $password, - 'name' => $name, - ]; - } - - /** - * @depends testCreateAccount - */ - public function testCreateAccountSession($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $password = (isset($data['password'])) ? $data['password'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password, - ]); - - $sessionUid = $response['body']['$uid']; - $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - $this->assertEquals($response['headers']['status-code'], 201); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email.'x', - 'password' => $password, - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password.'x', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => '', - 'password' => '', - ]); - - $this->assertEquals($response['headers']['status-code'], 400); - - return array_merge($data, [ - 'sessionUid' => $sessionUid, - 'session' => $session, - ]); - } - - /** - * @depends testCreateAccountSession - */ - public function testGetAccount($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $name = (isset($data['name'])) ? $data['name'] : ''; - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']['$uid']); - $this->assertIsNumeric($response['body']['registration']); - $this->assertEquals($response['body']['email'], $email); - $this->assertEquals($response['body']['name'], $name); - $this->assertContains('*', $response['body']['roles']); - $this->assertContains('user:'.$response['body']['$uid'], $response['body']['roles']); - $this->assertContains('role:1', $response['body']['roles']); - $this->assertCount(3, $response['body']['roles']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session.'xx', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testCreateAccountSession - */ - public function testGetAccountPrefs($data):array - { - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertEmpty($response['body']); - $this->assertCount(0, $response['body']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account/prefs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testCreateAccountSession - */ - public function testGetAccountSessions($data):array - { - $session = (isset($data['session'])) ? $data['session'] : ''; - $sessionUid = (isset($data['sessionUid'])) ? $data['sessionUid'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertCount(1, $response['body']); - $this->assertEquals($sessionUid, $response['body'][0]['$uid']); - - $this->assertIsArray($response['body'][0]['OS']); - $this->assertEquals('Windows', $response['body'][0]['OS']['name']); - $this->assertEquals('WIN', $response['body'][0]['OS']['short_name']); - $this->assertEquals('10', $response['body'][0]['OS']['version']); - $this->assertEquals('x64', $response['body'][0]['OS']['platform']); - - $this->assertIsArray($response['body'][0]['client']); - $this->assertEquals('browser', $response['body'][0]['client']['type']); - $this->assertEquals('Chrome', $response['body'][0]['client']['name']); - $this->assertEquals('CH', $response['body'][0]['client']['short_name']); // FIXME (v1) key name should be camelcase - $this->assertEquals('70.0', $response['body'][0]['client']['version']); - $this->assertEquals('Blink', $response['body'][0]['client']['engine']); - $this->assertEquals(0, $response['body'][0]['device']); - $this->assertEquals('', $response['body'][0]['brand']); - $this->assertEquals('', $response['body'][0]['model']); - $this->assertEquals($response['body'][0]['ip'], filter_var($response['body'][0]['ip'], FILTER_VALIDATE_IP)); - - $this->assertIsArray($response['body'][0]['geo']); - $this->assertEquals('--', $response['body'][0]['geo']['isoCode']); - $this->assertEquals('Unknown', $response['body'][0]['geo']['country']); - - $this->assertEquals(true, $response['body'][0]['current']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testCreateAccountSession - */ - public function testGetAccountLogs($data):array - { - sleep(5); - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertCount(2, $response['body']); - - $this->assertEquals('account.create', $response['body'][0]['event']); - $this->assertEquals($response['body'][0]['ip'], filter_var($response['body'][0]['ip'], FILTER_VALIDATE_IP)); - $this->assertIsNumeric($response['body'][0]['time']); - - $this->assertIsArray($response['body'][0]['OS']); - $this->assertEquals('Windows', $response['body'][0]['OS']['name']); - $this->assertEquals('WIN', $response['body'][0]['OS']['short_name']); - $this->assertEquals('10', $response['body'][0]['OS']['version']); - $this->assertEquals('x64', $response['body'][0]['OS']['platform']); - - $this->assertIsArray($response['body'][0]['client']); - $this->assertEquals('browser', $response['body'][0]['client']['type']); - $this->assertEquals('Chrome', $response['body'][0]['client']['name']); - $this->assertEquals('CH', $response['body'][0]['client']['short_name']); // FIXME (v1) key name should be camelcase - $this->assertEquals('70.0', $response['body'][0]['client']['version']); - $this->assertEquals('Blink', $response['body'][0]['client']['engine']); - $this->assertEquals(0, $response['body'][0]['device']); - $this->assertEquals('', $response['body'][0]['brand']); - $this->assertEquals('', $response['body'][0]['model']); - $this->assertEquals($response['body'][0]['ip'], filter_var($response['body'][0]['ip'], FILTER_VALIDATE_IP)); - - $this->assertIsArray($response['body'][0]['geo']); - $this->assertEquals('--', $response['body'][0]['geo']['isoCode']); - $this->assertEquals('Unknown', $response['body'][0]['geo']['country']); - - $this->assertEquals('account.sessions.create', $response['body'][1]['event']); - $this->assertEquals($response['body'][1]['ip'], filter_var($response['body'][0]['ip'], FILTER_VALIDATE_IP)); - $this->assertIsNumeric($response['body'][1]['time']); - - $this->assertIsArray($response['body'][1]['OS']); - $this->assertEquals('Windows', $response['body'][1]['OS']['name']); - $this->assertEquals('WIN', $response['body'][1]['OS']['short_name']); - $this->assertEquals('10', $response['body'][1]['OS']['version']); - $this->assertEquals('x64', $response['body'][1]['OS']['platform']); - - $this->assertIsArray($response['body'][1]['client']); - $this->assertEquals('browser', $response['body'][1]['client']['type']); - $this->assertEquals('Chrome', $response['body'][1]['client']['name']); - $this->assertEquals('CH', $response['body'][1]['client']['short_name']); // FIXME (v1) key name should be camelcase - $this->assertEquals('70.0', $response['body'][1]['client']['version']); - $this->assertEquals('Blink', $response['body'][1]['client']['engine']); - $this->assertEquals(0, $response['body'][1]['device']); - $this->assertEquals('', $response['body'][1]['brand']); - $this->assertEquals('', $response['body'][1]['model']); - $this->assertEquals($response['body'][1]['ip'], filter_var($response['body'][0]['ip'], FILTER_VALIDATE_IP)); - - $this->assertIsArray($response['body'][1]['geo']); - $this->assertEquals('--', $response['body'][1]['geo']['isoCode']); - $this->assertEquals('Unknown', $response['body'][1]['geo']['country']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account/logs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - //TODO Add tests for OAuth session creation - - /** - * @depends testCreateAccountSession - */ - public function testUpdateAccountName($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $session = (isset($data['session'])) ? $data['session'] : ''; - $newName = 'New Name'; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'name' => $newName - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']['$uid']); - $this->assertIsNumeric($response['body']['registration']); - $this->assertEquals($response['body']['email'], $email); - $this->assertEquals($response['body']['name'], $newName); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - ]); - - $this->assertEquals($response['headers']['status-code'], 400); - - $response = $this->client->call(Client::METHOD_PATCH, '/account/name', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'ocSRq1d3QphHivJyUmYY7WMnrxyjdk5YvVwcDqx2zS0coxESN8RmsQwLWw5Whnf0WbVohuFWTRAaoKgCOO0Y0M7LwgFnZmi8881Y7' - ]); - - $this->assertEquals($response['headers']['status-code'], 400); - - $data['name'] = $newName; - - return $data; - } - - /** - * @depends testUpdateAccountName - */ - public function testUpdateAccountPassword($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $password = (isset($data['password'])) ? $data['password'] : ''; - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'password' => 'new-password', - 'old-password' => $password, - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']['$uid']); - $this->assertIsNumeric($response['body']['registration']); - $this->assertEquals($response['body']['email'], $email); - $this->assertEquals($response['body']['name'], 'New Name'); - - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => 'new-password', - ]); - - $this->assertEquals($response['headers']['status-code'], 201); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_PATCH, '/account/password', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - ]); - - $this->assertEquals($response['headers']['status-code'], 400); - - $data['password'] = 'new-password'; - - return $data; - } - - /** - * @depends testUpdateAccountPassword - */ - public function testUpdateAccountEmail($data):array - { - $newEmail = uniqid().'new@localhost.test'; - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'email' => $newEmail, - 'password' => 'new-password', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']['$uid']); - $this->assertIsNumeric($response['body']['registration']); - $this->assertEquals($response['body']['email'], $newEmail); - $this->assertEquals($response['body']['name'], 'New Name'); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - $response = $this->client->call(Client::METHOD_PATCH, '/account/email', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - ]); - - $this->assertEquals($response['headers']['status-code'], 400); - - $data['email'] = $newEmail; - - return $data; - } - - /** - * @depends testUpdateAccountEmail - */ - public function testUpdateAccountPrefs($data):array - { - $newEmail = uniqid().'new@localhost.test'; - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'prefs' => [ - 'key1' => 'value1', - 'key2' => 'value2', - ] - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertNotEmpty($response['body']); - $this->assertEquals('value1', $response['body']['key1']); - $this->assertEquals('value2', $response['body']['key2']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testUpdateAccountPrefs - */ - public function testDeleteAccountSession($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $password = (isset($data['password'])) ? $data['password'] : ''; - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password, - ]); - - $sessionNewUid = $response['body']['$uid']; - $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - $this->assertEquals($response['headers']['status-code'], 201); - - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - - $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/'.$sessionNewUid, [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 204); - - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testUpdateAccountPrefs - */ - public function testDeleteAccountSessionCurrent($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $password = (isset($data['password'])) ? $data['password'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password, - ]); - - $sessionNew = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - $this->assertEquals($response['headers']['status-code'], 201); - - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - - $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions/current', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 204); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $sessionNew, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - return $data; - } - - /** - * @depends testUpdateAccountPrefs - */ - public function testDeleteAccountSessions($data):array - { - $session = (isset($data['session'])) ? $data['session'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_DELETE, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 204); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ]); - - $this->assertEquals($response['headers']['status-code'], 401); - - /** - * Create new fallback session - */ - $email = (isset($data['email'])) ? $data['email'] : ''; - $password = (isset($data['password'])) ? $data['password'] : ''; - - $response = $this->client->call(Client::METHOD_POST, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'password' => $password, - ]); - - $data['session'] = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - return $data; - } - - /** - * @depends testDeleteAccountSession - */ - public function testCreateAccountRecovery($data):array - { - $email = (isset($data['email'])) ? $data['email'] : ''; - $name = (isset($data['name'])) ? $data['name'] : ''; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'reset' => 'http://localhost/recovery', - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty(3, $response['body']['$uid']); - $this->assertEquals(3, $response['body']['type']); - $this->assertIsNumeric($response['body']['expire']); - - $lastEmail = $this->getLastEmail(); - - $this->assertEquals($email, $lastEmail['to'][0]['address']); - $this->assertEquals($name, $lastEmail['to'][0]['name']); - $this->assertEquals('Password Reset', $lastEmail['subject']); - - $recovery = substr($lastEmail['text'], strpos($lastEmail['text'], '&userId=', 0) + 8, 256); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'reset' => 'localhost/recovery', - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $email, - 'reset' => 'http://remotehost/recovery', - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_POST, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => 'not-found@localhost.test', - 'reset' => 'http://localhost/recovery', - ]); - - $this->assertEquals(404, $response['headers']['status-code']); - - $data['recovery'] = $recovery; - - return $data; - } - - /** - * @depends testCreateAccountRecovery - */ - public function testUpdateAccountRecovery($data):array - { - $uid = (isset($data['uid'])) ? $data['uid'] : ''; - $recovery = (isset($data['recovery'])) ? $data['recovery'] : ''; - $newPassowrd = 'test-recovery'; - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'userId' => $uid, - 'secret' => $recovery, - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - /** - * Test for FAILURE - */ - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'userId' => 'ewewe', - 'secret' => $recovery, - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, - ]); - - $this->assertEquals(404, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'userId' => $uid, - 'secret' => 'sdasdasdasd', - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, - ]); - - $this->assertEquals(401, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'userId' => $uid, - 'secret' => $recovery, - 'password-a' => $newPassowrd.'x', - 'password-b' => $newPassowrd, - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - return $data; - } -} \ No newline at end of file diff --git a/tests/old/Base.php b/tests/old/Base.php deleted file mode 100644 index 24104d782..000000000 --- a/tests/old/Base.php +++ /dev/null @@ -1,41 +0,0 @@ -client = new Client(); - - $this->client - ->setEndpoint($this->endpoint) - ; - } - - protected function tearDown(): void - { - $this->client = null; - } - - protected function getLastEmail():array - { - sleep(3); - $emails = json_decode(file_get_contents('http://localhost:1080/email'), true); - - if($emails && is_array($emails)) { - return end($emails); - } - - return []; - } -} diff --git a/tests/old/BaseConsole.php b/tests/old/BaseConsole.php deleted file mode 100644 index 4c8c36cd5..000000000 --- a/tests/old/BaseConsole.php +++ /dev/null @@ -1,124 +0,0 @@ -client = new Client(); - - $this->client - ->setEndpoint($this->endpoint) - ; - - $this->demoEmail = 'user.' . rand(0, 1000000) . '@appwrite.io'; - $this->demoPassword = 'password.' . rand(0, 1000000); - } - - protected function tearDown(): void - { - $this->client = null; - } - - public function register() - { - $response = $this->client->call(Client::METHOD_POST, '/auth/register', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $this->demoEmail, - 'password' => $this->demoPassword, - 'confirm' => 'http://localhost/confirm', - 'success' => 'http://localhost/success', - 'failure' => 'http://localhost/failure', - 'name' => 'Demo User', - ]); - - return $response; - } - - public function initProject(array $scopes): array { - $response = $this->register(); - - $this->assertEquals('http://localhost/success', $response['headers']['location']); - $this->assertEquals("", $response['body']); - - $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - $team = $this->client->call(Client::METHOD_POST, '/teams', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'Demo Project Team', - ]); - - $this->assertEquals(201, $team['headers']['status-code']); - $this->assertEquals('Demo Project Team', $team['body']['name']); - $this->assertNotEmpty($team['body']['$uid']); - - $project = $this->client->call(Client::METHOD_POST, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'Demo Project', - 'teamId' => $team['body']['$uid'], - 'description' => 'Demo Project Description', - 'logo' => '', - 'url' => 'https://appwrite.io', - 'legalName' => '', - 'legalCountry' => '', - 'legalState' => '', - 'legalCity' => '', - 'legalAddress' => '', - 'legalTaxId' => '', - ]); - - $this->assertEquals(201, $project['headers']['status-code']); - $this->assertNotEmpty($project['body']); - - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$uid'] . '/keys', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $session, - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'Demo Project Key', - 'scopes' => $scopes, - ]); - - $this->assertEquals(201, $project['headers']['status-code']); - $this->assertNotEmpty($key['body']); - $this->assertNotEmpty($key['body']['secret']); - - $user = $this->projectRegister($project['body']['$uid']); - - $this->assertEquals('http://localhost/success', $user['headers']['location']); - $this->assertEquals("", $user['body']); - - return [ - 'email' => $this->demoEmail, - 'password' => $this->demoPassword, - 'session' => $session, - 'projectUid' => $project['body']['$uid'], - 'projectAPIKeySecret' => $key['body']['secret'], - 'projectSession' => $this->client->parseCookie($user['headers']['set-cookie'])['a_session_' . $project['body']['$uid']], - ]; - } -} diff --git a/tests/old/BaseProjects.php b/tests/old/BaseProjects.php deleted file mode 100644 index bca982ae9..000000000 --- a/tests/old/BaseProjects.php +++ /dev/null @@ -1,47 +0,0 @@ -projectsDemoEmail = 'user.' . rand(0, 1000000) . '@appwrite.io'; - $this->projectsDemoPassword = 'password.' . rand(0, 1000000); - } - - protected function tearDown(): void - { - parent::tearDown(); - - $this->client = null; - } - - public function projectRegister($projectId) - { - $response = $this->client->call(Client::METHOD_POST, '/auth/register', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], [ - 'email' => $this->projectsDemoEmail, - 'password' => $this->projectsDemoPassword, - 'confirm' => 'http://localhost/confirm', - 'success' => 'http://localhost/success', - 'failure' => 'http://localhost/failure', - 'name' => 'Porject Demo User', - ]); - - return $response; - } -} diff --git a/tests/old/ConsoleHealthTest.php b/tests/old/ConsoleHealthTest.php deleted file mode 100644 index 26c49fa95..000000000 --- a/tests/old/ConsoleHealthTest.php +++ /dev/null @@ -1,91 +0,0 @@ -client->call(Client::METHOD_GET, '/health', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); - } - - public function testDBSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); - } - - public function testCacheSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); - } - - public function testTimeSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/time', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['remote']); - $this->assertIsInt($response['body']['local']); - $this->assertNotEmpty($response['body']['remote']); - $this->assertNotEmpty($response['body']['local']); - $this->assertLessThan(10, $response['body']['diff']); - } - - public function testWebhooksSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/webhooks', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(10, $response['body']['size']); - } - - public function xtestStorageLocalSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/storage/local', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('OK', $response['body']['status']); - } - - public function testStorageAntiVirusSuccess(): void - { - $response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('online', $response['body']['status']); - $this->assertStringStartsWith('ClamAV ', $response['body']['version']); - } -} diff --git a/tests/old/ConsoleProjectsTest.php b/tests/old/ConsoleProjectsTest.php deleted file mode 100644 index b31c789db..000000000 --- a/tests/old/ConsoleProjectsTest.php +++ /dev/null @@ -1,109 +0,0 @@ -register(); - - $this->assertEquals('http://localhost/success', $response['headers']['location']); - $this->assertEquals("", $response['body']); - - $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - return [ - 'email' => $this->demoEmail, - 'password' => $this->demoPassword, - 'session' => $session - ]; - } - - /** - * @depends testRegisterSuccess - */ - public function testProjectsList($data): void - { - $response = $this->client->call(Client::METHOD_GET, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsArray($response['body']); - } - - /** - * @depends testRegisterSuccess - */ - public function testProjectsCreateSuccess(array $data): array - { - $team = $this->client->call(Client::METHOD_POST, '/teams', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'Demo Project Team', - ]); - - $this->assertEquals(201, $team['headers']['status-code']); - $this->assertEquals('Demo Project Team', $team['body']['name']); - $this->assertNotEmpty($team['body']['$uid']); - - $response = $this->client->call(Client::METHOD_POST, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], [ - 'name' => 'Demo Project', - 'teamId' => $team['body']['$uid'], - 'description' => 'Demo Project Description', - 'logo' => '', - 'url' => 'https://appwrite.io', - 'legalName' => '', - 'legalCountry' => '', - 'legalState' => '', - 'legalCity' => '', - 'legalAddress' => '', - 'legalTaxId' => '', - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']); - - $data['project'] = $response['body']; - - return $data; - } - - /** - * @depends testProjectsCreateSuccess - */ - public function testProjectsUpdateSuccess(array $data): void - { - $response = $this->client->call(Client::METHOD_POST, '/projects', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], array_merge($data['project'], [ - 'name' => 'New Project Name', - 'description' => 'New Demo Project Description', - 'logo' => '', - 'url' => 'https://appwrite.io/new', - ])); - - $this->assertEquals(201, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']); - $this->assertEquals('New Project Name', $response['body']['name']); - $this->assertEquals('New Demo Project Description', $response['body']['description']); - $this->assertEquals('https://appwrite.io/new', $response['body']['url']); - } -} diff --git a/tests/old/ConsoleTest.php b/tests/old/ConsoleTest.php deleted file mode 100644 index 7b5f7999b..000000000 --- a/tests/old/ConsoleTest.php +++ /dev/null @@ -1,100 +0,0 @@ -register(); - - $this->assertEquals('http://localhost/success', $response['headers']['location']); - $this->assertEquals("", $response['body']); - - return [ - 'email' => $this->demoEmail, - 'password' => $this->demoPassword, - ]; - } - - /** - * @depends testRegisterSuccess - */ - public function testLoginSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_POST, '/auth/login', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], [ - 'email' => $data['email'], - 'password' => $data['password'], - 'success' => 'http://localhost/success', - 'failure' => 'http://localhost/failure', - ]); - - $session = $this->client->parseCookie($response['headers']['set-cookie'])['a_session_console']; - - $this->assertEquals('http://localhost/success', $response['headers']['location']); - $this->assertEquals("", $response['body']); - - return [ - 'email' => $data['email'], - 'password' => $data['password'], - 'session' => $session - ]; - } - - /** - * @depends testLoginSuccess - */ - public function testAccountSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/account', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], []); - - $this->assertEquals('Demo User', $response['body']['name']); - $this->assertEquals($data['email'], $response['body']['email']); - $this->assertEquals(false, $response['body']['confirm']); - $this->assertIsArray($response['body']['roles']); - $this->assertIsInt($response['body']['registration']); - $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 - */ - public function testLogoutSuccess(array $data): void - { - $response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'cookie' => 'a_session_console=' . $data['session'], - 'x-appwrite-project' => 'console', - ], []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('success', $response['body']['result']); - } - - public function testLogoutFailure(): void - { - $response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], []); - - $this->assertEquals('401', $response['body']['code']); - } -} diff --git a/tests/old/ProjectAvatarsTest.php b/tests/old/ProjectAvatarsTest.php deleted file mode 100644 index 791a02bdb..000000000 --- a/tests/old/ProjectAvatarsTest.php +++ /dev/null @@ -1,246 +0,0 @@ -initProject([]); - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsCCReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 200, - 'height' => 200, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 300, - 'height' => 300, - 'quality' => 30, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsBrowserReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 200, - 'height' => 200, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 300, - 'height' => 300, - 'quality' => 30, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsFlagReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 200, - 'height' => 200, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'width' => 300, - 'height' => 300, - 'quality' => 30, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsRemoteImageReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'url' => 'https://appwrite.io/images/apple.png', - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'url' => 'https://appwrite.io/images/apple.png', - 'width' => 200, - 'height' => 200, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'url' => 'https://appwrite.io/images/apple.png', - 'width' => 300, - 'height' => 300, - 'quality' => 30, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsFaviconReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'url' => 'https://appwrite.io/', - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testAvatarsQRReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'text' => 'url:https://appwrite.io/', - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'text' => 'url:https://appwrite.io/', - 'size' => 200, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'text' => 'url:https://appwrite.io/', - 'size' => 200, - 'margin' => 10, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'text' => 'url:https://appwrite.io/', - 'size' => 200, - 'margin' => 10, - 'download' => 1, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']); - $this->assertEquals('image/png; charset=UTF-8', $response['headers']['content-type']); - $this->assertNotEmpty($response['body']); - - return $data; - } -} diff --git a/tests/old/ProjectDatabaseTest.php b/tests/old/ProjectDatabaseTest.php deleted file mode 100644 index 61ffd224e..000000000 --- a/tests/old/ProjectDatabaseTest.php +++ /dev/null @@ -1,516 +0,0 @@ -initProject(['collections.read', 'collections.write', 'documents.read', 'documents.write',]); - } - - /** - * @depends testRegisterSuccess - */ - public function testCollectionCreateSuccess(array $data): array - { - $actors = $this->client->call(Client::METHOD_POST, '/database/collections', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'name' => 'Actors', - 'read' => ['*'], - 'write' => ['role:1', 'role:2'], - 'rules' => [ - [ - 'label' => 'First Name', - 'key' => 'firstName', - 'type' => 'text', - 'default' => '', - 'required' => true, - 'array' => false - ], - [ - 'label' => 'Last Name', - 'key' => 'lastName', - 'type' => 'text', - 'default' => '', - 'required' => true, - 'array' => false - ], - ], - ]); - - $this->assertEquals($actors['headers']['status-code'], 201); - $this->assertEquals($actors['body']['$collection'], 0); - $this->assertEquals($actors['body']['name'], 'Actors'); - $this->assertIsArray($actors['body']['$permissions']); - $this->assertIsArray($actors['body']['$permissions']['read']); - $this->assertIsArray($actors['body']['$permissions']['write']); - $this->assertCount(1, $actors['body']['$permissions']['read']); - $this->assertCount(2, $actors['body']['$permissions']['write']); - - $movies = $this->client->call(Client::METHOD_POST, '/database/collections', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'name' => 'Movies', - 'read' => ['*'], - 'write' => ['role:1', 'role:2'], - 'rules' => [ - [ - 'label' => 'Name', - 'key' => 'name', - 'type' => 'text', - 'default' => '', - 'required' => true, - 'array' => false - ], - [ - 'label' => 'Release Year', - 'key' => 'releaseYear', - 'type' => 'numeric', - 'default' => 0, - 'required' => false, - 'array' => false - ], - [ - 'label' => 'Actors', - 'key' => 'actors', - 'type' => 'document', - 'default' => [], - 'required' => false, - 'array' => true, - 'list' => [$actors['body']['$uid']], - ], - ], - ]); - - $this->assertEquals($movies['headers']['status-code'], 201); - $this->assertEquals($movies['body']['$collection'], 0); - $this->assertEquals($movies['body']['name'], 'Movies'); - $this->assertIsArray($movies['body']['$permissions']); - $this->assertIsArray($movies['body']['$permissions']['read']); - $this->assertIsArray($movies['body']['$permissions']['write']); - $this->assertCount(1, $movies['body']['$permissions']['read']); - $this->assertCount(2, $movies['body']['$permissions']['write']); - - return array_merge($data, ['moviesId' => $movies['body']['$uid'], 'actorsId' => $actors['body']['$uid']]); - } - - /** - * @depends testCollectionCreateSuccess - */ - public function testDocumentCreateSuccess(array $data): array - { - $document1 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Captain America', - 'releaseYear' => 1944, - 'actors' => [ - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Chris', - 'lastName' => 'Evans', - ], - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Samuel', - 'lastName' => 'Jackson', - ], - ] - ] - ]); - - $document2 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Spider-Man: Far From Home', - 'releaseYear' => 2019, - 'actors' => [ - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Tom', - 'lastName' => 'Holland', - ], - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Zendaya', - 'lastName' => 'Maree Stoermer', - ], - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Samuel', - 'lastName' => 'Jackson', - ], - ] - ] - ]); - - $document3 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Spider-Man: Homecoming', - 'releaseYear' => 2017, - 'actors' => [ - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Tom', - 'lastName' => 'Holland', - ], - [ - '$collection' => $data['actorsId'], - '$permissions' => ['read' => [], 'write' => []], - 'firstName' => 'Zendaya', - 'lastName' => 'Maree Stoermer', - ], - ], - ] - ]); - - $document4 = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'releaseYear' => 2020, // Missing title, expect an 400 error - ] - ]); - - $this->assertEquals($document1['headers']['status-code'], 201); - $this->assertEquals($document1['body']['$collection'], $data['moviesId']); - $this->assertEquals($document1['body']['name'], 'Captain America'); - $this->assertEquals($document1['body']['releaseYear'], 1944); - $this->assertIsArray($document1['body']['$permissions']); - $this->assertIsArray($document1['body']['$permissions']['read']); - $this->assertIsArray($document1['body']['$permissions']['write']); - $this->assertCount(0, $document1['body']['$permissions']['read']); - $this->assertCount(0, $document1['body']['$permissions']['write']); - $this->assertCount(2, $document1['body']['actors']); - - $this->assertEquals($document2['headers']['status-code'], 201); - $this->assertEquals($document2['body']['$collection'], $data['moviesId']); - $this->assertEquals($document2['body']['name'], 'Spider-Man: Far From Home'); - $this->assertEquals($document2['body']['releaseYear'], 2019); - $this->assertIsArray($document2['body']['$permissions']); - $this->assertIsArray($document2['body']['$permissions']['read']); - $this->assertIsArray($document2['body']['$permissions']['write']); - $this->assertCount(0, $document2['body']['$permissions']['read']); - $this->assertCount(0, $document2['body']['$permissions']['write']); - $this->assertCount(3, $document2['body']['actors']); - $this->assertEquals($document2['body']['actors'][0]['firstName'], 'Tom'); - $this->assertEquals($document2['body']['actors'][0]['lastName'], 'Holland'); - $this->assertEquals($document2['body']['actors'][1]['firstName'], 'Zendaya'); - $this->assertEquals($document2['body']['actors'][1]['lastName'], 'Maree Stoermer'); - $this->assertEquals($document2['body']['actors'][2]['firstName'], 'Samuel'); - $this->assertEquals($document2['body']['actors'][2]['lastName'], 'Jackson'); - - $this->assertEquals($document3['headers']['status-code'], 201); - $this->assertEquals($document3['body']['$collection'], $data['moviesId']); - $this->assertEquals($document3['body']['name'], 'Spider-Man: Homecoming'); - $this->assertEquals($document3['body']['releaseYear'], 2017); - $this->assertIsArray($document3['body']['$permissions']); - $this->assertIsArray($document3['body']['$permissions']['read']); - $this->assertIsArray($document3['body']['$permissions']['write']); - $this->assertCount(0, $document3['body']['$permissions']['read']); - $this->assertCount(0, $document3['body']['$permissions']['write']); - $this->assertCount(2, $document3['body']['actors']); - $this->assertEquals($document3['body']['actors'][0]['firstName'], 'Tom'); - $this->assertEquals($document3['body']['actors'][0]['lastName'], 'Holland'); - $this->assertEquals($document3['body']['actors'][1]['firstName'], 'Zendaya'); - $this->assertEquals($document3['body']['actors'][1]['lastName'], 'Maree Stoermer'); - - $this->assertEquals($document4['headers']['status-code'], 400); - - return $data; - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsListSuccessOrderAndCasting(array $data): void - { - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', - ]); - - $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); - $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); - $this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']); - $this->assertCount(3, $documents['body']['documents']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'order-field' => 'releaseYear', - 'order-type' => 'DESC', - 'order-cast' => 'int', - ]); - - $this->assertEquals(1944, $documents['body']['documents'][2]['releaseYear']); - $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); - $this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']); - $this->assertCount(3, $documents['body']['documents']); - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsListSuccessLimitAndOffset(array $data): void - { - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'limit' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', - ]); - - $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); - $this->assertCount(1, $documents['body']['documents']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'limit' => 2, - 'offset' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', - ]); - - $this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']); - $this->assertEquals(2019, $documents['body']['documents'][1]['releaseYear']); - $this->assertCount(2, $documents['body']['documents']); - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsListSuccessFirstAndLast(array $data): void - { - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'limit' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', - 'first' => true, - ]); - - $this->assertEquals(1944, $documents['body']['releaseYear']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'limit' => 2, - 'offset' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', - 'last' => true, - ]); - - $this->assertEquals(2019, $documents['body']['releaseYear']); - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsListSuccessSearch(array $data): void - { - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'search' => 'Captain America', - ]); - - $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); - $this->assertCount(1, $documents['body']['documents']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'search' => 'Homecoming', - ]); - - $this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']); - $this->assertCount(1, $documents['body']['documents']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'search' => 'spider', - ]); - - $this->assertEquals(2019, $documents['body']['documents'][0]['releaseYear']); - $this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']); - $this->assertCount(2, $documents['body']['documents']); - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsListSuccessFilters(array $data): void - { - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'filters' => [ - 'actors.firstName=Tom' - ], - ]); - - $this->assertCount(2, $documents['body']['documents']); - $this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']); - $this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'filters' => [ - 'releaseYear=1944' - ], - ]); - - $this->assertCount(1, $documents['body']['documents']); - $this->assertEquals('Captain America', $documents['body']['documents'][0]['name']); - - $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'filters' => [ - 'releaseYear!=1944' - ], - ]); - - $this->assertCount(2, $documents['body']['documents']); - $this->assertEquals('Spider-Man: Far From Home', $documents['body']['documents'][0]['name']); - $this->assertEquals('Spider-Man: Homecoming', $documents['body']['documents'][1]['name']); - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsUpdateSuccess(array $data): void - { - $document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Thor: Ragnaroc', - 'releaseYear' => 2017, - ] - ]); - - $id = $document['body']['$uid']; - $collection = $document['body']['$collection']; - - $this->assertEquals($document['headers']['status-code'], 201); - $this->assertEquals($document['body']['name'], 'Thor: Ragnaroc'); - $this->assertEquals($document['body']['releaseYear'], 2017); - - $document = $this->client->call(Client::METHOD_PATCH, '/database/collections/' . $collection . '/documents/' . $id, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Thor: Ragnarok' - ] - ]); - - $this->assertEquals($document['headers']['status-code'], 200); - $this->assertEquals($document['body']['name'], 'Thor: Ragnarok'); - $this->assertEquals($document['body']['releaseYear'], 2017); - - $document = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collection . '/documents/' . $id, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $id = $document['body']['$uid']; - $collection = $document['body']['$collection']; - - $this->assertEquals($document['headers']['status-code'], 200); - $this->assertEquals($document['body']['name'], 'Thor: Ragnarok'); - $this->assertEquals($document['body']['releaseYear'], 2017); - - } - - /** - * @depends testDocumentCreateSuccess - */ - public function testDocumentsDeleteSuccess(array $data): void - { - $document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], [ - 'data' => [ - 'name' => 'Thor: Ragnarok', - 'releaseYear' => 2017, - ] - ]); - - $id = $document['body']['$uid']; - $collection = $document['body']['$collection']; - - $this->assertEquals($document['headers']['status-code'], 201); - - $document = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collection . '/documents/' . $id, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($document['headers']['status-code'], 200); - - $document = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collection . '/documents/' . $id, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($document['headers']['status-code'], 204); - - $document = $this->client->call(Client::METHOD_GET, '/database/collections/' . $collection . '/documents/' . $id, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($document['headers']['status-code'], 404); - - } -} diff --git a/tests/old/ProjectLocaleTest.php b/tests/old/ProjectLocaleTest.php deleted file mode 100644 index d9db9f827..000000000 --- a/tests/old/ProjectLocaleTest.php +++ /dev/null @@ -1,193 +0,0 @@ -initProject([]); - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/locale', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertArrayHasKey('ip', $response['body']); - $this->assertArrayHasKey('countryCode', $response['body']); - $this->assertArrayHasKey('country', $response['body']); - $this->assertArrayHasKey('continent', $response['body']); - $this->assertArrayHasKey('continentCode', $response['body']); - $this->assertArrayHasKey('eu', $response['body']); - $this->assertArrayHasKey('currency', $response['body']); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleCountriesReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(194, $response['body']); - $this->assertEquals($response['body']['US'], 'United States'); - - // Test locale code change to ES - - $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - 'x-appwrite-locale' => 'es', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(194, $response['body']); - $this->assertEquals($response['body']['US'], 'Estados Unidos'); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleCountriesEUReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(27, $response['body']); - $this->assertEquals($response['body']['DE'], 'Germany'); - - // Test locale code change to ES - - $response = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - 'x-appwrite-locale' => 'es', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(27, $response['body']); - $this->assertEquals($response['body']['DE'], 'Alemania'); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleContinentsReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(7, $response['body']); - $this->assertEquals($response['body']['NA'], 'North America'); - - // Test locale code change to ES - $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - 'x-appwrite-locale' => 'es', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(7, $response['body']); - $this->assertEquals($response['body']['NA'], 'América del Norte'); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleCurrenciesReadSuccess(array $data): array - { - $response = $this->client->call(Client::METHOD_GET, '/locale/currencies', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertIsArray($response['body']); - $this->assertCount(117, $response['body']); - $this->assertEquals($response['body'][0]['symbol'], '$'); - $this->assertEquals($response['body'][0]['name'], 'US Dollar'); - - return $data; - } - - /** - * @depends testRegisterSuccess - */ - public function testLocaleLangsSuccess(array $data): array - { - $languages = require('app/config/locales.php'); - $defaultCountries = require('app/config/locales/en.countries.php'); - $defaultContinents = require('app/config/locales/en.continents.php'); - - foreach ($languages as $key => $lang) { - $response = $this->client->call(Client::METHOD_GET, '/locale/countries', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - 'x-appwrite-locale' => $lang, - ]); - - foreach ($response['body'] as $i => $code) { - $this->assertArrayHasKey($i, $defaultCountries, $i . ' country should be removed from ' . $lang); - } - - foreach (array_keys($defaultCountries) as $i => $code) { - $this->assertArrayHasKey($code, $response['body'], $code . ' country is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); - } - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertCount(194, $response['body']); - - $response = $this->client->call(Client::METHOD_GET, '/locale/continents', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - 'x-appwrite-locale' => $lang, - ]); - - foreach ($response['body'] as $i => $code) { - $this->assertArrayHasKey($i, $defaultContinents, $i . ' continent should be removed from ' . $lang); - } - - foreach (array_keys($defaultContinents) as $i => $code) { - $this->assertArrayHasKey($code, $response['body'], $code . ' continent is missing from ' . $lang . ' (total: ' . count($response['body']) . ')'); - } - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertCount(7, $response['body']); - } - - return $data; - } -} diff --git a/tests/old/ProjectStorageTest.php b/tests/old/ProjectStorageTest.php deleted file mode 100644 index 43b6154b7..000000000 --- a/tests/old/ProjectStorageTest.php +++ /dev/null @@ -1,170 +0,0 @@ -initProject(['files.read', 'files.write']); - } - - /** - * @depends testRegisterSuccess - */ - public function testFileCreateSuccess(array $data): array - { - $file = $this->client->call(Client::METHOD_POST, '/storage/files', [ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $data['projectUid'], - ], [ - 'files' => new CURLFile(realpath(__DIR__ . '/../resources/logo.png'), 'image/png', 'logo.png'), - 'read' => ['*'], - 'write' => ['*'], - 'folderId' => 'xyz', - ]); - - $this->assertEquals($file['headers']['status-code'], 201); - $this->assertNotEmpty($file['body'][0]['$uid']); - $this->assertEquals('files', $file['body'][0]['$collection']); - $this->assertIsInt($file['body'][0]['dateCreated']); - $this->assertEquals('logo.png', $file['body'][0]['name']); - $this->assertEquals('image/png', $file['body'][0]['mimeType']); - $this->assertEquals(47218, $file['body'][0]['sizeOriginal']); - $this->assertEquals(54944, $file['body'][0]['sizeActual']); - $this->assertEquals('gzip', $file['body'][0]['algorithm']); - $this->assertEquals('1', $file['body'][0]['fileOpenSSLVersion']); - $this->assertEquals('aes-128-gcm', $file['body'][0]['fileOpenSSLCipher']); - $this->assertNotEmpty($file['body'][0]['fileOpenSSLTag']); - $this->assertNotEmpty($file['body'][0]['fileOpenSSLIV']); - - return array_merge($data, ['fileId' => $file['body'][0]['$uid']]); - } - - /** - * @depends testFileCreateSuccess - */ - public function testFileReadSuccess(array $data): array - { - $file1 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals($file1['headers']['status-code'], 200); - $this->assertNotEmpty($file1['body']['$uid']); - $this->assertIsInt($file1['body']['dateCreated']); - $this->assertEquals('logo.png', $file1['body']['name']); - $this->assertEquals('image/png', $file1['body']['mimeType']); - $this->assertEquals(47218, $file1['body']['sizeOriginal']); - //$this->assertEquals(54944, $file1['body']['sizeActual']); - //$this->assertEquals('gzip', $file1['body']['algorithm']); - //$this->assertEquals('1', $file1['body']['fileOpenSSLVersion']); - //$this->assertEquals('aes-128-gcm', $file1['body']['fileOpenSSLCipher']); - //$this->assertNotEmpty($file1['body']['fileOpenSSLTag']); - //$this->assertNotEmpty($file1['body']['fileOpenSSLIV']); - $this->assertIsArray($file1['body']['$permissions']['read']); - $this->assertIsArray($file1['body']['$permissions']['write']); - $this->assertCount(1, $file1['body']['$permissions']['read']); - $this->assertCount(1, $file1['body']['$permissions']['write']); - - $file2 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals(200, $file2['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $file2['headers']['content-type']); - $this->assertNotEmpty($file2['body']); - - $file3 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/download', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals(200, $file3['headers']['status-code']); - $this->assertEquals('attachment; filename="logo.png"', $file3['headers']['content-disposition']); - $this->assertEquals('image/png; charset=UTF-8', $file3['headers']['content-type']); - $this->assertNotEmpty($file3['body']); - - $file4 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/view', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals(200, $file4['headers']['status-code']); - $this->assertEquals('image/png; charset=UTF-8', $file4['headers']['content-type']); - $this->assertNotEmpty($file4['body']); - - return $data; - } - - /** - * @depends testFileReadSuccess - */ - public function testFileListSuccess(array $data): array - { - $files = $this->client->call(Client::METHOD_GET, '/storage/files', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals(200, $files['headers']['status-code']); - $this->assertEquals(1, $files['body']['sum']); - $this->assertCount(1, $files['body']['files']); - - return $data; - } - - /** - * @depends testFileListSuccess - */ - public function testFileUpdateSuccess(array $data): array - { - $file = $this->client->call(Client::METHOD_PUT, '/storage/files/' . $data['fileId'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders()), [ - 'read' => ['*'], - 'write' => ['*'], - ]); - - $this->assertEquals(200, $file['headers']['status-code']); - $this->assertNotEmpty($file['body']['$uid']); - $this->assertIsInt($file['body']['dateCreated']); - $this->assertEquals('logo.png', $file['body']['name']); - $this->assertEquals('image/png', $file['body']['mimeType']); - $this->assertEquals(47218, $file['body']['sizeOriginal']); - //$this->assertEquals(54944, $file['body']['sizeActual']); - //$this->assertEquals('gzip', $file['body']['algorithm']); - //$this->assertEquals('1', $file['body']['fileOpenSSLVersion']); - //$this->assertEquals('aes-128-gcm', $file['body']['fileOpenSSLCipher']); - //$this->assertNotEmpty($file['body']['fileOpenSSLTag']); - //$this->assertNotEmpty($file['body']['fileOpenSSLIV']); - $this->assertIsArray($file['body']['$permissions']['read']); - $this->assertIsArray($file['body']['$permissions']['write']); - $this->assertCount(0, $file['body']['$permissions']['read']); - $this->assertCount(0, $file['body']['$permissions']['write']); - - return $data; - } - - /** - * @depends testFileUpdateSuccess - */ - public function testFileDeleteSuccess(array $data): array - { - $file = $this->client->call(Client::METHOD_DELETE, '/storage/files/' . $data['fileId'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$uid'], - ], $this->getHeaders())); - - $this->assertEquals(204, $file['headers']['status-code']); - $this->assertEmpty($file['body']); - - return $data; - } -} diff --git a/tests/old/ProjectUsersTest.php b/tests/old/ProjectUsersTest.php deleted file mode 100644 index 3b53754e7..000000000 --- a/tests/old/ProjectUsersTest.php +++ /dev/null @@ -1,159 +0,0 @@ -initProject(['users.read', 'users.write']); - } - - /** - * @depends testRegisterSuccess - */ - public function testUserCreateSuccess(array $data): array - { - $user = $this->client->call(Client::METHOD_POST, '/users', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ], [ - 'email' => 'users.service@example.com', - 'password' => 'password', - 'name' => 'Project User', - ]); - - $this->assertEquals($user['headers']['status-code'], 201); - $this->assertEquals($user['body']['name'], 'Project User'); - $this->assertEquals($user['body']['email'], 'users.service@example.com'); - $this->assertEquals($user['body']['status'], 0); - $this->assertGreaterThan(0, $user['body']['registration']); - $this->assertIsArray($user['body']['roles']); - - return array_merge($data, ['userId' => $user['body']['$uid']]); - } - - /** - * @depends testUserCreateSuccess - */ - public function testUserReadSuccess(array $data): array - { - $user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); - - $this->assertEquals($user['headers']['status-code'], 200); - $this->assertEquals($user['body']['name'], 'Project User'); - $this->assertEquals($user['body']['email'], 'users.service@example.com'); - $this->assertEquals($user['body']['status'], 0); - $this->assertGreaterThan(0, $user['body']['registration']); - $this->assertIsArray($user['body']['roles']); - - $sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); - - $this->assertEquals($sessions['headers']['status-code'], 200); - $this->assertIsArray($sessions['body']); - - $logs = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/logs', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); - - $this->assertEquals($logs['headers']['status-code'], 200); - $this->assertIsArray($logs['body']); - - $users = $this->client->call(Client::METHOD_GET, '/users', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); - - $this->assertEquals($users['headers']['status-code'], 200); - $this->assertIsArray($users['body']); - $this->assertIsArray($users['body']['users']); - $this->assertIsInt($users['body']['sum']); - $this->assertGreaterThan(0, $users['body']['sum']); - - $users = $this->client->call(Client::METHOD_GET, '/users', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ], [ - 'search' => 'demo' - ]); - - $this->assertEquals($users['headers']['status-code'], 200); - $this->assertIsArray($users['body']); - $this->assertIsArray($users['body']['users']); - $this->assertIsInt($users['body']['sum']); - $this->assertEquals(1, $users['body']['sum']); - $this->assertGreaterThan(0, $users['body']['sum']); - $this->assertCount(1, $users['body']['users']); - - return $data; - } - - /** - * @depends testUserReadSuccess - */ - public function testUserUpdateStatusSuccess(array $data): array - { - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/status', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ], [ - 'status' => 2, - ]); - - $this->assertEquals($user['headers']['status-code'], 200); - $this->assertEquals($user['body']['status'], 2); - - $user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ]); - - $this->assertEquals($user['headers']['status-code'], 200); - $this->assertEquals($user['body']['status'], 2); - - return $data; - } - - /** - * @depends testUserReadSuccess - */ - public function testUserUpdatePrefsSuccess(array $data): array - { - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectUid'], - 'x-appwrite-key' => $data['projectAPIKeySecret'], - ], [ - 'prefs' => [ - 'key1' => 'value1', - 'key2' => 'value2', - ], - ]); - - $this->assertEquals($user['headers']['status-code'], 200); - $this->assertEquals($user['body']['key1'], 'value1'); - $this->assertEquals($user['body']['key2'], 'value2'); - - return $data; - } - - // TODO add test for session delete - // TODO add test for all sessions delete -}