File tree 3 files changed +134
-0
lines changed
3 files changed +134
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Cloudflare \API \Endpoints ;
4
+
5
+ use Cloudflare \API \Adapter \Adapter ;
6
+ use Cloudflare \API \Traits \BodyAccessorTrait ;
7
+ use stdClass ;
8
+
9
+ class AccountRoles implements API
10
+ {
11
+ use BodyAccessorTrait;
12
+
13
+ /**
14
+ * @var Adapter
15
+ */
16
+ private $ adapter ;
17
+
18
+ public function __construct (Adapter $ adapter )
19
+ {
20
+ $ this ->adapter = $ adapter ;
21
+ }
22
+
23
+ public function listAccountRoles (string $ accountId ): stdClass
24
+ {
25
+ $ roles = $ this ->adapter ->get ('accounts/ ' . $ accountId . '/roles ' );
26
+ $ this ->body = json_decode ($ roles ->getBody ());
27
+
28
+ return (object )[
29
+ 'result ' => $ this ->body ->result ,
30
+ 'result_info ' => $ this ->body ->result_info ,
31
+ ];
32
+ }
33
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Endpoints ;
4
+
5
+ use Cloudflare \API \Adapter \Adapter ;
6
+ use Cloudflare \API \Endpoints \AccountRoles ;
7
+ use TestCase ;
8
+
9
+ class AccountRolesTest extends TestCase
10
+ {
11
+ public function testListAccountRoles ()
12
+ {
13
+ $ response = $ this ->getPsr7JsonResponseForFixture ('Endpoints/listAccountRoles.json ' );
14
+
15
+ $ adapter = $ this ->getMockBuilder (Adapter::class)->getMock ();
16
+ $ adapter ->method ('get ' )->willReturn ($ response );
17
+
18
+ $ adapter ->expects ($ this ->once ())
19
+ ->method ('get ' )
20
+ ->with ($ this ->equalTo ('accounts/023e105f4ecef8ad9ca31a8372d0c353/roles ' ));
21
+
22
+ $ roles = new AccountRoles ($ adapter );
23
+ $ result = $ roles ->listAccountRoles ('023e105f4ecef8ad9ca31a8372d0c353 ' );
24
+
25
+ $ this ->assertObjectHasAttribute ('result ' , $ result );
26
+ $ this ->assertObjectHasAttribute ('result_info ' , $ result );
27
+
28
+ $ this ->assertEquals ('3536bcfad5faccb999b47003c79917fb ' , $ result ->result [0 ]->id );
29
+ $ this ->assertEquals (1 , $ result ->result_info ->page );
30
+ $ this ->assertEquals ('3536bcfad5faccb999b47003c79917fb ' , $ roles ->getBody ()->result [0 ]->id );
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "success" : true ,
3
+ "errors" : [],
4
+ "messages" : [],
5
+ "result" : [
6
+ {
7
+ "id" : " 3536bcfad5faccb999b47003c79917fb" ,
8
+ "name" : " Account Administrator" ,
9
+ "description" : " Administrative access to the entire Account" ,
10
+ "permissions" : {
11
+ "analytics" : {
12
+ "read" : true ,
13
+ "write" : true
14
+ },
15
+ "billing" : {
16
+ "read" : true ,
17
+ "write" : true
18
+ },
19
+ "cache_purge" : {
20
+ "read" : true ,
21
+ "write" : true
22
+ },
23
+ "dns" : {
24
+ "read" : true ,
25
+ "write" : true
26
+ },
27
+ "dns_records" : {
28
+ "read" : true ,
29
+ "write" : true
30
+ },
31
+ "lb" : {
32
+ "read" : true ,
33
+ "write" : true
34
+ },
35
+ "logs" : {
36
+ "read" : true ,
37
+ "write" : true
38
+ },
39
+ "organization" : {
40
+ "read" : true ,
41
+ "write" : true
42
+ },
43
+ "ssl" : {
44
+ "read" : true ,
45
+ "write" : true
46
+ },
47
+ "waf" : {
48
+ "read" : true ,
49
+ "write" : true
50
+ },
51
+ "zones" : {
52
+ "read" : true ,
53
+ "write" : true
54
+ },
55
+ "zone_settings" : {
56
+ "read" : true ,
57
+ "write" : true
58
+ }
59
+ }
60
+ }
61
+ ],
62
+ "result_info" : {
63
+ "page" : 1 ,
64
+ "per_page" : 1 ,
65
+ "total_pages" : 1 ,
66
+ "count" : 1 ,
67
+ "total_count" : 1
68
+ }
69
+ }
You can’t perform that action at this time.
0 commit comments