1
0
Fork 0
mirror of synced 2024-07-03 05:31:38 +12:00
appwrite/tests/unit/Event/RealtimeTest.php
Torsten Dittmann e232b2a723 fix tests
2021-06-29 15:11:14 +02:00

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);
}
}