Fix bug in DbLayer, add tests to test.php