Skip to content

Commit af7a4a4

Browse files
Merge pull request plesk#12 from vbaranovskiy-plesk/master
Add method to add subdomain
2 parents 72836f7 + 2a68ff6 commit af7a4a4

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

src/PleskX/Api/Operator/Subdomain.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,24 @@
22
// Copyright 1999-2016. Parallels IP Holdings GmbH.
33

44
namespace PleskX\Api\Operator;
5+
use PleskX\Api\Struct\Subdomain as Struct;
56

67
class Subdomain extends \PleskX\Api\Operator
78
{
9+
/**
10+
* @param array $properties
11+
* @return Struct\Info
12+
*/
13+
public function create($properties)
14+
{
15+
$packet = $this->_client->getPacket();
16+
$info = $packet->addChild($this->_wrapperTag)->addChild('add');
817

18+
foreach ($properties as $name => $value) {
19+
$info->addChild($name, $value);
20+
}
21+
22+
$response = $this->_client->request($packet);
23+
return new Struct\Info($response);
24+
}
925
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3+
4+
namespace PleskX\Api\Struct\Subdomain;
5+
6+
class Info extends \PleskX\Api\Struct
7+
{
8+
/** @var integer */
9+
public $id;
10+
11+
public function __construct($apiResponse)
12+
{
13+
$this->_initScalarProperties($apiResponse, [
14+
'id',
15+
]);
16+
}
17+
}

tests/SubdomainTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3+
4+
class SubdomainTest extends TestCase
5+
{
6+
7+
/**
8+
* @param string $name
9+
* @return \PleskX\Api\Struct\Webspace\Info
10+
*/
11+
private function _createWebspace($name)
12+
{
13+
return $this->_client->webspace()->create([
14+
'name' => $name,
15+
'ip_address' => $this->_getIpAddress(),
16+
], [
17+
'ftp_login' => 'test-login',
18+
'ftp_password' => 'test-password',
19+
]);
20+
}
21+
22+
/**
23+
* @param string $name
24+
* @param string $webspaceName
25+
* @return \PleskX\Api\Struct\Subdomain\Info
26+
*/
27+
private function _createSubdomain($name, $webspaceName)
28+
{
29+
return $this->_client->subdomain()->create([
30+
'parent' => $webspaceName,
31+
'name' => $name,
32+
]);
33+
}
34+
35+
public function testCreate()
36+
{
37+
$webspaceName = 'example.tld';
38+
$webspace = $this->_createWebspace($webspaceName);
39+
$subdomain = $this->_createSubdomain('sub', $webspaceName);
40+
41+
$this->assertInternalType('integer', $subdomain->id);
42+
$this->assertGreaterThan(0, $subdomain->id);
43+
44+
$this->_client->webspace()->delete('id', $webspace->id);
45+
}
46+
}

0 commit comments

Comments
 (0)