|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: lenovo |
|
5
|
|
|
* Date: 6/15/2018 |
|
6
|
|
|
* Time: 3:28 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace TimSDK\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use TimSDK\Core\API; |
|
12
|
|
|
use TimSDK\TimCloud; |
|
13
|
|
|
|
|
14
|
|
|
class TimCloudTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testEnv() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->assertTrue(phpunit_env('phpunit_running')); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testCertPemExist() |
|
22
|
|
|
{ |
|
23
|
|
|
$t = $this->timCloud(); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertTrue(file_exists($t['path.cert'] . '/cacert.pem')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testRefreshConfiguration() |
|
29
|
|
|
{ |
|
30
|
|
|
$timCloud = $this->timCloud(); |
|
31
|
|
|
|
|
32
|
|
|
$this->assertFalse($timCloud->im->isNeedRefresh()); |
|
33
|
|
|
|
|
34
|
|
|
$timCloud->setIdentifier('admin'); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertTrue($timCloud->im->isNeedRefresh()); |
|
37
|
|
|
|
|
38
|
|
|
$query = $timCloud->im->getRefreshedQueryStringArray(); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertSame('admin', $query['identifier']); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFormatKey() |
|
44
|
|
|
{ |
|
45
|
|
|
$timCloud = $this->timCloud(); |
|
46
|
|
|
|
|
47
|
|
|
$prikey = $timCloud->formatKey(phpunit_env('private_key'), 'private'); |
|
48
|
|
|
$pubkey = $timCloud->formatKey(phpunit_env('public_key'), 'public'); |
|
49
|
|
|
|
|
50
|
|
|
$prikeyResource = openssl_pkey_get_private($prikey); |
|
51
|
|
|
$pubkeyResource = openssl_pkey_get_public($pubkey); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertTrue(is_resource($prikeyResource)); |
|
54
|
|
|
$this->assertTrue(is_resource($pubkeyResource)); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testRequestApi() |
|
58
|
|
|
{ |
|
59
|
|
|
$t = $this->timCloud(); |
|
60
|
|
|
$c = $t->request(API::DIRTY_WORDS_GET); |
|
61
|
|
|
$this->assertSame('OK', $c->getContent('ActionStatus')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function timCloud() |
|
65
|
|
|
{ |
|
66
|
|
|
return new TimCloud([ |
|
67
|
|
|
'sdkappid' => phpunit_env('sdk_appid'), |
|
68
|
|
|
'identifier' => phpunit_env('identifier'), |
|
69
|
|
|
'prikey' => phpunit_env('private_key'), |
|
70
|
|
|
'pubkey' => phpunit_env('public_key'), |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|