mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch 'dev' of https://github.com/appwrite/appwrite into feat-265-realtime
This commit is contained in:
@@ -501,6 +501,133 @@ trait DatabaseBase
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 404);
|
||||
|
||||
return [];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDeleteDocument
|
||||
*/
|
||||
public function testDefaultPermissions(array $data):array
|
||||
{
|
||||
$document = $this->client->call(Client::METHOD_POST, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Captain America',
|
||||
'releaseYear' => 1944,
|
||||
'actors' => [],
|
||||
],
|
||||
]);
|
||||
|
||||
$id = $document['body']['$id'];
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 201);
|
||||
$this->assertEquals($document['body']['$collection'], $data['moviesId']);
|
||||
$this->assertEquals($document['body']['name'], 'Captain America');
|
||||
$this->assertEquals($document['body']['releaseYear'], 1944);
|
||||
$this->assertIsArray($document['body']['$permissions']);
|
||||
$this->assertIsArray($document['body']['$permissions']['read']);
|
||||
$this->assertIsArray($document['body']['$permissions']['write']);
|
||||
|
||||
if($this->getSide() == 'client') {
|
||||
$this->assertCount(1, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(1, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals(['user:'.$this->getUser()['$id']], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals(['user:'.$this->getUser()['$id']], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
if($this->getSide() == 'server') {
|
||||
$this->assertCount(0, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
// Updated and Inherit Permissions
|
||||
|
||||
$document = $this->client->call(Client::METHOD_PATCH, '/database/collections/' . $data['moviesId'] . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Captain America 2',
|
||||
'releaseYear' => 1945,
|
||||
'actors' => [],
|
||||
],
|
||||
'read' => ['*'],
|
||||
]);
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['name'], 'Captain America 2');
|
||||
$this->assertEquals($document['body']['releaseYear'], 1945);
|
||||
|
||||
if($this->getSide() == 'client') {
|
||||
$this->assertCount(1, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(1, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals(['*'], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals(['user:'.$this->getUser()['$id']], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
if($this->getSide() == 'server') {
|
||||
$this->assertCount(1, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals(['*'], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
$document = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['name'], 'Captain America 2');
|
||||
$this->assertEquals($document['body']['releaseYear'], 1945);
|
||||
|
||||
if($this->getSide() == 'client') {
|
||||
$this->assertCount(1, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(1, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals(['*'], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals(['user:'.$this->getUser()['$id']], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
if($this->getSide() == 'server') {
|
||||
$this->assertCount(1, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals(['*'], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
// Reset Permissions
|
||||
|
||||
$document = $this->client->call(Client::METHOD_PATCH, '/database/collections/' . $data['moviesId'] . '/documents/' . $id, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), [
|
||||
'data' => [
|
||||
'name' => 'Captain America 3',
|
||||
'releaseYear' => 1946,
|
||||
'actors' => [],
|
||||
],
|
||||
'read' => [],
|
||||
'write' => [],
|
||||
]);
|
||||
|
||||
if($this->getSide() == 'client') {
|
||||
$this->assertEquals($document['headers']['status-code'], 401);
|
||||
}
|
||||
|
||||
if($this->getSide() == 'server') {
|
||||
$this->assertEquals($document['headers']['status-code'], 200);
|
||||
$this->assertEquals($document['body']['name'], 'Captain America 3');
|
||||
$this->assertEquals($document['body']['releaseYear'], 1946);
|
||||
$this->assertCount(0, $document['body']['$permissions']['read']);
|
||||
$this->assertCount(0, $document['body']['$permissions']['write']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['read']);
|
||||
$this->assertEquals([], $document['body']['$permissions']['write']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -628,7 +628,7 @@ class FunctionsCustomServerTest extends Scope
|
||||
], $this->getHeaders()), [
|
||||
'tag' => $tagId,
|
||||
]);
|
||||
|
||||
|
||||
$this->assertEquals(200, $tag['headers']['status-code']);
|
||||
|
||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/executions', array_merge([
|
||||
|
||||
@@ -234,8 +234,9 @@ class HealthCustomServerTest extends Scope
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertEquals('online', $response['body']['status']);
|
||||
$this->assertStringStartsWith('ClamAV ', $response['body']['version']);
|
||||
$this->assertNotEmpty($response['body']['status']);
|
||||
$this->assertIsString($response['body']['status']);
|
||||
$this->assertIsString($response['body']['version']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Appwrite\Tests;
|
||||
|
||||
use PHPUnit\Runner\AfterTestHook;
|
||||
|
||||
class TestHook implements AfterTestHook
|
||||
{
|
||||
public function executeAfterTest(string $test, float $time): void
|
||||
{
|
||||
printf("%s ended in %s seconds\n",
|
||||
$test,
|
||||
$time
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user