Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Api/Operator/ServicePlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,27 @@ private function _get($field = null, $value = null)
return $items;
}

/**
* @param string $planName
* @return Struct\Info
*/
public function create($planName)
{
$packet = $this->_client->getPacket();
$info = $packet->addChild($this->_wrapperTag)->addChild('add');
$info->addChild('name', $planName);

$response = $this->_client->request($packet);
return new Struct\Info($response);
}

/**
* @param string $field
* @param integer|string $value
* @return bool
*/
public function delete($field, $value)
{
return $this->_delete($field, $value);
}
}
68 changes: 64 additions & 4 deletions tests/ServicePlanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,76 @@ class ServicePlanTest extends TestCase
{
public function testGet()
{
$servicePlan = static::$_client->servicePlan()->get('name', 'Default Domain');
$this->assertEquals('Default Domain', $servicePlan->name);
$this->assertGreaterThan(0, $servicePlan->id);
$servicePlan = static::_createServicePlan();
$servicePlanInfo = static::$_client->servicePlan()->get('id', $servicePlan->id);
$this->assertNotEmpty($servicePlanInfo->name);
$this->assertSame($servicePlan->id, $servicePlanInfo->id);

static::$_client->servicePlan()->delete('id', $servicePlan->id);
}

public function testGetAll()
{
static::_createServicePlan();
static::_createServicePlan();
static::_createServicePlan();

$servicePlans = static::$_client->servicePlan()->getAll();
$this->assertInternalType('array', $servicePlans);
$this->assertGreaterThan(0, count($servicePlans));
$this->assertGreaterThan(2, count($servicePlans));
$this->assertNotEmpty($servicePlans[0]->name);
}

public function testCreateServicePlan()
{
$servicePlan = static::_createServicePlan();
$this->assertGreaterThan(0, $servicePlan->id);

static::$_client->servicePlan()->delete('id', $servicePlan->id);
}

public function testDelete()
{
$servicePlan = static::_createServicePlan();
$result = static::$_client->servicePlan()->delete('id', $servicePlan->id);

$this->assertTrue($result);
}

public function testRequestCreateServicePlan()
{
$request = [
'add' => [
'name' => 'Service Plan Full Test',
'limits' => [
'overuse' => 'block',
],
'preferences' => [
'stat' => 6,
'maillists' => 'true',
],
'hosting' => [
'property' => [
[
'name' => 'ftp_quota',
'value' => '-1',
],
[
'name' => 'ssl',
'value' => 'true',
],
],
],
'performance' => [
'bandwidth' => 1000,
'max_connections' => 20,
],
],
];

$servicePlan = static::$_client->servicePlan()->request($request);
$this->assertGreaterThan(0, $servicePlan->id);

static::$_client->servicePlan()->delete('id', $servicePlan->id);
}
}
18 changes: 18 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
protected static $_client;

private static $webspaces = [];
private static $servicePlans = [];

public static function setUpBeforeClass()
{
Expand All @@ -36,6 +37,13 @@ public static function tearDownAfterClass()
} catch (\Exception $e) {
}
}

foreach (self::$servicePlans as $servicePlan) {
try {
static::$_client->servicePlan()->delete('id', $servicePlan->id);
} catch (\Exception $e) {
}
}
}

/**
Expand Down Expand Up @@ -67,4 +75,14 @@ protected static function _createWebspace()

return $webspace;
}

protected static function _createServicePlan()
{
$id = uniqid();
$servicePlan = static::$_client->servicePlan()->create("test{$id}plan");

self::$servicePlans[] = $servicePlan;

return $servicePlan;
}
}