started \Settings\Store unit tests
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -27,44 +27,7 @@ class Store
|
|||||||
$returnvalue = self::storeSettingField($fieldname, $fielddata, $newfieldvalue);
|
$returnvalue = self::storeSettingField($fieldname, $fielddata, $newfieldvalue);
|
||||||
|
|
||||||
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'defaultip') {
|
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'defaultip') {
|
||||||
|
self::updateStdSubdomainDefaultIp($newfieldvalue, $defaultips_old);
|
||||||
$customerstddomains_result_stmt = Database::prepare("
|
|
||||||
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
|
|
||||||
");
|
|
||||||
Database::pexecute($customerstddomains_result_stmt);
|
|
||||||
|
|
||||||
$ids = array();
|
|
||||||
|
|
||||||
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
|
||||||
$ids[] = (int) $customerstddomains_row['standardsubdomain'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($ids) > 0) {
|
|
||||||
$defaultips_new = explode(',', $newfieldvalue);
|
|
||||||
|
|
||||||
// Delete the existing mappings linking to default IPs
|
|
||||||
$del_stmt = Database::prepare("
|
|
||||||
DELETE FROM `" . TABLE_DOMAINTOIP . "`
|
|
||||||
WHERE `id_domain` IN (" . implode(', ', $ids) . ")
|
|
||||||
AND `id_ipandports` IN (" . $defaultips_old . ", " . $newfieldvalue . ")
|
|
||||||
");
|
|
||||||
Database::pexecute($del_stmt);
|
|
||||||
|
|
||||||
// Insert the new mappings
|
|
||||||
$ins_stmt = Database::prepare("
|
|
||||||
INSERT INTO `" . TABLE_DOMAINTOIP . "`
|
|
||||||
SET `id_domain` = :domainid, `id_ipandports` = :ipandportid
|
|
||||||
");
|
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
foreach ($defaultips_new as $defaultip_new) {
|
|
||||||
Database::pexecute($ins_stmt, array(
|
|
||||||
'domainid' => $id,
|
|
||||||
'ipandportid' => $defaultip_new
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnvalue;
|
return $returnvalue;
|
||||||
@@ -77,14 +40,21 @@ class Store
|
|||||||
$returnvalue = self::storeSettingField($fieldname, $fielddata, $newfieldvalue);
|
$returnvalue = self::storeSettingField($fieldname, $fielddata, $newfieldvalue);
|
||||||
|
|
||||||
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'defaultsslip') {
|
if ($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'system' && isset($fielddata['varname']) && $fielddata['varname'] == 'defaultsslip') {
|
||||||
|
self::updateStdSubdomainDefaultIp($newfieldvalue, $defaultips_old);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $returnvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function updateStdSubdomainDefaultIp($newfieldvalue, $defaultips_old)
|
||||||
|
{
|
||||||
|
// update standard-subdomain of customer if exists
|
||||||
$customerstddomains_result_stmt = Database::prepare("
|
$customerstddomains_result_stmt = Database::prepare("
|
||||||
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
|
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
|
||||||
");
|
");
|
||||||
Database::pexecute($customerstddomains_result_stmt);
|
Database::pexecute($customerstddomains_result_stmt);
|
||||||
|
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
|
||||||
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
$ids[] = (int) $customerstddomains_row['standardsubdomain'];
|
$ids[] = (int) $customerstddomains_row['standardsubdomain'];
|
||||||
}
|
}
|
||||||
@@ -127,9 +97,6 @@ class Store
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnvalue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates the setting for the default panel-theme
|
* updates the setting for the default panel-theme
|
||||||
* and also the user themes (customers and admins) if
|
* and also the user themes (customers and admins) if
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ class CustomersTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @depends testAdminCustomersAdd
|
* @depends testAdminCustomerUpdateDeactivate
|
||||||
*/
|
*/
|
||||||
public function testCustomerCustomersGetWhenDeactivated()
|
public function testCustomerCustomersGetWhenDeactivated()
|
||||||
{
|
{
|
||||||
@@ -252,7 +252,7 @@ class CustomersTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @depends testAdminCustomersAdd
|
* @depends testCustomerCustomersGetWhenDeactivated
|
||||||
*/
|
*/
|
||||||
public function testCustomerCustomersUpdate()
|
public function testCustomerCustomersUpdate()
|
||||||
{
|
{
|
||||||
|
|||||||
97
tests/Froxlor/StoreTest.php
Normal file
97
tests/Froxlor/StoreTest.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Froxlor\Settings;
|
||||||
|
use Froxlor\Api\Commands\Customers;
|
||||||
|
use Froxlor\Database\Database;
|
||||||
|
use Froxlor\Settings\Store;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @covers \Froxlor\Settings\Store
|
||||||
|
*/
|
||||||
|
class StoreTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testStoreSettingClearCertificates()
|
||||||
|
{
|
||||||
|
// when froxlor vhost setting "use lets encrypt" is set to false, the corresponding
|
||||||
|
// certificate needs to be cleaned
|
||||||
|
// for testing purposes, let's add some entry to the table
|
||||||
|
Database::query("INSERT INTO `domain_ssl_settings` SET `domainid` = '0', `ssl_cert_file` = 'test-content'");
|
||||||
|
|
||||||
|
$fielddata = array(
|
||||||
|
'label' => 'le_froxlor_enabled',
|
||||||
|
'settinggroup' => 'system',
|
||||||
|
'varname' => 'le_froxlor_enabled'
|
||||||
|
);
|
||||||
|
Store::storeSettingClearCertificates('system_le_froxlor_enabled', $fielddata, 0);
|
||||||
|
|
||||||
|
// there should be no entry in domain_ssl_settings now
|
||||||
|
$result = Database::query("SELECT COUNT(*) as entries FROM `domain_ssl_settings` WHERE `domainid` = '0'");
|
||||||
|
$result = $result->fetch(\PDO::FETCH_ASSOC);
|
||||||
|
$this->assertEquals(0, (int) $result['entries']);
|
||||||
|
|
||||||
|
// truncate the table for other tests
|
||||||
|
Database::query("TRUNCATE TABLE `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "`;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStoreSettingDefaultIp()
|
||||||
|
{
|
||||||
|
global $admin_userdata;
|
||||||
|
|
||||||
|
// the customer should have a std-subdomin
|
||||||
|
Customers::getLocal($admin_userdata, array(
|
||||||
|
'id' => 1,
|
||||||
|
'createstdsubdomain' => 1
|
||||||
|
))->update();
|
||||||
|
|
||||||
|
// we need a second non-ssl IP
|
||||||
|
Database::query("INSERT INTO `panel_ipsandports` SET `ip` = '82.149.225.47', `port` = '80'");
|
||||||
|
$ip_id = Database::lastInsertId();
|
||||||
|
$default_ip = Settings::Get('system.defaultip');
|
||||||
|
|
||||||
|
// get all std-subdomains
|
||||||
|
$customerstddomains_result_stmt = Database::prepare("
|
||||||
|
SELECT `standardsubdomain` FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE `standardsubdomain` <> '0'
|
||||||
|
");
|
||||||
|
Database::pexecute($customerstddomains_result_stmt);
|
||||||
|
|
||||||
|
$ids = array();
|
||||||
|
while ($customerstddomains_row = $customerstddomains_result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
$ids[] = (int) $customerstddomains_row['standardsubdomain'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($ids) <= 0) {
|
||||||
|
$this->fail("There should be customer std-subdomains for this test to make sense");
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that they have the current default IP set
|
||||||
|
$sel_stmt = Database::prepare("
|
||||||
|
SELECT * FROM `" . TABLE_DOMAINTOIP . "`
|
||||||
|
WHERE `id_domain` IN (" . implode(', ', $ids) . ") AND `id_ipandports` = :ipid
|
||||||
|
");
|
||||||
|
Database::pexecute($sel_stmt, array('ipid' => $default_ip));
|
||||||
|
$current_result = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
// we assume there are entries
|
||||||
|
$this->assertTrue(count($current_result) > 0);
|
||||||
|
|
||||||
|
$fielddata = array(
|
||||||
|
'label' => 'serversettingsipaddress',
|
||||||
|
'settinggroup' => 'system',
|
||||||
|
'varname' => 'defaultip'
|
||||||
|
);
|
||||||
|
Store::storeSettingDefaultIp('serversettings_ipaddress', $fielddata, $ip_id);
|
||||||
|
|
||||||
|
// check that they do not have the current default IP set anymore
|
||||||
|
Database::pexecute($sel_stmt, array('ipid' => $default_ip));
|
||||||
|
$current_result = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
// we assume there are entries
|
||||||
|
$this->assertTrue(count($current_result) == 0);
|
||||||
|
|
||||||
|
// check that they have the new default IP set
|
||||||
|
Database::pexecute($sel_stmt, array('ipid' => $ip_id));
|
||||||
|
$current_result = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
// we assume there are entries
|
||||||
|
$this->assertTrue(count($current_result) > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user