forked from smsapi/smsapi-php-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTest.php
More file actions
180 lines (135 loc) · 3.72 KB
/
Copy pathUserTest.php
File metadata and controls
180 lines (135 loc) · 3.72 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
class UserTest extends SmsapiTestCase
{
private static $userTest;
/**
* @var \SMSApi\Api\UserFactory
*/
private $userFactory;
public static function setUpBeforeClass()
{
self::$userTest = "test-smsapi-client";
}
protected function setUp()
{
$this->userFactory = new \SMSApi\Api\UserFactory($this->proxy, $this->client());
}
private function renderUserItem($item)
{
if( $item ) {
print("Username: " . $item->getUsername()
. " Limit: " . $item->getLimit()
. " MouthLimit:" . $item->getMonthLimit()
. " Phonebook:" . $item->getPhonebook()
. " Senders: " . $item->getSenders()
. " Active: " . $item->getActive()
. "\n");
} else {
print("Item is null");
}
}
public function testAdd()
{
if ($this->userExists()) {
$this->markTestSkipped("User: \"" . self::$userTest . "\" already exists. No need to add another.");
}
$result = null;
$error = 0;
$action = $this->userFactory->actionAdd(self::$userTest)
->setPassword(md5("100costma100"))
->setPasswordApi(md5("200costam200"))
->setActive(true)
->setLimit("5.5")
->setPhonebook(true);
$result = $action->execute();
/* @var $result \SMSApi\Api\Response\UserResponse */
if( empty($result) ) {
$error++;
}
echo "\nUserAdd:\n";
$this->renderUserItem($result);
$this->assertEquals(0, $error);
}
private function userExists()
{
try {
$this->getApiUser();
return true;
} catch(\SMSApi\Exception\ActionException $e) {
return false;
}
}
public function testGet()
{
$result = $this->getApiUser();
echo "\nUserGet:\n";
$error = 0;
if( empty($result) ) {
$error++;
}
$this->renderUserItem($result);
$this->assertEquals(0, $error);
}
public function testEdit()
{
$result = null;
$error = 0;
$action = $this->userFactory->actionEdit(self::$userTest)
->setLimit("10")
->setInfo("to jest test");
$result = $action->execute();
/* @var $result \SMSApi\Api\Response\UserResponse */
echo "\nUserEdit:\n";
if( empty($result) ) {
$error++;
}
$this->renderUserItem($result);
$this->assertEquals(0, $error);
}
public function testList()
{
$result = null;
$error = 0;
$action = $this->userFactory->actionList();
/* @var $result \SMSApi\Api\Response\UsersResponse */
/* @var $item \SMSApi\Api\Response\UserResponse */
$result = $action->execute();
echo "\nUserList:\n";
if( empty($result) ) {
$error++;
}
foreach( $result->getList() as $item ) {
$this->renderUserItem($item);
}
$this->assertEquals(0, $error);
}
public function testGetPoints()
{
$action = $this->userFactory->actionGetPoints();
$result = $action->execute();
$this->assertInstanceOf(\SMSApi\Api\Response\PointsResponse::className, $result);
$this->greaterThanOrEqual($result->getPoints(), 0);
}
/**
* @return \SMSApi\Api\Response\UserResponse
*/
private function getApiUser()
{
$action = $this->userFactory->actionGet(self::$userTest);
$result = $action->execute();
return $result;
}
public function testGetPointsDetails()
{
$result = $this->userFactory
->actionGetPoints()
->setDetails(true)
->execute();
$this->assertGreaterThanOrEqual(0, $result->getPoints());
$this->assertGreaterThanOrEqual(0, $result->getProCount());
$this->assertGreaterThanOrEqual(0, $result->getEcoCount());
$this->assertGreaterThanOrEqual(0, $result->getMmsCount());
$this->assertGreaterThanOrEqual(0, $result->getVmsGsmCount());
$this->assertGreaterThanOrEqual(0, $result->getVmsLandCount());
}
}