Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 140 additions & 150 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class DNSResolverSettings extends Model {
* Obtains all available Python module options.
* @return array The available Python module options.
*/
protected function get_python_script_options(): array {
public function get_python_script_options(): array {
# Use glob to obtain all .py files in /var/unbound/
$files = glob('/var/unbound/*.py');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1267,4 +1267,26 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
$this->assert_is_true(method_exists($model_obj, $model_obj->internal_callable));
}
}

/**
* Checks that all Model class fields with a 'choices_callable' assigned have an existing callable assigned.
*/
public function test_model_field_choices_callables_exist(): void {
# Loop through all Model classes
foreach (Model::get_all_model_classes() as $model_class) {
# Create a new instance of the Model class
$model_obj = new $model_class(skip_init: true);

# Loop through all the fields in the Model class
foreach ($model_obj->get_fields() as $field) {
# Skip fields that don't have a choices callable assigned
if (!$field->choices_callable) {
continue;
}

# Ensure the choices callable exists
$this->assert_is_true(method_exists($model_obj, $field->choices_callable));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ class APIModelsDNSResolverSettingsTestCase extends TestCase {
$unbound_config = file_get_contents('/var/unbound/unbound.conf');
$this->assert_str_contains($unbound_config, 'test: test');
}

/**
* Checks that the `get_python_script_options` method correctly retrieves the available Python scripts.
*/
public function test_get_python_script_options(): void {
# Add a mock script to /var/unbound/ to populate an option
touch('/var/unbound/test_option1.py');
$settings = new DNSResolverSettings(async: false);
$this->assert_equals($settings->get_python_script_options(), ['test_option1']);
unlink('/var/unbound/test_option1.py');
}
}