Skip to content

Commit d2853a3

Browse files
Sander van der Vlugtsibprogrammer
authored andcommitted
Add servicePlan create and delete
1 parent a484fc9 commit d2853a3

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

src/Api/Operator/ServicePlan.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ public function getAll()
2828
return $this->_get();
2929
}
3030

31+
/**
32+
* @param string $planName
33+
* @return Struct\Info
34+
*/
35+
public function create($planName)
36+
{
37+
$packet = $this->_client->getPacket();
38+
$info = $packet->addChild($this->_wrapperTag)->addChild('add');
39+
$info->addChild('name', $planName);
40+
41+
$response = $this->_client->request($packet);
42+
return new Struct\Info($response);
43+
}
44+
45+
/**
46+
* @param string $field
47+
* @param integer|string $value
48+
* @return bool
49+
*/
50+
public function delete($field, $value)
51+
{
52+
return $this->_delete($field, $value);
53+
}
54+
3155
/**
3256
* @param string|null $field
3357
* @param int|string|null $value

tests/ServicePlanTest.php

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,76 @@ class ServicePlanTest extends TestCase
77
{
88
public function testGet()
99
{
10-
$servicePlan = static::$_client->servicePlan()->get('name', 'Default Domain');
11-
$this->assertEquals('Default Domain', $servicePlan->name);
12-
$this->assertGreaterThan(0, $servicePlan->id);
10+
$servicePlan = static::_createServicePlan();
11+
$servicePlanInfo = static::$_client->servicePlan()->get('id', $servicePlan->id);
12+
$this->assertNotEmpty($servicePlanInfo->name);
13+
$this->assertSame($servicePlan->id, $servicePlanInfo->id);
14+
15+
static::$_client->servicePlan()->delete('id', $servicePlan->id);
1316
}
1417

1518
public function testGetAll()
1619
{
20+
static::_createServicePlan();
21+
static::_createServicePlan();
22+
static::_createServicePlan();
23+
1724
$servicePlans = static::$_client->servicePlan()->getAll();
1825
$this->assertIsArray($servicePlans);
19-
$this->assertGreaterThan(0, count($servicePlans));
26+
$this->assertGreaterThan(2, count($servicePlans));
2027
$this->assertNotEmpty($servicePlans[0]->name);
2128
}
29+
30+
public function testCreateServicePlan()
31+
{
32+
$servicePlan = static::_createServicePlan();
33+
$this->assertGreaterThan(0, $servicePlan->id);
34+
35+
static::$_client->servicePlan()->delete('id', $servicePlan->id);
36+
}
37+
38+
public function testDelete()
39+
{
40+
$servicePlan = static::_createServicePlan();
41+
$result = static::$_client->servicePlan()->delete('id', $servicePlan->id);
42+
43+
$this->assertTrue($result);
44+
}
45+
46+
public function testRequestCreateServicePlan()
47+
{
48+
$request = [
49+
'add' => [
50+
'name' => 'Service Plan Full Test',
51+
'limits' => [
52+
'overuse' => 'block',
53+
],
54+
'preferences' => [
55+
'stat' => 6,
56+
'maillists' => 'true',
57+
],
58+
'hosting' => [
59+
'property' => [
60+
[
61+
'name' => 'ftp_quota',
62+
'value' => '-1',
63+
],
64+
[
65+
'name' => 'ssl',
66+
'value' => 'true',
67+
],
68+
],
69+
],
70+
'performance' => [
71+
'bandwidth' => 1000,
72+
'max_connections' => 20,
73+
],
74+
],
75+
];
76+
77+
$servicePlan = static::$_client->servicePlan()->request($request);
78+
$this->assertGreaterThan(0, $servicePlan->id);
79+
80+
static::$_client->servicePlan()->delete('id', $servicePlan->id);
81+
}
2282
}

tests/TestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
1111
protected static $_client;
1212

1313
private static $webspaces = [];
14+
private static $servicePlans = [];
1415

1516
public static function setUpBeforeClass(): void
1617
{
@@ -41,6 +42,13 @@ public static function tearDownAfterClass(): void
4142
} catch (\Exception $e) {
4243
}
4344
}
45+
46+
foreach (self::$servicePlans as $servicePlan) {
47+
try {
48+
static::$_client->servicePlan()->delete('id', $servicePlan->id);
49+
} catch (\Exception $e) {
50+
}
51+
}
4452
}
4553

4654
/**
@@ -74,4 +82,14 @@ protected static function _createWebspace()
7482

7583
return $webspace;
7684
}
85+
86+
protected static function _createServicePlan()
87+
{
88+
$id = uniqid();
89+
$servicePlan = static::$_client->servicePlan()->create("test{$id}plan");
90+
91+
self::$servicePlans[] = $servicePlan;
92+
93+
return $servicePlan;
94+
}
7795
}

0 commit comments

Comments
 (0)