From e16ea186dc56ede237dc06484f45cd0f94f3ffd8 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sun, 28 Oct 2018 13:47:19 +0100 Subject: [PATCH] add some more unit-tests for Cronjobs and PhpSettings Signed-off-by: Michael Kaufmann --- tests/Cronjobs/CronjobsTest.php | 15 +++++++- tests/PhpAndFpm/PhpSettingsTest.php | 54 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/Cronjobs/CronjobsTest.php b/tests/Cronjobs/CronjobsTest.php index 7097f4e8..cc957d7e 100644 --- a/tests/Cronjobs/CronjobsTest.php +++ b/tests/Cronjobs/CronjobsTest.php @@ -17,7 +17,20 @@ class CronjobsTest extends TestCase $this->assertTrue(isset($result['list'][0]['module'])); $this->assertTrue(isset($result['list'][0]['cronfile'])); } - + + public function testCustomerCronjobsListNotAllowed() + { + global $admin_userdata; + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + $this->expectExceptionCode(403); + $this->expectExceptionMessage("Not allowed to execute given command."); + Cronjobs::getLocal($customer_userdata)->listing(); + } + public function testAdminCronjobsAdd() { global $admin_userdata; diff --git a/tests/PhpAndFpm/PhpSettingsTest.php b/tests/PhpAndFpm/PhpSettingsTest.php index 56f1deaf..f8921d08 100644 --- a/tests/PhpAndFpm/PhpSettingsTest.php +++ b/tests/PhpAndFpm/PhpSettingsTest.php @@ -11,6 +11,28 @@ class PhpSettingsText extends TestCase { private static $id = 0; + public function testAdminPhpSettingsList() + { + global $admin_userdata; + $json_result = PhpSettings::getLocal($admin_userdata)->listing(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals("Default Config", $result['list'][0]['description']); + $this->assertEquals("/usr/bin/php-cgi", $result['list'][0]['binary']); + } + + public function testCustomerPhpSettingsListNotAllowed() + { + global $admin_userdata; + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + $this->expectExceptionCode(403); + $this->expectExceptionMessage("Not allowed to execute given command."); + PhpSettings::getLocal($customer_userdata)->listing(); + } + public function testAdminPhpSettingsAdd() { global $admin_userdata; @@ -25,5 +47,37 @@ class PhpSettingsText extends TestCase $this->assertEquals('60s', $result['fpm_reqterm']); self::$id = $result['id']; } + + public function testAdminPhpSettingsGet() + { + global $admin_userdata; + $data = [ + 'id' => self::$id + ]; + $json_result = PhpSettings::getLocal($admin_userdata, $data)->get(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('error_reporting=E_ALL', $result['phpsettings']); + $this->assertEquals('60s', $result['fpm_reqterm']); + } + public function testAdminPhpSettingsGetNotFound() + { + global $admin_userdata; + $this->expectExceptionCode(404); + $this->expectExceptionMessage("php-config with id #999 could not be found"); + PhpSettings::getLocal($admin_userdata, array('id' => 999))->get(); + } + + public function testCustomerPhpSettingsGetNotAllowed() + { + global $admin_userdata; + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + $this->expectExceptionCode(403); + $this->expectExceptionMessage("Not allowed to execute given command."); + PhpSettings::getLocal($customer_userdata, array('id' => 1))->get(); + } }