Skip to content

Commit 6e3258c

Browse files
tests: ensure fields with a choices_callable method have access to it #681
1 parent db7f07e commit 6e3258c

2 files changed

Lines changed: 162 additions & 150 deletions

File tree

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/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
}

0 commit comments

Comments
 (0)