diff --git a/.env.testing.example b/.env.testing.example
index 165994d1..1434c598 100644
--- a/.env.testing.example
+++ b/.env.testing.example
@@ -2,7 +2,7 @@ HOST=127.0.0.1
PORT=9987
DEV_LIVE_SERVER_AVAILABLE=false
DEV_LIVE_SERVER_HOST=127.0.0.1
-DEV_LIVE_SERVER_QUERY_PORT=10011
+DEV_LIVE_SERVER_QUERY_PORT=10022
DEV_LIVE_SERVER_QUERY_USER=serveradmin
DEV_LIVE_SERVER_QUERY_USER_PASSWORD=PASSWORD
DEV_LIVE_SERVER_UNIT_TEST_CHANNEL=UnitTest
diff --git a/README.md b/README.md
index 6102a896..9f695442 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,11 @@
# TeamSpeak X PHP Framework
-
+[](https://github.com/Prestige-Solution/ts-x-php-framework/actions/workflows/phpcsfixer.yml)
+[](https://github.com/Prestige-Solution/ts-x-php-framework/actions/workflows/phpunit.yml)
+
+> [!CAUTION]
> **_IMPORTANT CHANGE_**
-> With Version 3.0.0 we refactored to integrate phpseclib3. This changes affects how TCP connections are established.
-> The "raw" mode was removed, and the support for only ssh mode was established to handel Teamspeak 3 and Teamspeak 6 Server connections.
+> With Version 3.x we refactored to integrate phpseclib3. This changes affects how TCP connections are established.
+> The "raw" mode was removed, and the support for only ssh mode was established to handel Teamspeak 3 and Teamspeak 6 Server API connections.
The X stands for a non-specific Teamspeak Server Version. So we would handle all current and future Versions from a Teamspeak Server.
@@ -14,7 +17,7 @@ The ideal is that this version can be integrated into your own project and the m
---
# Installation
-With the Refactoring at Version 3.0.0, the Framework has a lot of changes. But most functionalities and namespaces are the same.
+With the Refactoring at Version 3.x, the Framework has a lot of changes. But most functionalities and namespaces are the same.
**PHP Required Extensions**
``apt install php8.3 php8.3-{common,mbstring,ssh2} -y``
@@ -42,9 +45,9 @@ Before you start UnitTests, make sure that you have set the environment variable
The best way to test all functionalities is to use the serveradmin query user.
The serveradmin is != Server Admin there you can find in your Teamspeak Client UI.
-| serveradmin (Query) | Server Admin (GUI) |
-|----------------------------|---------------------------|
-| Max. permission value: 100 | Max. permission value: 75 |
+| serveradmin (Query) | Server Admin (GUI) |
+|-------------------------------------|------------------------------------|
+| Max. permission value: 100 (=grant) | Max. permission value: 75 (=grant) |
You can find more information in the Documentation [testing-live-server](doc/testing-live-server.md)
diff --git a/composer.json b/composer.json
index 4bdec724..25bc4d88 100644
--- a/composer.json
+++ b/composer.json
@@ -46,6 +46,9 @@
"Composer\\Config::disableProcessTimeout",
"\"vendor/bin/phpunit\" --no-coverage"
],
- "coverage": "\"vendor/bin/phpunit\""
+ "coverage": [
+ "Composer\\Config::disableProcessTimeout",
+ "\"vendor/bin/phpunit\" --configuration phpunit.xml.dist"
+ ]
}
}
diff --git a/doc/coverage/coverage-badge.svg b/doc/coverage/coverage-badge.svg
new file mode 100644
index 00000000..66360ebe
--- /dev/null
+++ b/doc/coverage/coverage-badge.svg
@@ -0,0 +1,19 @@
+
\ No newline at end of file
diff --git a/generate-coverage-badge.php b/generate-coverage-badge.php
new file mode 100644
index 00000000..fc54f029
--- /dev/null
+++ b/generate-coverage-badge.php
@@ -0,0 +1,65 @@
+project->metrics)) {
+ die("No project-level metrics found in Clover XML\n");
+}
+
+$metrics = $clover->project->metrics;
+$elements = (int) $metrics['elements'];
+$covered = (int) $metrics['coveredelements'];
+
+$preciseCoverage = $elements > 0 ? ($covered / $elements * 100) : 0;
+$coverage = round($preciseCoverage);
+
+if ($coverage >= 90) {
+ $color = '#4c1';
+} elseif ($coverage >= 75) {
+ $color = '#dfb317';
+} elseif ($coverage >= 50) {
+ $color = '#fe7d37';
+} else {
+ $color = '#e05d44';
+}
+
+$label = 'coverage';
+$value = $coverage.'%';
+$labelWidth = 60;
+$valueWidth = 40;
+$height = 20;
+
+$totalWidth = $labelWidth + $valueWidth;
+$labelX = $labelWidth / 2;
+$valueX = $labelWidth + ($valueWidth / 2);
+
+$svg = <<
+SVG;
+
+file_put_contents($outputSvg, $svg);
+echo "Badge created: $outputSvg ($coverage%)\n";
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 5f7c640b..7b7a8ef8 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -19,7 +19,7 @@
>
- ./
+ ./src
./images
diff --git a/src/Node/Channel.php b/src/Node/Channel.php
index 29034342..2a421130 100644
--- a/src/Node/Channel.php
+++ b/src/Node/Channel.php
@@ -74,23 +74,25 @@ public function subChannelList(array $filter = []): array
*/
public function subChannelGetById(int $cid): self
{
- if (! array_key_exists($cid, $this->subChannelList())) {
+ $subChannels = $this->subChannelList();
+
+ if (! array_key_exists($cid, $subChannels)) {
throw new ServerQueryException('invalid channelID', 0x300);
}
- return $this->channelList[$cid];
+ return $subChannels[$cid];
}
/**
* Returns the PlanetTeamSpeak\TeamSpeak3Framework\Node\Channel object matching the given name.
*
- * @param int $name
+ * @param string $name
* @return Channel
* @throws AdapterException
* @throws ServerQueryException
* @throws TransportException
*/
- public function subChannelGetByName(int $name): self
+ public function subChannelGetByName(string $name): self
{
foreach ($this->subChannelList() as $channel) {
if ($channel['channel_name'] == $name) {
@@ -134,23 +136,25 @@ public function clientList(array $filter = []): array
*/
public function clientGetById(int $clid): Client
{
- if (! array_key_exists($clid, $this->clientList())) {
+ $clientList = $this->clientList();
+
+ if (! array_key_exists($clid, $clientList)) {
throw new ServerQueryException('invalid clientID', 0x200);
}
- return $this->clientList[$clid];
+ return $clientList[$clid];
}
/**
* Returns the PlanetTeamSpeak\TeamSpeak3Framework\Node\Client object matching the given name.
*
- * @param int $name
+ * @param string $name
* @return Client
* @throws AdapterException
* @throws ServerQueryException
* @throws TransportException
*/
- public function clientGetByName(int $name): Client
+ public function clientGetByName(string $name): Client
{
foreach ($this->clientList() as $client) {
if ($client['client_nickname'] == $name) {
diff --git a/src/Node/Node.php b/src/Node/Node.php
index 772ed024..49288d7a 100644
--- a/src/Node/Node.php
+++ b/src/Node/Node.php
@@ -136,8 +136,11 @@ public function iconIsLocal(string $key): bool
public function iconGetName(string $key): StringHelper
{
$iconid = $this[$key];
- if (! is_int($iconid)) {
+
+ if ($iconid instanceof StringHelper) {
$iconid = $iconid->toInt();
+ } elseif (! is_int($iconid)) {
+ $iconid = (int) $iconid;
}
$iconid = $iconid < 0 ? pow(2, 32) - abs($iconid) : $iconid;
@@ -145,6 +148,49 @@ public function iconGetName(string $key): StringHelper
return new StringHelper('/icon_'.$iconid);
}
+ public function iconList(): array
+ {
+ $iconBasePath = '/icons';
+
+ try {
+ $files = $this->execute('ftgetfilelist', [
+ 'cid' => 0,
+ 'cpw' => '',
+ 'path' => $iconBasePath,
+ ])->toArray();
+ } catch (\Exception $e) {
+ return [];
+ }
+
+ $result = [];
+
+ foreach ($files as $file) {
+ // Skip meta entry (“ftgetfilelist” exists)
+ if (isset($file['ftgetfilelist']) || ! isset($file['name'])) {
+ continue;
+ }
+
+ // Set a fallback path
+ $file['path'] = $file['path'] ?? $iconBasePath;
+ $file['cid'] = 0;
+ $file['sid'] = $this->getId();
+
+ // Create StringHelper
+ $src = new StringHelper('/'.ltrim($file['path'], '/'));
+ if (! $src->endsWith('/')) {
+ $src->append('/');
+ }
+ if (! empty($file['name'])) {
+ $src->append($file['name']);
+ }
+ $file['src'] = $src;
+
+ $result[] = $file;
+ }
+
+ return $result;
+ }
+
/**
* Returns a possible classname for the node which can be used as an HTML property.
*
@@ -318,7 +364,7 @@ public function getInfo(bool $extend = true, bool $convert = false): array
} elseif (str_ends_with($key, '_version')) {
$info[$key] = Convert::version($val);
} elseif (str_ends_with($key, '_icon_id')) {
- $info[$key] = $this->iconGetName($key)->filterDigits();
+ $info[$key] = $this->iconGetName($val)->filterDigits()->toInt();
}
}
}
@@ -346,51 +392,6 @@ public function getInfo(bool $extend = true, bool $convert = false): array
return $info;
}
- /**
- * Returns information about the host node and optionally the selected virtual server.
- */
- public function getFullInfo(?int $serverPort = null, bool $convert = false): array
- {
- // Retrieve host/node information
- $this->fetchNodeInfo();
- $info = $this->nodeInfo;
-
- // Retrieve VirtualServer if port has been specified
- if ($serverPort !== null) {
- try {
- $virtualServer = $this->serverGetByPort($serverPort); //polymorphic call is okay because we use strict analysis
- $vsInfo = $virtualServer->getInfo(false, false); // raw value
- $info = array_merge($info, $vsInfo);
- } catch (\Exception $e) {
- $info['virtualserver_error'] = $e->getMessage();
- }
- }
-
- if ($convert) {
- foreach ($info as $key => $val) {
- $keyObj = StringHelper::factory($key);
-
- if ($keyObj->contains('_bytes_')) {
- $info[$keyObj->toString()] = Convert::bytes($val);
- } elseif ($keyObj->contains('_bandwidth_')) {
- $info[$keyObj->toString()] = Convert::bytes($val).'/s';
- } elseif ($keyObj->contains('_packets_')) {
- $info[$keyObj->toString()] = number_format($val, 0, null, '.');
- } elseif ($keyObj->contains('_packetloss_')) {
- $info[$keyObj->toString()] = sprintf('%01.2f', floatval($val instanceof StringHelper ? $val->toString() : strval($val)) * 100).'%';
- } elseif ($keyObj->endsWith('_uptime')) {
- $info[$keyObj->toString()] = Convert::seconds($val);
- } elseif ($keyObj->endsWith('_version')) {
- $info[$keyObj->toString()] = Convert::version($val);
- } elseif ($keyObj->endsWith('_icon_id')) {
- $info[$keyObj->toString()] = $this->iconGetName($key)->filterDigits();
- }
- }
- }
-
- return $info;
- }
-
/**
* Returns the specified property or a pre-defined default value from the node info array.
*
diff --git a/src/Node/Server.php b/src/Node/Server.php
index 426857a8..797d8d93 100644
--- a/src/Node/Server.php
+++ b/src/Node/Server.php
@@ -476,14 +476,31 @@ public function channelClientPermRemove(int $cid, int $cldbid, int|array $permid
*/
public function channelFileList(int $cid, string $cpw = '', string $path = '/', bool $recursive = false): array
{
- $files = $this->execute('ftgetfilelist', ['cid' => $cid, 'cpw' => $cpw, 'path' => $path])->toArray();
+ try {
+ $files = $this->execute('ftgetfilelist', ['cid' => $cid, 'cpw' => $cpw, 'path' => $path])->toArray();
+ } catch (ServerQueryException $e) {
+ // only catch an empty result
+ if (str_contains($e->getMessage(), 'database empty result set')) {
+ return [];
+ }
+ throw $e;
+ }
+
$count = count($files);
+ $flattened = [];
for ($i = 0; $i < $count; $i++) {
+ // proof exists
+ if (empty($files[$i]['name'])) {
+ continue; // skip entry without a valid file extension
+ }
+
$files[$i]['sid'] = $this->getId();
- $files[$i]['cid'] = $files[0]['cid'];
- $files[$i]['path'] = $files[0]['path'];
- $files[$i]['src'] = new StringHelper($cid ? $files[$i]['path'] : '/');
+ $files[$i]['cid'] = $files[$i]['cid'] ?? $cid;
+ $files[$i]['path'] = $files[$i]['path'] ?? $path;
+
+ $src = $files[$i]['path'] ?? '/';
+ $files[$i]['src'] = StringHelper::factory($src);
if (! $files[$i]['src']->endsWith('/')) {
$files[$i]['src']->append('/');
@@ -491,14 +508,17 @@ public function channelFileList(int $cid, string $cpw = '', string $path = '/',
$files[$i]['src']->append($files[$i]['name']);
- if ($recursive && $files[$i]['type'] == TeamSpeak3::FILE_TYPE_DIRECTORY) {
- $files = array_merge($files, $this->channelFileList($cid, $cpw, $path.$files[$i]['name'], $recursive));
+ $flattened[] = $files[$i];
+
+ if ($recursive && ($files[$i]['type'] ?? '') == TeamSpeak3::FILE_TYPE_DIRECTORY) {
+ $nested = $this->channelFileList($cid, $cpw, $files[$i]['path'].$files[$i]['name'], $recursive);
+ $flattened = array_merge($flattened, $nested);
}
}
- uasort($files, [__CLASS__, 'sortFileList']);
+ uasort($flattened, [__CLASS__, 'sortFileList']);
- return $files;
+ return $flattened;
}
/**
@@ -766,8 +786,25 @@ public function clientInfoDb(int $cldbid): array
*/
public function clientFindDb(string $pattern, bool $uid = false): array
{
- return array_keys($this->execute('clientdbfind', ['pattern' => $pattern, ($uid) ? '-uid' : null, '-details'])
- ->toAssocArray('cldbid'));
+ $args = ['pattern' => $pattern];
+
+ // Flags must be appended as separate parameters
+ if ($uid) {
+ $args['-uid'] = null;
+ }
+
+ $args['-details'] = null;
+
+ try {
+ $result = $this->execute('clientdbfind', $args)->toAssocArray('cldbid');
+ } catch (ServerQueryException $e) {
+ if (str_contains($e->getMessage(), 'database empty result set')) {
+ return [];
+ }
+ throw $e;
+ }
+
+ return array_keys($result);
}
/**
@@ -781,7 +818,33 @@ public function clientCount(): int
return 0;
}
- return $this['virtualserver_clientsonline'] - $this['virtualserver_queryclientsonline'];
+ // Try direct access first
+ if (isset($this->nodeInfo[1]['virtualserver_clientsonline']) && isset($this->nodeInfo[1]['virtualserver_queryclientsonline'])) {
+ $clientsOnline = (int) $this->nodeInfo[1]['virtualserver_clientsonline'];
+ $queryClientsOnline = (int) $this->nodeInfo[1]['virtualserver_queryclientsonline'];
+ $result = $clientsOnline - $queryClientsOnline;
+
+ return max(0, $result);
+ }
+
+ // Fallback: try to refresh node info
+ try {
+ $this->fetchNodeInfo();
+
+ if (isset($this->nodeInfo[1]['virtualserver_clientsonline']) && isset($this->nodeInfo[1]['virtualserver_queryclientsonline'])) {
+ $clientsOnline = (int) $this->nodeInfo[1]['virtualserver_clientsonline'];
+ $queryClientsOnline = (int) $this->nodeInfo[1]['virtualserver_queryclientsonline'];
+ $result = $clientsOnline - $queryClientsOnline;
+
+ return max(0, $result);
+ }
+ } catch (Exception) {
+ // If fetching fails, return 0
+ return 0;
+ }
+
+ // Last fallback
+ return 0;
}
/**
@@ -1206,14 +1269,32 @@ public function serverGroupCopy(int $ssgid, string $name = null, int $tsgid = 0,
{
$this->serverGroupListReset();
- $sgid = $this->execute('servergroupcopy', ['ssgid' => $ssgid, 'tsgid' => $tsgid, 'name' => $name, 'type' => $type])
- ->toList();
+ $result = $this->execute('servergroupcopy', ['ssgid' => $ssgid, 'tsgid' => $tsgid, 'name' => $name, 'type' => $type])->toList();
if ($tsgid && $name) {
$this->serverGroupRename($tsgid, $name);
}
- return count($sgid) ? $sgid['sgid'] : $tsgid;
+ // Search for the new sgid in all elements of the result array
+ $sgid = null;
+
+ for ($i = count($result) - 1; $i >= 0; $i--) {
+ foreach ($result[$i] as $key => $value) {
+ if (stripos($key, 'sgid') !== false) {
+ // Extrahiere nur die führenden Ziffern
+ if (preg_match('/\d+/', $value, $matches)) {
+ $sgid = (int) $matches[0];
+ break 2;
+ }
+ }
+ }
+ }
+
+ if ($sgid === null) {
+ throw new \RuntimeException('serverGroupCopy: Could not determine a valid server group ID.');
+ }
+
+ return $sgid;
}
/**
@@ -2769,7 +2850,25 @@ protected function fetchNodeList(): void
*/
protected function fetchNodeInfo(): void
{
- $this->nodeInfo = array_merge($this->nodeInfo, $this->request('serverinfo')->toList());
+ $serverInfo = $this->request('serverinfo')->toList();
+ $this->nodeInfo = array_merge($this->nodeInfo, $serverInfo);
+
+ // Ensure virtualserver_status is set
+ if (! isset($this->nodeInfo['virtualserver_status'])) {
+ // Try to get the status from the parent's server list if available
+ try {
+ $serverList = $this->getParent()->serverList();
+ if (isset($serverList[$this->getId()])) {
+ $serverData = $serverList[$this->getId()]->getInfo(false);
+ if (isset($serverData['virtualserver_status'])) {
+ $this->nodeInfo['virtualserver_status'] = $serverData['virtualserver_status'];
+ }
+ }
+ } catch (Exception) {
+ // If we can't get the status, assume it offline
+ $this->nodeInfo['virtualserver_status'] = 'offline';
+ }
+ }
}
/**
@@ -2847,7 +2946,21 @@ protected static function sortFileList(array $a, array $b): int
*/
public function isOnline(): bool
{
- return $this['virtualserver_status'] == 'online';
+ // First, try to get the property without forcing a refresh
+ $status = $this->getProperty('virtualserver_status');
+
+ if ($status === null) {
+ // Force refresh the node info
+ try {
+ $this->fetchNodeInfo();
+ $status = $this->getProperty('virtualserver_status', 'offline');
+ } catch (Exception) {
+ // If fetching fails, assume it offline
+ return false;
+ }
+ }
+
+ return $status === 'online';
}
/**
@@ -2857,7 +2970,21 @@ public function isOnline(): bool
*/
public function isOffline(): bool
{
- return $this['virtualserver_status'] == 'offline';
+ // First, try to get the property without forcing a refresh
+ $status = $this->getProperty('virtualserver_status');
+
+ if ($status === null) {
+ // Force refresh the node info
+ try {
+ $this->fetchNodeInfo();
+ $status = $this->getProperty('virtualserver_status', 'offline');
+ } catch (Exception) {
+ // If fetching fails, assume it offline
+ return true;
+ }
+ }
+
+ return $status === 'offline';
}
/**
diff --git a/src/Node/ServerGroup.php b/src/Node/ServerGroup.php
index 90a85bf8..1ae5f0db 100644
--- a/src/Node/ServerGroup.php
+++ b/src/Node/ServerGroup.php
@@ -97,7 +97,7 @@ public function permList(bool $permsid = false): array
* Adds a set of specified permissions to the server group. Multiple permissions
* can be added by providing the four parameters of each permission in separate arrays.
*
- * @param int $permid
+ * @param int|array $permid
* @param int $permvalue
* @param int $permnegated
* @param int $permskip
@@ -106,7 +106,7 @@ public function permList(bool $permsid = false): array
* @throws ServerQueryException
* @throws TransportException
*/
- public function permAssign(int $permid, int $permvalue, int $permnegated = 0, int $permskip = 0): void
+ public function permAssign(int|array $permid, int $permvalue, int $permnegated = 0, int $permskip = 0): void
{
$this->getParent()->serverGroupPermAssign($this->getId(), $permid, $permvalue, $permnegated, $permskip);
}
@@ -115,13 +115,13 @@ public function permAssign(int $permid, int $permvalue, int $permnegated = 0, in
* Removes a set of specified permissions from the server group. Multiple
* permissions can be removed at once.
*
- * @param int $permid
+ * @param int|array $permid
* @return void
* @throws AdapterException
* @throws ServerQueryException
* @throws TransportException
*/
- public function permRemove(int $permid): void
+ public function permRemove(int|array $permid): void
{
$this->getParent()->serverGroupPermRemove($this->getId(), $permid);
}
@@ -216,6 +216,7 @@ public function getUniqueId(): string
*/
public function getIcon(): string
{
+ //TODO: HÄ whats this?
return 'group_server';
}
}
diff --git a/tests/Adapter/ServerQuery/ReplyTest.php b/tests/Adapter/ServerQuery/ReplyTest.php
index 3ec59125..345fd109 100644
--- a/tests/Adapter/ServerQuery/ReplyTest.php
+++ b/tests/Adapter/ServerQuery/ReplyTest.php
@@ -160,11 +160,6 @@ public function testToArray()
$this->assertEquals(static::$E_CLIENTLIST_EXTENDED_SINGLE_CLIENT_BADGES, (string) $clientlist_array['client_badges']);
}
- public function testToAssocArray()
- {
- $this->markTestSkipped('todo: testToTable');
- }
-
/**
* @throws AdapterException
* @throws ServerQueryException
@@ -194,24 +189,4 @@ public function testToList()
$this->assertEquals('N', $reply->toList()[3]['client_nickname']);
$this->assertEquals('Q', $reply->toList()[3]['client_unique_identifier']);
}
-
- public function testToObjectArray()
- {
- $this->markTestSkipped('todo: testToObjectArray');
- }
-
- public function testGetCommandString()
- {
- $this->markTestSkipped('todo: testGetCommandString');
- }
-
- public function testGetNotifyEvents()
- {
- $this->markTestSkipped('todo: testGetNotifyEvents');
- }
-
- public function testFetchReply()
- {
- $this->markTestSkipped('todo: testFetchReply');
- }
}
diff --git a/tests/DevLiveServer/ChannelTest.php b/tests/DevLiveServer/ChannelTest.php
index ed38ffd5..bdaa89e0 100644
--- a/tests/DevLiveServer/ChannelTest.php
+++ b/tests/DevLiveServer/ChannelTest.php
@@ -575,6 +575,157 @@ public function test_invalid_parameter_size_length()
$ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
}
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_handle_file_directory()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_channel($ts3_VirtualServer);
+
+ $ts3_VirtualServer->channelDirCreate($this->test_cid, '', '/test_dir');
+ $fileList = $ts3_VirtualServer->channelFileList($this->test_cid);
+
+ foreach ($fileList as $file) {
+ $this->assertEquals('test_dir', $file['name']);
+ $this->assertIsString($file['name']);
+ }
+
+ $ts3_VirtualServer->channelFileRename($this->test_cid, '', '/test_dir', '/test_dir_renamed');
+ $ts3_VirtualServer->channelFileDelete($this->test_cid, '', '/test_dir_renamed');
+ $fileList = $ts3_VirtualServer->channelFileList($this->test_cid);
+ $this->assertEmpty($fileList);
+
+ //enhance test to validate over channel.php
+ $ts3_VirtualServer->channelGetById($this->test_cid)->dirCreate('', '/test_dir');
+ $fileListGetByChannelID = $ts3_VirtualServer->channelGetById($this->test_cid)->fileList();
+ $ts3_VirtualServer->channelGetById($this->test_cid)->fileRename('', '/test_dir', '/test_dir_renamed');
+
+ foreach ($fileListGetByChannelID as $fileGetByChannelID) {
+ $this->assertEquals('test_dir', $fileGetByChannelID['name']);
+ $this->assertIsString($fileGetByChannelID['name']);
+ }
+
+ $ts3_VirtualServer->channelGetById($this->test_cid)->fileDelete('', '/test_dir_renamed');
+ $fileList = $ts3_VirtualServer->channelGetById($this->test_cid)->fileList();
+ $this->assertEmpty($fileList);
+
+ $this->unset_play_test_channel($ts3_VirtualServer);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_get_level()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_channel($ts3_VirtualServer);
+
+ //get level means hierarchy level
+ $getLevel = $ts3_VirtualServer->channelGetLevel($this->test_cid);
+ $this->assertEquals(1, $getLevel);
+
+ $channelCidLevelOne = $ts3_VirtualServer->channelgetByName('Play-Test')->getId();
+ $cidChannelLevelTwo = $ts3_VirtualServer->channelcreate(['channel_name' => 'Standard Channel Level 2', 'channel_flag_permanent' => 1, 'cpid' => $channelCidLevelOne]);
+ $getLevelTwo = $ts3_VirtualServer->channelGetLevel($cidChannelLevelTwo);
+ $this->assertEquals(2, $getLevelTwo);
+
+ //enhance test to validate over channel.php
+ $getLevelOverChannel = $ts3_VirtualServer->channelGetByName('Standard Channel Level 2')->getLevel();
+ $this->assertEquals(2, $getLevelOverChannel);
+
+ $this->unset_play_test_channel($ts3_VirtualServer);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_get_subChannelList()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_channel($ts3_VirtualServer);
+
+ $subChannelList = $ts3_VirtualServer->channelGetByName('UnitTest')->subChannelList();
+
+ foreach ($subChannelList as $subChannel) {
+ $this->assertEquals('Play-Test', $subChannel['channel_name']);
+ }
+
+ $this->unset_play_test_channel($ts3_VirtualServer);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_get_subChannelGetById()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_channel($ts3_VirtualServer);
+
+ $subChannel = $ts3_VirtualServer->channelGetByName('UnitTest')->subChannelGetById($this->test_cid);
+
+ $this->assertEquals('Play-Test', $subChannel['channel_name']);
+ $this->assertIsInt($subChannel['cid']);
+
+ $this->unset_play_test_channel($ts3_VirtualServer);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_get_subChannelGetByName()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_channel($ts3_VirtualServer);
+
+ $subChannel = $ts3_VirtualServer->channelGetByName('UnitTest')->subChannelGetByName('Play-Test');
+
+ $this->assertEquals('Play-Test', $subChannel['channel_name']);
+ $this->assertIsInt($subChannel['cid']);
+
+ $this->unset_play_test_channel($ts3_VirtualServer);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
/**
* @throws AdapterException
* @throws TransportException
diff --git a/tests/DevLiveServer/ClientTest.php b/tests/DevLiveServer/ClientTest.php
index 0bf45607..cd963e85 100644
--- a/tests/DevLiveServer/ClientTest.php
+++ b/tests/DevLiveServer/ClientTest.php
@@ -147,10 +147,225 @@ public function test_can_move_user()
$userMoved = $ts3_VirtualServer->clientGetByName($this->ts3_unit_test_userName)->getInfo();
$this->assertEquals($userMoved['cid'], $testCid);
+ //get client by channel list
+ $clientChannelList = $ts3_VirtualServer->channelGetById($testCid)->clientList();
+ foreach ($clientChannelList as $client) {
+ $this->assertEquals($this->ts3_unit_test_userName, $client['client_nickname']);
+ }
+
+ //get client by channel clientGetById
+ $clientChannelByID = $ts3_VirtualServer->channelGetById($testCid)->clientGetById($userID);
+ $this->assertEquals($this->ts3_unit_test_userName, $clientChannelByID['client_nickname']);
+
+ //get client by channel clientGetByName
+ $clientChannelByName = $ts3_VirtualServer->channelGetById($testCid)->clientGetByName($this->ts3_unit_test_userName);
+ $this->assertEquals($this->ts3_unit_test_userName, $clientChannelByName['client_nickname']);
+
$this->unset_play_test_channel($ts3_VirtualServer);
$ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
}
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_send_client_text_message()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $userID = $ts3_VirtualServer->clientGetByName($this->ts3_unit_test_userName)->getId();
+ $this->assertIsInt($userID);
+ $userID = $ts3_VirtualServer->clientGetById($userID);
+ $this->assertIsObject($userID);
+ $userID->message('Hello World');
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_send_client_poke()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $userID = $ts3_VirtualServer->clientGetByName($this->ts3_unit_test_userName)->getId();
+ $userID = $ts3_VirtualServer->clientGetById($userID);
+ $userID->poke('UnitTest');
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws HelperException
+ */
+ public function test_can_find_client_by_name_pattern()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $userFindings = $ts3_VirtualServer->clientFind('UnitT');
+
+ foreach ($userFindings as $user) {
+ $this->assertEquals($this->ts3_unit_test_userName, $user['client_nickname']);
+ }
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws HelperException
+ */
+ public function test_can_get_clientListDB()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $clientListDb = $ts3_VirtualServer->clientListDb();
+ $this->assertIsArray($clientListDb);
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ */
+ public function test_can_get_clientInfoDB()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $clientInfoDB = [];
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $clientListDb = $ts3_VirtualServer->clientListDb();
+
+ foreach ($clientListDb as $client) {
+ if ($client['client_nickname'] == $this->ts3_unit_test_userName) {
+ $clientInfoDB = $ts3_VirtualServer->clientInfoDb($client['cldbid']);
+ }
+ }
+
+ $this->assertIsArray($clientInfoDB);
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws HelperException
+ */
+ public function test_can_clientFindDb_by_name_pattern()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $resultArray = $ts3_VirtualServer->clientFindDb('UnitT');
+
+ foreach ($resultArray as $user) {
+ var_dump($user);
+ $this->assertEquals($this->ts3_unit_test_userName, $user['client_nickname']);
+ }
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws HelperException
+ * @throws ServerQueryException
+ */
+ public function test_can_get_clientCount()
+ {
+ if ($this->user_test_active == 'false' || $this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $clientCount = $ts3_VirtualServer->clientCount();
+ $this->assertIsInt($clientCount);
+ $this->assertGreaterThan(0, $clientCount);
+
+ $this->asserttrue(true);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws HelperException
+ * @throws NodeException
+ */
+ public function test_can_add_list_del_client_to_servergroup()
+ {
+ if ($this->active == 'false' || $this->user_test_active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $sgid = $ts3_VirtualServer->serverGroupCreate('UnitTest', 1);
+
+ $user = $ts3_VirtualServer->clientGetByName($this->ts3_unit_test_userName);
+ $clidDB = $ts3_VirtualServer->clientGetByUid($user['client_unique_identifier']);
+
+ $ts3_VirtualServer->serverGroupGetById($sgid)->clientAdd($clidDB['client_database_id']);
+ $clientList = $ts3_VirtualServer->serverGroupGetById($sgid)->clientList();
+
+ foreach ($clientList as $client) {
+ $this->assertEquals($this->ts3_unit_test_userName, $client['client_nickname']);
+ }
+
+ $ts3_VirtualServer->serverGroupGetById($sgid)->clientDel($clidDB['client_database_id']);
+
+ //remember at this point the test will fail if the user is still in the servergroup
+ // unset will not force delete the user from the servergroup
+ $ts3_VirtualServer->serverGroupDelete($sgid);
+ $ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
/**
* @throws AdapterException
* @throws ServerQueryException
diff --git a/tests/DevLiveServer/FoundIssuesOnPublicProjectsTest.php b/tests/DevLiveServer/FoundIssuesOnPublicProjectsTest.php
new file mode 100644
index 00000000..3bacda92
--- /dev/null
+++ b/tests/DevLiveServer/FoundIssuesOnPublicProjectsTest.php
@@ -0,0 +1,107 @@
+active = str_replace('DEV_LIVE_SERVER_AVAILABLE=', '', preg_replace('#\n(?!\n)#', '', $env[2]));
+ $this->host = str_replace('DEV_LIVE_SERVER_HOST=', '', preg_replace('#\n(?!\n)#', '', $env[3]));
+ $this->queryPort = str_replace('DEV_LIVE_SERVER_QUERY_PORT=', '', preg_replace('#\n(?!\n)#', '', $env[4]));
+ $this->user = str_replace('DEV_LIVE_SERVER_QUERY_USER=', '', preg_replace('#\n(?!\n)#', '', $env[5]));
+ $this->password = str_replace('DEV_LIVE_SERVER_QUERY_USER_PASSWORD=', '', preg_replace('#\n(?!\n)#', '', $env[6]));
+ } else {
+ $this->active = 'false';
+ }
+
+ $this->ts3_server_uri = 'serverquery://'.$this->user.':'.$this->password.'@'.$this->host.':'.$this->queryPort.
+ '/?server_port=9987'.
+ '&no_query_clients=0'.
+ '&timeout=30';
+ }
+
+ /**
+ * @throws \Exception
+ */
+ public function test_can_get_virtual_servername(): void
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ try {
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ } catch(TeamSpeak3Exception $e) {
+ echo $e->getMessage();
+ }
+
+ try {
+ $this->ts3_VirtualServer->virtualserver_name;
+ } catch (TeamSpeak3Exception $e) {
+ $this->assertEquals("node 'PlanetTeamSpeak\TeamSpeak3Framework\Node\Server' has no property named 'virtualserver_name'", $e->getMessage());
+ }
+
+ $serverName = $this->ts3_VirtualServer->getInfo()['virtualserver_name'];
+ $this->assertNotEmpty($serverName);
+
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws \Exception
+ */
+ public function test_can_getInfo_with_convert_option(): void
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ try {
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ } catch(TeamSpeak3Exception $e) {
+ echo $e->getMessage();
+ }
+
+ $serverinfo = $this->ts3_VirtualServer->getInfo(true, true);
+ $this->assertArrayHasKey('virtualserver_icon_id', $serverinfo);
+ $this->assertEquals(1, $serverinfo['virtualserver_icon_id']);
+ $this->assertIsInt($serverinfo['virtualserver_icon_id']);
+
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+}
diff --git a/tests/DevLiveServer/RefactorFunctionsTest.php b/tests/DevLiveServer/RefactorFunctionsTest.php
index a2a09c52..724bbd42 100644
--- a/tests/DevLiveServer/RefactorFunctionsTest.php
+++ b/tests/DevLiveServer/RefactorFunctionsTest.php
@@ -7,7 +7,6 @@
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\AdapterException;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\NodeException;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\ServerQueryException;
-use PlanetTeamSpeak\TeamSpeak3Framework\Exception\TeamSpeak3Exception;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\TransportException;
use PlanetTeamSpeak\TeamSpeak3Framework\Node\Host;
use PlanetTeamSpeak\TeamSpeak3Framework\Node\Node;
@@ -69,13 +68,7 @@ public function test_clientupdate_getErrorProperty()
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- // Connect to the specified server, authenticate and spawn an object for the virtual server
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- //catch exception
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
$clientUpdate = $this->ts3_VirtualServer->getAdapter()->request('clientupdate');
$clientUpdateResult = $clientUpdate->getErrorProperty('msg')->toString();
@@ -99,13 +92,7 @@ public function test_serverGroupList_serverGroupClientList()
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- // Connect to the specified server, authenticate and spawn an object for the virtual server
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- //catch exception
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
// Resetting lists
$this->ts3_VirtualServer->clientListReset();
@@ -142,13 +129,7 @@ public function test_channelGroupList_channelGroupClientList()
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- // Connect to the specified server, authenticate and spawn an object for the virtual server
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- //catch exception
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
// Resetting lists
$this->ts3_VirtualServer->clientListReset();
@@ -179,11 +160,7 @@ public function test_can_create_server_group(): void
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
$sid = $this->ts3_VirtualServer->serverGroupCreate('UniTest', 1);
$this->ts3_VirtualServer->serverGroupDelete($sid);
@@ -204,11 +181,7 @@ public function test_can_create_channel_group(): void
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
$cgid = $this->ts3_VirtualServer->channelGroupCreate('UniTest', 1);
$this->ts3_VirtualServer->channelGroupDelete($cgid);
@@ -229,11 +202,7 @@ public function test_invalid_parameter_size(): void
$this->markTestSkipped('DevLiveServer ist not active');
}
- try {
- $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
- } catch(TeamSpeak3Exception $e) {
- echo $e->getMessage();
- }
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
//#channel name
//30 chars
@@ -273,4 +242,25 @@ public function test_invalid_parameter_size(): void
$this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
$this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
}
+
+ /**
+ * @throws \Exception
+ */
+ public function test_can_get_isOnline_isOffline(): void
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+
+ $statusOnline = $this->ts3_VirtualServer->isOnline();
+ $statusOffline = $this->ts3_VirtualServer->isOffline();
+
+ $this->assertTrue($statusOnline);
+ $this->assertFalse($statusOffline);
+
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
}
diff --git a/tests/DevLiveServer/ServerGroupTest.php b/tests/DevLiveServer/ServerGroupTest.php
new file mode 100644
index 00000000..5c8f3e2b
--- /dev/null
+++ b/tests/DevLiveServer/ServerGroupTest.php
@@ -0,0 +1,264 @@
+active = str_replace('DEV_LIVE_SERVER_AVAILABLE=', '', preg_replace('#\n(?!\n)#', '', $env[2]));
+ $this->host = str_replace('DEV_LIVE_SERVER_HOST=', '', preg_replace('#\n(?!\n)#', '', $env[3]));
+ $this->queryPort = str_replace('DEV_LIVE_SERVER_QUERY_PORT=', '', preg_replace('#\n(?!\n)#', '', $env[4]));
+ $this->user = str_replace('DEV_LIVE_SERVER_QUERY_USER=', '', preg_replace('#\n(?!\n)#', '', $env[5]));
+ $this->password = str_replace('DEV_LIVE_SERVER_QUERY_USER_PASSWORD=', '', preg_replace('#\n(?!\n)#', '', $env[6]));
+ } else {
+ $this->active = 'false';
+ }
+
+ $this->ts3_server_uri = 'serverquery://'.$this->user.':'.$this->password.'@'.$this->host.':'.$this->queryPort.
+ '/?server_port=9987'.
+ '&no_query_clients=0'.
+ '&timeout=30';
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws NodeException
+ * @throws HelperException
+ */
+ public function test_can_get_servergroup_by_name()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ $serverGroupName = $this->ts3_VirtualServer->serverGroupGetByName('UnitTest');
+ $this->assertEquals('UnitTest', $serverGroupName['name']);
+ $this->assertIsString($serverGroupName['name']);
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws \Exception
+ */
+ public function test_can_rename_servergroup()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ $this->ts3_VirtualServer->servergrouprename($this->sgid, 'UnitTest-Renamed');
+ $renamedServerGroup = $this->ts3_VirtualServer->serverGroupGetById($this->sgid);
+ $this->assertEquals('UnitTest-Renamed', $renamedServerGroup['name']);
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+
+ //test by ServerGroup Class
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->rename('UnitTest-Renamed');
+ $renamedByChain = $this->ts3_VirtualServer->serverGroupGetById($this->sgid);
+ $this->assertEquals('UnitTest-Renamed', $renamedByChain['name']);
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws NodeException
+ * @throws HelperException
+ */
+ public function test_can_copy_servergroup()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ $duplicatedSGID = $this->ts3_VirtualServer->serverGroupCopy($this->sgid, 'UnitTest-Copy');
+ $getDuplicatedServerGroup = $this->ts3_VirtualServer->serverGroupGetById($duplicatedSGID);
+ $this->assertEquals('UnitTest-Copy', $getDuplicatedServerGroup['name']);
+
+ $this->ts3_VirtualServer->serverGroupDelete($duplicatedSGID);
+ try {
+ $this->ts3_VirtualServer->serverGroupGetById($duplicatedSGID);
+ $this->fail('ServerGroup should not exist');
+ } catch (ServerQueryException $e) {
+ $this->assertEquals('invalid groupID', $e->getMessage());
+ }
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+
+ //test by ServerGroup Class
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ $duplicatedSGIDChain = $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->copy('UnitTest-Copy');
+ $getDuplicatedServerGroupChain = $this->ts3_VirtualServer->serverGroupGetById($duplicatedSGIDChain);
+ $this->assertEquals('UnitTest-Copy', $getDuplicatedServerGroupChain['name']);
+
+ $this->ts3_VirtualServer->serverGroupDelete($getDuplicatedServerGroupChain->getId());
+ try {
+ $this->ts3_VirtualServer->serverGroupGetById($getDuplicatedServerGroupChain->getId());
+ $this->fail('ServerGroup should not exist');
+ } catch (ServerQueryException $e) {
+ $this->assertEquals('invalid groupID', $e->getMessage());
+ }
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws TransportException
+ * @throws ServerQueryException
+ * @throws AdapterException
+ * @throws NodeException
+ * @throws HelperException
+ */
+ public function test_can_assign_remove_permissions_to_servergroup()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ $this->ts3_VirtualServer->serverGroupPermAssign($this->sgid, ['i_client_private_textmessage_power'], [75], [0], [0]);
+ $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->permAssign(['i_client_talk_power'], 75);
+
+ $permList = $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->permList(true);
+ $this->assertEquals(75, $permList['i_client_talk_power']['permvalue']);
+ $this->assertEquals(75, $permList['i_client_private_textmessage_power']['permvalue']);
+
+ $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->permRemove(['i_client_private_textmessage_power']);
+ $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->permRemove(['i_client_talk_power']);
+
+ $permListKeyRemoved = $this->ts3_VirtualServer->serverGroupGetById($this->sgid)->permList(true);
+
+ $this->assertArrayNotHasKey('i_client_talk_power', $permListKeyRemoved);
+ $this->assertArrayNotHasKey('i_client_private_textmessage_power', $permListKeyRemoved);
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws HelperException
+ * @throws ServerQueryException
+ * @throws TransportException
+ */
+ public function test_can_get_iconList()
+ {
+ if ($this->active == 'false') {
+ $this->markTestSkipped('DevLiveServer ist not active');
+ }
+
+ $this->ts3_VirtualServer = TeamSpeak3::factory($this->ts3_server_uri);
+ $this->set_play_test_servergroup($this->ts3_VirtualServer);
+
+ //memo: an array can be empty if no icons uploaded
+ $iconList = $this->ts3_VirtualServer->iconList();
+ $this->assertIsarray($iconList);
+
+ $this->unset_play_test_servergroup($this->ts3_VirtualServer);
+ $this->ts3_VirtualServer->getAdapter()->getTransport()->disconnect();
+ $this->assertFalse($this->ts3_VirtualServer->getAdapter()->getTransport()->isConnected());
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws ServerQueryException
+ * @throws TransportException
+ */
+ private function set_play_test_servergroup(Server $ts3VirtualServer): void
+ {
+ $this->sgid = $ts3VirtualServer->serverGroupCreate('UnitTest', 1);
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws ServerQueryException
+ * @throws HelperException
+ */
+ public function unset_play_test_servergroup($ts3_VirtualServer): void
+ {
+ $ts3_VirtualServer->serverGroupDelete($this->sgid);
+ }
+
+ /**
+ * @throws AdapterException
+ * @throws NodeException
+ * @throws TransportException
+ * @throws ServerQueryException
+ */
+ public function dev_reset_servergroup(): void
+ {
+ $servergrouplist = $this->ts3_VirtualServer->serverGroupList(['type' => 1]);
+ foreach ($servergrouplist as $servergroup) {
+ if ($servergroup['name'] != 'Server Admin' && $servergroup['name'] != 'Guest') {
+ $this->ts3_VirtualServer->serverGroupDelete($servergroup['sgid'], true);
+ }
+ }
+ }
+}
diff --git a/tests/Transport/TransportTest.php b/tests/Transport/TransportTest.php
deleted file mode 100644
index ad27c9f6..00000000
--- a/tests/Transport/TransportTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
- '0.0.0.0', 'port' => 9987]);
- }
-
- /**
- * @throws AdapterException
- */
- public function testGetAdapterTypeReturnValue()
- {
- $this->markTestSkipped('Mockserverquery is not working it will be fixed in the future');
- $mockServerQuery = $this->createMockServerQuery();
-
- // The original value should be returned as it is
- $this->assertEquals('MockServerQuery', $mockServerQuery->getTransport()->getAdapterType());
-
- // The Signal class combines the lowered class name with an additional string for the `emit()` function
- $this->assertEquals('mockserverquery', strtolower($mockServerQuery->getTransport()->getAdapterType()));
- }
-}