client->call(Client::METHOD_PUT, '/database/collections/'.$data['actorsId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Actors1', 'read' => ['*'], 'write' => ['*'], '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'], 200); $this->assertNotEmpty($actors['body']['$id']); $webhook = $this->getLastRequest(); $this->assertEquals($webhook['method'], 'POST'); $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.collections.update'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), true); $this->assertNotEmpty($webhook['data']['$id']); $this->assertEquals($webhook['data']['name'], 'Actors1'); $this->assertIsArray($webhook['data']['$permissions']); $this->assertIsArray($webhook['data']['$permissions']['read']); $this->assertIsArray($webhook['data']['$permissions']['write']); $this->assertCount(1, $webhook['data']['$permissions']['read']); $this->assertCount(1, $webhook['data']['$permissions']['write']); $this->assertCount(2, $webhook['data']['rules']); return array_merge(['actorsId' => $actors['body']['$id']]); } public function testDeleteCollection(): array { /** * Test for SUCCESS */ $actors = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Demo', 'read' => ['*'], 'write' => ['*'], '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->assertNotEmpty($actors['body']['$id']); $actors = $this->client->call(Client::METHOD_DELETE, '/database/collections/'.$actors['body']['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ]), []); $this->assertEquals($actors['headers']['status-code'], 204); $webhook = $this->getLastRequest(); $this->assertEquals($webhook['method'], 'POST'); $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'database.collections.delete'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), true); $this->assertNotEmpty($webhook['data']['$id']); $this->assertEquals($webhook['data']['name'], 'Demo'); $this->assertIsArray($webhook['data']['$permissions']); $this->assertIsArray($webhook['data']['$permissions']['read']); $this->assertIsArray($webhook['data']['$permissions']['write']); $this->assertCount(1, $webhook['data']['$permissions']['read']); $this->assertCount(1, $webhook['data']['$permissions']['write']); $this->assertCount(2, $webhook['data']['rules']); return []; } public function testCreateUser():array { $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'User Name'; /** * Test for SUCCESS */ $user = $this->client->call(Client::METHOD_POST, '/users', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'email' => $email, 'password' => $password, 'name' => $name, ]); $this->assertEquals($user['headers']['status-code'], 201); $this->assertNotEmpty($user['body']['$id']); $id = $user['body']['$id']; $webhook = $this->getLastRequest(); $this->assertEquals($webhook['method'], 'POST'); $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'users.create'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide())); $this->assertNotEmpty($webhook['data']['$id']); $this->assertEquals($webhook['data']['name'], $name); $this->assertIsInt($webhook['data']['registration']); $this->assertEquals($webhook['data']['status'], 0); $this->assertEquals($webhook['data']['email'], $email); $this->assertEquals($webhook['data']['emailVerification'], false); $this->assertEquals($webhook['data']['prefs'], []); /** * Test for FAILURE */ return ['userId' => $user['body']['$id'], 'name' => $user['body']['name'], 'email' => $user['body']['email']]; } /** * @depends testCreateUser */ public function testUpdateUserStatus(array $data):array { /** * Test for SUCCESS */ $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/status', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'status' => 2, ]); $this->assertEquals($user['headers']['status-code'], 200); $this->assertNotEmpty($user['body']['$id']); $webhook = $this->getLastRequest(); $this->assertEquals($webhook['method'], 'POST'); $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'users.update.status'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide())); $this->assertNotEmpty($webhook['data']['$id']); $this->assertEquals($webhook['data']['name'], $data['name']); $this->assertIsInt($webhook['data']['registration']); $this->assertEquals($webhook['data']['status'], 2); $this->assertEquals($webhook['data']['email'], $data['email']); $this->assertEquals($webhook['data']['emailVerification'], false); $this->assertEquals($webhook['data']['prefs'], []); return $data; } /** * @depends testUpdateUserStatus */ public function testDeleteUser(array $data):array { /** * Test for SUCCESS */ $user = $this->client->call(Client::METHOD_DELETE, '/users/' . $data['userId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals($user['headers']['status-code'], 204); $webhook = $this->getLastRequest(); $this->assertEquals($webhook['method'], 'POST'); $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'users.delete'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide())); $this->assertNotEmpty($webhook['data']['$id']); $this->assertEquals($webhook['data']['name'], $data['name']); $this->assertIsInt($webhook['data']['registration']); $this->assertEquals($webhook['data']['status'], 2); $this->assertEquals($webhook['data']['email'], $data['email']); $this->assertEquals($webhook['data']['emailVerification'], false); $this->assertEquals($webhook['data']['prefs'], []); return $data; } }