@@ -4,8 +4,52 @@ namespace RESTAPI\Tests;
44
55use RESTAPI \Core \TestCase ;
66use RESTAPI \Models \DefaultGateway ;
7+ use RESTAPI \Models \RoutingGateway ;
8+ use RESTAPI \Models \RoutingGatewayGroup ;
79
810class APIModelsDefaultGatewayTestCase extends TestCase {
11+ /**
12+ * @var RoutingGateway $gateway The RoutingGateway object we will use for testing.
13+ */
14+ private RoutingGateway $ gateway ;
15+
16+ /**
17+ * @var RoutingGatewayGroup $gateway_group The RoutingGatewayGroup object we will use for testing.
18+ */
19+ private RoutingGatewayGroup $ gateway_group ;
20+
21+ /**
22+ * Setup the test case by creating a new RoutingGateway and GatewayGroup we can use for testing.
23+ */
24+ public function setup (): void {
25+ # Create a gateway object we can use for testing
26+ $ this ->gateway = new RoutingGateway (
27+ name: 'testgw ' ,
28+ interface: 'wan ' ,
29+ gateway: '1.2.3.4 ' ,
30+ nonlocalgateway: true ,
31+ ipprotocol: 'inet ' ,
32+ );
33+ $ this ->gateway ->create ();
34+
35+ # Create a gateway group object we can use for testing
36+ $ this ->gateway_group = new RoutingGatewayGroup (
37+ name: 'testgwgroup ' ,
38+ trigger: 'down ' ,
39+ descr: 'Test Gateway Group ' ,
40+ priorities: [['gateway ' => $ this ->gateway ->name ->value , 'tier ' => 1 , 'virtual_ip ' => 'address ' ]],
41+ );
42+ $ this ->gateway_group ->create ();
43+ }
44+
45+ /**
46+ * Tear down the test case by deleting the RoutingGateway and GatewayGroup objects we created.
47+ */
48+ public function teardown (): void {
49+ $ this ->gateway_group ->delete ();
50+ $ this ->gateway ->delete ();
51+ }
52+
953 /**
1054 * Ensure we can update the DefaultGateway for both IPv4 and IPv6
1155 */
@@ -17,4 +61,19 @@ class APIModelsDefaultGatewayTestCase extends TestCase {
1761 },
1862 );
1963 }
64+
65+ /**
66+ * Ensure we can assign an existing RoutingGateway or RoutingGatewayGroup as the DefaultGateway
67+ */
68+ public function test_assign_gateway_or_gateway_group (): void {
69+ $ this ->assert_does_not_throw (
70+ callable: function () {
71+ $ default_gw = new DefaultGateway (defaultgw4: $ this ->gateway ->name ->value );
72+ $ default_gw ->validate ();
73+
74+ $ default_gw = new DefaultGateway (defaultgw4: $ this ->gateway_group ->name ->value );
75+ $ default_gw ->validate ();
76+ },
77+ );
78+ }
2079}
0 commit comments