add possibility to add customer using a hosting-plan instead of specifying resources

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-09-27 12:54:43 +02:00
parent eabad4917b
commit cc04e44031
2 changed files with 105 additions and 30 deletions

View File

@@ -12,6 +12,7 @@ use Froxlor\Api\Commands\HostingPlans;
* @covers \Froxlor\Api\ApiCommand
* @covers \Froxlor\Api\ApiParameter
* @covers \Froxlor\Api\Commands\HostingPlans
* @covers \Froxlor\Api\Commands\Customers
*/
class HostingPlansTest extends TestCase
{
@@ -65,7 +66,7 @@ class HostingPlansTest extends TestCase
$this->expectExceptionMessage('Requested parameter "name" could not be found for "HostingPlans:add"');
HostingPlans::getLocal($admin_userdata, $data)->add();
$data['name'] = null;
$this->expectExceptionMessage('Requested parameter "name" is empty where it should not be for "HostingPlans:add"');
HostingPlans::getLocal($admin_userdata, $data)->add();
@@ -120,7 +121,7 @@ class HostingPlansTest extends TestCase
$json_result = HostingPlans::getLocal($customer_userdata)->listing();
}
public function testCustomerPlanAdd()
{
global $admin_userdata;
@@ -129,10 +130,10 @@ class HostingPlansTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
$json_result = HostingPlans::getLocal($customer_userdata)->add();
}
@@ -144,13 +145,13 @@ class HostingPlansTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
$json_result = HostingPlans::getLocal($customer_userdata)->get();
}
public function testCustomerPlanUpdate()
{
global $admin_userdata;
@@ -159,10 +160,10 @@ class HostingPlansTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
$json_result = HostingPlans::getLocal($customer_userdata)->update();
}
@@ -174,10 +175,10 @@ class HostingPlansTest extends TestCase
'id' => 1
))->get();
$customer_userdata = json_decode($json_result, true)['data'];
$this->expectExceptionCode(403);
$this->expectExceptionMessage("Not allowed to execute given command.");
$json_result = HostingPlans::getLocal($customer_userdata)->delete();
}
@@ -255,4 +256,48 @@ class HostingPlansTest extends TestCase
$result = json_decode($json_result, true)['data'];
$this->assertEquals('test2', $result['name']);
}
/**
*
* @depends testAdminPlanAdd
*/
public function testAdminCustomersAddWithHostingPlan()
{
global $admin_userdata;
$json_result = HostingPlans::getLocal($admin_userdata, array(
'planname' => 'test'
))->get();
$result = json_decode($json_result, true)['data'];
$data = [
'new_loginname' => 'test1hp',
'email' => 'team@froxlor.org',
'firstname' => 'Test',
'name' => 'Testman',
'customernumber' => 1337,
'createstdsubdomain' => 0,
'new_customer_password' => 'h0lYmo1y',
'sendpassword' => TRAVIS_CI == 1 ? 0 : 1,
'store_defaultindex' => 1,
'custom_notes' => 'secret',
'custom_notes_show' => 0,
'gender' => 5,
'hosting_plan_id' => $result['id']
];
$json_result = Customers::getLocal($admin_userdata, $data)->add();
$result = json_decode($json_result, true)['data'];
$this->assertEquals(- 1024, $result['diskspace']);
$this->assertEquals(15, $result['subdomains']);
$this->assertEquals(1, $result['phpenabled']);
$this->assertJsonStringEqualsJsonString(json_encode([
1
]), $result['allowed_phpconfigs']);
// remove customer
Customers::getLocal($admin_userdata, array(
'loginname' => 'test1hp'
))->delete();
}
}