/
RemoteControlTest.php
62 lines (47 loc) · 1.78 KB
/
RemoteControlTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace ls\tests;
use Yii;
class RemoteControlTest extends TestBaseClassWeb
{
private static $tmpBaseUrl;
private static $tmpRPCType;
private static $client;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
$urlMan = Yii::app()->urlManager;
self::$tmpBaseUrl = $urlMan->getBaseUrl();
$urlMan->setBaseUrl('http://' . self::$domain . '/index.php');
//$serverUrl = App()->createAbsoluteUrl('/admin/remotecontrol');
$serverUrl = $urlMan->createUrl('/admin/remotecontrol');
self::$tmpRPCType = Yii::app()->getConfig('RPCInterface');
if (self::$tmpRPCType === 'off') {
\SettingGlobal::setSetting('RPCInterface', 'json');
$RPCType = 'json';
} else {
$RPCType = self::$tmpRPCType;
}
if ($RPCType == 'xml') {
$cur_path = get_include_path();
set_include_path($cur_path . PATH_SEPARATOR . APPPATH . 'helpers');
require_once('Zend/XmlRpc/Client.php');
self::$client = new \Zend_XmlRpc_Client($serverUrl);
} elseif ($RPCType == 'json') {
Yii::app()->loadLibrary('jsonRPCClient');
self::$client = new \jsonRPCClient($serverUrl);
}
}
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
$urlMan = Yii::app()->urlManager;
$urlMan->setBaseUrl(self::$tmpBaseUrl);
\SettingGlobal::setSetting('RPCInterface', self::$tmpRPCType);
}
public function testGetSessionKey()
{
$sessionKey = self::$client->call('get_session_key', ['admin', 'password']);
$this->assertIsNotArray($sessionKey);
self::$client->call('release_session_key', [$sessionKey]);
}
}