33namespace LKDev \Tests \Unit \Models \Zones ;
44
55use GuzzleHttp \Psr7 \Response ;
6+ use LKDev \HetznerCloud \Models \Zones \PrimaryNameserver ;
67use LKDev \HetznerCloud \Models \Zones \Zone ;
78use LKDev \HetznerCloud \Models \Zones \Zones ;
89use LKDev \Tests \TestCase ;
@@ -19,7 +20,7 @@ public function setUp(): void
1920 parent ::setUp ();
2021 $ tmp = new Zones ($ this ->hetznerApi ->getHttpClient ());
2122
22- $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone.json ' )));
23+ $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone.json ' )));
2324 $ this ->zone = $ tmp ->getById (4711 );
2425 }
2526
@@ -36,15 +37,15 @@ public function testDelete()
3637
3738 public function testUpdate ()
3839 {
39- $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone.json ' )));
40+ $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone.json ' )));
4041 $ this ->zone ->update (['name ' => 'new-name ' ]);
4142 $ this ->assertLastRequestEquals ('PUT ' , '/zones/4711 ' );
4243 $ this ->assertLastRequestBodyParametersEqual (['name ' => 'new-name ' ]);
4344 }
4445
4546 public function testChangeProtection ()
4647 {
47- $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone_action_change_protection.json ' )));
48+ $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone_action_change_protection.json ' )));
4849 $ apiResponse = $ this ->zone ->changeProtection (true );
4950 $ this ->assertEquals ('change_protection ' , $ apiResponse ->action ->command );
5051 $ this ->assertEquals ($ this ->zone ->id , $ apiResponse ->action ->resources [0 ]->id );
@@ -53,8 +54,52 @@ public function testChangeProtection()
5354 $ this ->assertLastRequestBodyParametersEqual (['delete ' => true ]);
5455 }
5556
57+ public function testChangeTTL ()
58+ {
59+ $ this ->mockHandler ->append (new Response (200 , [], $ this ->getGenericActionResponse ('change_ttl ' )));
60+ $ apiResponse = $ this ->zone ->changeTTL (50 );
61+ $ this ->assertEquals ('change_ttl ' , $ apiResponse ->action ->command );
62+ $ this ->assertEquals ($ this ->zone ->id , $ apiResponse ->action ->resources [0 ]->id );
63+ $ this ->assertEquals ('zone ' , $ apiResponse ->action ->resources [0 ]->type );
64+ $ this ->assertLastRequestEquals ('POST ' , '/zones/4711/actions/change_ttl ' );
65+ $ this ->assertLastRequestBodyParametersEqual (['ttl ' => 50 ]);
66+ }
67+
68+ public function testImportZonefile ()
69+ {
70+ $ this ->mockHandler ->append (new Response (200 , [], $ this ->getGenericActionResponse ('import_zonefile ' )));
71+ $ apiResponse = $ this ->zone ->importZonefile ("zonefile_content " );
72+ $ this ->assertEquals ('import_zonefile ' , $ apiResponse ->action ->command );
73+ $ this ->assertEquals ($ this ->zone ->id , $ apiResponse ->action ->resources [0 ]->id );
74+ $ this ->assertEquals ('zone ' , $ apiResponse ->action ->resources [0 ]->type );
75+ $ this ->assertLastRequestEquals ('POST ' , '/zones/4711/actions/import_zonefile ' );
76+ $ this ->assertLastRequestBodyParametersEqual (['zonefile ' => "zonefile_content " ]);
77+ }
78+
79+ public function testTestChangePrimaryNameservers ()
80+ {
81+ $ this ->mockHandler ->append (new Response (200 , [], $ this ->getGenericActionResponse ('import_zonefile ' )));
82+ $ apiResponse = $ this ->zone ->changePrimaryNameservers ([
83+ new PrimaryNameserver ("192.168.178.1 " , 53 )
84+ ]);
85+ $ this ->assertEquals ('import_zonefile ' , $ apiResponse ->action ->command );
86+ $ this ->assertEquals ($ this ->zone ->id , $ apiResponse ->action ->resources [0 ]->id );
87+ $ this ->assertEquals ('zone ' , $ apiResponse ->action ->resources [0 ]->type );
88+ $ this ->assertLastRequestEquals ('POST ' , '/zones/4711/actions/change_primary_nameservers ' );
89+ $ this ->assertLastRequestBodyParametersEqual (['primary_nameservers ' => [["address " => "192.168.178.1 " , "port " => 53 ]]]);
90+ }
91+
92+
93+ public function testExportZonefile ()
94+ {
95+ $ this ->mockHandler ->append (new Response (200 , [], file_get_contents (__DIR__ . '/fixtures/zone_zonefile.json ' )));
96+ $ apiResponse = $ this ->zone ->exportZonefile ();
97+ $ this ->assertNotEmpty ($ apiResponse ->zonefile );
98+ $ this ->assertLastRequestEquals ('GET ' , '/zones/4711/zonefile ' );
99+ }
100+
56101 protected function getGenericActionResponse (string $ command )
57102 {
58- return str_replace ('$command ' , $ command , file_get_contents (__DIR__ . '/fixtures/zone_action_generic.json ' ));
103+ return str_replace ('$command ' , $ command , file_get_contents (__DIR__ . '/fixtures/zone_action_generic.json ' ));
59104 }
60105}
0 commit comments