Skip to content

Commit d8bcfad

Browse files
author
Alexandr Bashurov
committed
Move out license checks into a separate class
1 parent 5fd061d commit d8bcfad

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

tests/Utility/KeyLimitChecker.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace PleskXTest\Utility;
4+
5+
class KeyLimitChecker
6+
{
7+
const LIMIT_CLIENTS = 'limit_clients';
8+
const LIMIT_RESELLERS = 'limit_resellers';
9+
const LIMIT_DOMAINS = 'limit_domains';
10+
11+
/**
12+
* Checks whether limit is within the required constraint
13+
*
14+
* @param (string|int)[] $keyInfo Structure returned by the getKeyInfo call
15+
* @param string $type Type of the object that should be checked
16+
* @param int $minimalRequirement Minimal value that should satisfy the limit
17+
* @return bool if license satisfies set limits
18+
*/
19+
public static function checkByType(array $keyInfo, $type, $minimalRequirement)
20+
{
21+
$field = null;
22+
switch ($type) {
23+
case self::LIMIT_CLIENTS:
24+
if (intval($keyInfo['can-manage-customers']) === 0) {
25+
return false;
26+
}
27+
$field = 'lim_cl';
28+
break;
29+
case self::LIMIT_RESELLERS:
30+
if (intval($keyInfo['can-manage-resellers']) === 0) {
31+
return false;
32+
}
33+
$field = 'lim_cl';
34+
break;
35+
case self::LIMIT_DOMAINS:
36+
$field = 'lim_dom';
37+
break;
38+
default:
39+
return false;
40+
}
41+
return intval($keyInfo[$field]) === -1 || intval($keyInfo[$field]) > $minimalRequirement;
42+
}
43+
}

tests/WebspaceTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright 1999-2019. Plesk International GmbH.
33
namespace PleskXTest;
44

5+
use PleskXTest\Utility\PasswordProvider;
6+
57
class WebspaceTest extends TestCase
68
{
79
public function testGetPermissionDescriptor()
@@ -96,7 +98,7 @@ public function testRequestCreateWebspace()
9698
],
9799
[
98100
'name' => 'ftp_password',
99-
'value' => 'test-PWD*1',
101+
'value' => PasswordProvider::STRONG_PASSWORD,
100102
],
101103
],
102104
'ip_address' => static::_getIpAddress(),

0 commit comments

Comments
 (0)