-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathProtectedDirectoryTest.php
91 lines (69 loc) · 2.89 KB
/
ProtectedDirectoryTest.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
82
83
84
85
86
87
88
89
90
91
<?php
// Copyright 1999-2025. WebPros International GmbH.
namespace PleskXTest;
use PleskXTest\Utility\PasswordProvider;
class ProtectedDirectoryTest extends AbstractTestCase
{
private static \PleskX\Api\Struct\Webspace\Info $webspace;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
static::$webspace = static::createWebspace();
}
public function testAdd()
{
$protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
$this->assertIsObject($protectedDirectory);
$this->assertGreaterThan(0, $protectedDirectory->id);
static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
}
public function testAddInvalidDirectory()
{
$this->expectException(\PleskX\Api\Exception::class);
$this->expectExceptionCode(1019);
static::$client->protectedDirectory()->add('', static::$webspace->id);
}
public function testDelete()
{
$protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
$result = static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
$this->assertTrue($result);
}
public function testGetById()
{
$protectedDirectory = static::$client->protectedDirectory()->add('test', static::$webspace->id);
$foundDirectory = static::$client->protectedDirectory()->get('id', $protectedDirectory->id);
$this->assertEquals('test', $foundDirectory->name);
static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
}
public function testGetUnknownDirectory()
{
$this->expectException(\PleskX\Api\Exception::class);
$this->expectExceptionCode(1013);
$nonExistentDirectoryId = 99999999;
static::$client->protectedDirectory()->get('id', $nonExistentDirectoryId);
}
public function testAddUser()
{
$protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
$user = static::$client->protectedDirectory()->addUser(
$protectedDirectory,
'john',
PasswordProvider::STRONG_PASSWORD
);
$this->assertGreaterThan(0, $user->id);
static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
}
public function testDeleteUser()
{
$protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
$user = static::$client->protectedDirectory()->addUser(
$protectedDirectory,
'john',
PasswordProvider::STRONG_PASSWORD
);
$result = static::$client->protectedDirectory()->deleteUser('id', $user->id);
$this->assertTrue($result);
static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
}
}