forked from plesk/api-php-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubdomainTest.php
81 lines (65 loc) · 2.73 KB
/
SubdomainTest.php
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
<?php
// Copyright 1999-2022. Plesk International GmbH.
namespace PleskXTest;
class SubdomainTest extends AbstractTestCase
{
private static \PleskX\Api\Struct\Webspace\Info $webspace;
private static string $webspaceName;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
static::$webspace = static::createWebspace();
$webspaceInfo = static::$client->webspace()->get('id', static::$webspace->id);
static::$webspaceName = $webspaceInfo->name;
}
private function createSubdomain(string $name): \PleskX\Api\Struct\Subdomain\Info
{
return static::$client->subdomain()->create([
'parent' => static::$webspaceName,
'name' => $name,
'property' => [
'www_root' => $name,
],
]);
}
public function testCreate()
{
$subdomain = $this->createSubdomain('sub');
$this->assertIsInt($subdomain->id);
$this->assertGreaterThan(0, $subdomain->id);
static::$client->subdomain()->delete('id', $subdomain->id);
}
public function testDelete()
{
$subdomain = $this->createSubdomain('sub');
$result = static::$client->subdomain()->delete('id', $subdomain->id);
$this->assertTrue($result);
}
public function testGet()
{
$name = 'sub';
$subdomain = $this->createSubdomain($name);
$subdomainInfo = static::$client->subdomain()->get('id', $subdomain->id);
$this->assertEquals($name . '.' . $subdomainInfo->parent, $subdomainInfo->name);
$this->assertTrue(false !== strpos($subdomainInfo->properties['www_root'], $name));
$this->assertEquals($subdomain->id, $subdomainInfo->id);
static::$client->subdomain()->delete('id', $subdomain->id);
}
public function testGetAll()
{
$name = 'sub';
$name2 = 'sub2';
$subdomain = $this->createSubdomain($name);
$subdomain2 = $this->createSubdomain($name2);
$subdomainsInfo = static::$client->subdomain()->getAll();
$this->assertCount(2, $subdomainsInfo);
$this->assertEquals($name . '.' . $subdomainsInfo[0]->parent, $subdomainsInfo[0]->name);
$this->assertTrue(false !== strpos($subdomainsInfo[0]->properties['www_root'], $name));
$this->assertEquals($name2 . '.' . $subdomainsInfo[1]->parent, $subdomainsInfo[1]->name);
$this->assertTrue(false !== strpos($subdomainsInfo[1]->properties['www_root'], $name2));
static::$client->subdomain()->delete('id', $subdomain->id);
static::$client->subdomain()->delete('id', $subdomain2->id);
$subdomainsInfo = static::$client->subdomain()->getAll();
$this->assertEmpty($subdomainsInfo);
}
}