Skip to content

Commit 73a36a9

Browse files
Merge pull request #683 from jaredhendrickson13/next_patch
v2.4.2 Fixes
2 parents e56d961 + 8fadb4a commit 73a36a9

File tree

4 files changed

+174
-151
lines changed

4 files changed

+174
-151
lines changed

composer.lock

Lines changed: 140 additions & 150 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DNSResolverSettings.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class DNSResolverSettings extends Model {
149149
* Obtains all available Python module options.
150150
* @return array The available Python module options.
151151
*/
152-
protected function get_python_script_options(): array {
152+
public function get_python_script_options(): array {
153153
# Use glob to obtain all .py files in /var/unbound/
154154
$files = glob('/var/unbound/*.py');
155155

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APICoreModelTestCase.inc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,4 +1267,26 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
12671267
$this->assert_is_true(method_exists($model_obj, $model_obj->internal_callable));
12681268
}
12691269
}
1270+
1271+
/**
1272+
* Checks that all Model class fields with a 'choices_callable' assigned have an existing callable assigned.
1273+
*/
1274+
public function test_model_field_choices_callables_exist(): void {
1275+
# Loop through all Model classes
1276+
foreach (Model::get_all_model_classes() as $model_class) {
1277+
# Create a new instance of the Model class
1278+
$model_obj = new $model_class(skip_init: true);
1279+
1280+
# Loop through all the fields in the Model class
1281+
foreach ($model_obj->get_fields() as $field) {
1282+
# Skip fields that don't have a choices callable assigned
1283+
if (!$field->choices_callable) {
1284+
continue;
1285+
}
1286+
1287+
# Ensure the choices callable exists
1288+
$this->assert_is_true(method_exists($model_obj, $field->choices_callable));
1289+
}
1290+
}
1291+
}
12701292
}

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDNSResolverSettingsTestCase.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,15 @@ class APIModelsDNSResolverSettingsTestCase extends TestCase {
7474
$unbound_config = file_get_contents('/var/unbound/unbound.conf');
7575
$this->assert_str_contains($unbound_config, 'test: test');
7676
}
77+
78+
/**
79+
* Checks that the `get_python_script_options` method correctly retrieves the available Python scripts.
80+
*/
81+
public function test_get_python_script_options(): void {
82+
# Add a mock script to /var/unbound/ to populate an option
83+
touch('/var/unbound/test_option1.py');
84+
$settings = new DNSResolverSettings(async: false);
85+
$this->assert_equals($settings->get_python_script_options(), ['test_option1']);
86+
unlink('/var/unbound/test_option1.py');
87+
}
7788
}

0 commit comments

Comments
 (0)