74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Appwrite\Tests;
|
||
|
|
||
|
use Appwrite\Database\Document;
|
||
|
use Appwrite\Event\Event;
|
||
|
use Appwrite\Event\Realtime;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use Utopia\App;
|
||
|
|
||
|
class RealtimeTest extends TestCase
|
||
|
{
|
||
|
public function testConvertChannelsGuest()
|
||
|
{
|
||
|
$user = new Document([
|
||
|
'$id' => ''
|
||
|
]);
|
||
|
$channels = [
|
||
|
0 => 'files',
|
||
|
1 => 'documents',
|
||
|
2 => 'documents.789',
|
||
|
3 => 'account',
|
||
|
4 => 'account.456'
|
||
|
];
|
||
|
|
||
|
$channels = Realtime::convertChannels($channels, $user);
|
||
|
$this->assertCount(3, $channels);
|
||
|
$this->assertArrayHasKey('files', $channels);
|
||
|
$this->assertArrayHasKey('documents', $channels);
|
||
|
$this->assertArrayHasKey('documents.789', $channels);
|
||
|
$this->assertArrayNotHasKey('account', $channels);
|
||
|
$this->assertArrayNotHasKey('account.456', $channels);
|
||
|
}
|
||
|
|
||
|
public function testConvertChannelsUser()
|
||
|
{
|
||
|
$user = new Document([
|
||
|
'$id' => '123',
|
||
|
'memberships' => [
|
||
|
[
|
||
|
'teamId' => 'abc',
|
||
|
'roles' => [
|
||
|
'administrator',
|
||
|
'moderator'
|
||
|
]
|
||
|
],
|
||
|
[
|
||
|
'teamId' => 'def',
|
||
|
'roles' => [
|
||
|
'guest'
|
||
|
]
|
||
|
]
|
||
|
]
|
||
|
]);
|
||
|
$channels = [
|
||
|
0 => 'files',
|
||
|
1 => 'documents',
|
||
|
2 => 'documents.789',
|
||
|
3 => 'account',
|
||
|
4 => 'account.456'
|
||
|
];
|
||
|
|
||
|
$channels = Realtime::convertChannels($channels, $user);
|
||
|
|
||
|
$this->assertCount(4, $channels);
|
||
|
$this->assertArrayHasKey('files', $channels);
|
||
|
$this->assertArrayHasKey('documents', $channels);
|
||
|
$this->assertArrayHasKey('documents.789', $channels);
|
||
|
$this->assertArrayHasKey('account.123', $channels);
|
||
|
$this->assertArrayNotHasKey('account', $channels);
|
||
|
$this->assertArrayNotHasKey('account.456', $channels);
|
||
|
}
|
||
|
}
|