diff --git a/e107 b/e107 index e92c6789c..840859a32 160000 --- a/e107 +++ b/e107 @@ -1 +1 @@ -Subproject commit e92c6789c51c9b653153efe555d1ded9ffbff49f +Subproject commit 840859a32f5e7c6d579f1b643e99ed30d30d1fd7 diff --git a/lib/deployers/cpanel_deployer.php b/lib/deployers/cpanel_deployer.php index a851fa087..2cb6f6924 100644 --- a/lib/deployers/cpanel_deployer.php +++ b/lib/deployers/cpanel_deployer.php @@ -289,11 +289,13 @@ class cPanelDeployer private static function prune_mysql_databases($dbs, $ids, $cPanel) { + $prefix = $cPanel->user."_".self::TEST_PREFIX; foreach ($dbs as $db) { $db = (array) $db; - $offset = strpos($db['db'], self::TEST_PREFIX); - $questionable_db = substr($db['db'], $offset); + if (substr($db['db'], 0, strlen($prefix)) !== $prefix) + continue; + $questionable_db = substr($db['db'], strlen($prefix)); if (!in_array($questionable_db, $ids)) { self::println("Deleting expired MySQL database \"".$db['db']."\"…"); @@ -304,11 +306,13 @@ class cPanelDeployer private static function prune_mysql_users($users, $ids, $cPanel) { + $prefix = $cPanel->user."_".self::TEST_PREFIX; foreach ($users as $user) { $user = (array) $user; - $offset = strpos($user['user'], self::TEST_PREFIX); - $questionable_user = substr($user['user'], $offset); + if (substr($user['user'], 0, strlen($prefix)) !== $prefix) + continue; + $questionable_user = substr($user['user'], strlen($prefix)); if (!in_array($questionable_user, $ids)) { self::println("Deleting expired MySQL user \"".$user['user']."\"…"); diff --git a/tests/unit/TreeModelTest.php b/tests/unit/TreeModelTest.php index 270f95aa5..14ba1dfcc 100644 --- a/tests/unit/TreeModelTest.php +++ b/tests/unit/TreeModelTest.php @@ -122,6 +122,76 @@ class TreeModelTest extends \Codeception\Test\Unit $this->assertEquals('163', $tree_model->getParam('db_limit_count')); $this->assertEquals('79', $tree_model->getParam('db_limit_offset')); } + + public function testMultiFieldCompareWithSortFieldsReturnsExpectedValues() + { + $tree_model = $this->make('e_tree_model'); + $class = new \ReflectionClass(get_class($tree_model)); + $method = $class->getMethod('multiFieldCmp'); + $method->setAccessible(true); + + $row1 = array( + 'field1' => '0', + 'field2' => '-1', + ); + $row2 = array( + 'field1' => '0', + 'field2' => '1', + ); + $sort_fields = ['field1', 'field2']; + + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(-1, $result); + + $row1['field2'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(0, $result); + + $row1['field2'] = 2; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(1, $result); + + $row1['field1'] = -1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(-1, $result); + + $row1['field1'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_fields, 1); + $this->assertEquals(1, $result); + } + + public function testMultiFieldCompareWithSortFieldReturnsExpectedValues() + { + $tree_model = $this->make('e_tree_model'); + $class = new \ReflectionClass(get_class($tree_model)); + $method = $class->getMethod('multiFieldCmp'); + $method->setAccessible(true); + + $row1 = array( + 'field1' => '0', + 'field2' => '-1', + ); + $row2 = array( + 'field1' => '0', + 'field2' => '1', + ); + $sort_field = 'field1'; + + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(0, $result); + + $row1['field1'] = -1; + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(-1, $result); + + $row1['field1'] = 1; + $result = $method->invoke(null, $row1, $row2, $sort_field, 1); + $this->assertEquals(1, $result); + + $row1['field2'] = 1337; + $this->assertEquals(1, $result); + } + protected $sample_rows = array ( 1 =>