Passed
Push — master ( 3c32e6...6d1be7 )
by Adam
02:49
created

OrganizationsTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 101
dl 0
loc 178
rs 10
c 0
b 0
f 0
wmc 15

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testChangeOwner() 0 14 1
A testGetOrganizations() 0 18 3
A testLeaveOrganization() 0 11 1
A testCreateOrganizationAdminInvite() 0 12 1
A testGetOrganizationTeams() 0 17 3
A testGetOrganizationInvitees() 0 18 3
A testGetOrganizationApplications() 0 17 3
1
<?php
2
3
namespace AcquiaCloudApi\Tests\Endpoints;
4
5
use AcquiaCloudApi\Tests\CloudApiTestCase;
6
use AcquiaCloudApi\Endpoints\Organizations;
7
8
class OrganizationsTest extends CloudApiTestCase
9
{
10
11
    public $organizationProperties = [
12
        'id',
13
        'uuid',
14
        'name',
15
        'owner',
16
        'subscriptions_total',
17
        'admins_total',
18
        'users_total',
19
        'teams_total',
20
        'roles_total',
21
        'links'
22
    ];
23
24
    public $invitationProperties = [
25
        'uuid',
26
        'email',
27
        'author',
28
        'applications',
29
        'organization',
30
        'roles',
31
        'team',
32
        'created_at',
33
        'token',
34
        'flags',
35
        'links'
36
    ];
37
38
    protected $applicationProperties = [
39
        'uuid',
40
        'name',
41
        'hosting',
42
        'subscription',
43
        'organization',
44
        'type',
45
        'flags',
46
        'status',
47
        'links'
48
    ];
49
50
    protected $teamProperties = [
51
        'uuid',
52
        'name',
53
        'created_at',
54
        'updated_at',
55
        'organization',
56
        'links'
57
    ];
58
59
    public function testGetOrganizations()
60
    {
61
62
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Organizations/getAllOrganizations.json');
63
        $client = $this->getMockClient($response);
64
65
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
66
        $organization = new Organizations($client);
67
        $result = $organization->getAll();
68
69
        $this->assertInstanceOf('\ArrayObject', $result);
70
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OrganizationsResponse', $result);
71
72
        foreach ($result as $record) {
73
            $this->assertInstanceOf('\AcquiaCloudApi\Response\OrganizationResponse', $record);
74
75
            foreach ($this->organizationProperties as $property) {
76
                $this->assertObjectHasAttribute($property, $record);
77
            }
78
        }
79
    }
80
81
    public function testCreateOrganizationAdminInvite()
82
    {
83
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Organizations/inviteAdmin.json');
84
        $client = $this->getMockClient($response);
85
86
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
87
        $organization = new Organizations($client);
88
        $result = $organization->inviteAdmin('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', '[email protected]');
89
90
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
91
92
        $this->assertEquals('Invited organization administrator.', $result->message);
93
    }
94
95
    public function testGetOrganizationApplications()
96
    {
97
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Organizations/getApplications.json');
98
        $client = $this->getMockClient($response);
99
100
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
101
        $organization = new Organizations($client);
102
        $result = $organization->getApplications('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
103
104
        $this->assertInstanceOf('\ArrayObject', $result);
105
        $this->assertInstanceOf('\AcquiaCloudApi\Response\ApplicationsResponse', $result);
106
107
        foreach ($result as $record) {
108
            $this->assertInstanceOf('\AcquiaCloudApi\Response\ApplicationResponse', $record);
109
110
            foreach ($this->applicationProperties as $property) {
111
                $this->assertObjectHasAttribute($property, $record);
112
            }
113
        }
114
    }
115
116
    public function testGetOrganizationTeams()
117
    {
118
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Organizations/getTeams.json');
119
        $client = $this->getMockClient($response);
120
121
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
122
        $organization = new Organizations($client);
123
        $result = $organization->getTeams('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
124
125
        $this->assertInstanceOf('\ArrayObject', $result);
126
        $this->assertInstanceOf('\AcquiaCloudApi\Response\TeamsResponse', $result);
127
128
        foreach ($result as $record) {
129
            $this->assertInstanceOf('\AcquiaCloudApi\Response\TeamResponse', $record);
130
131
            foreach ($this->teamProperties as $property) {
132
                $this->assertObjectHasAttribute($property, $record);
133
            }
134
        }
135
    }
136
137
    public function testGetOrganizationInvitees()
138
    {
139
140
        $response = $this->getPsr7JsonResponseForFixture('Endpoints/Organizations/getMemberInvites.json');
141
        $client = $this->getMockClient($response);
142
143
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
144
        $organization = new Organizations($client);
145
        $result = $organization->getMemberInvitations('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
146
147
        $this->assertInstanceOf('\ArrayObject', $result);
148
        $this->assertInstanceOf('\AcquiaCloudApi\Response\InvitationsResponse', $result);
149
150
        foreach ($result as $record) {
151
            $this->assertInstanceOf('\AcquiaCloudApi\Response\InvitationResponse', $record);
152
153
            foreach ($this->invitationProperties as $property) {
154
                $this->assertObjectHasAttribute($property, $record);
155
            }
156
        }
157
    }
158
159
    public function testLeaveOrganization()
160
    {
161
        $response = $this->getPsr7GzipResponseForFixture('Endpoints/Organizations/leaveOrganization.json');
162
        $client = $this->getMockClient($response);
163
164
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
165
        $organization = new Organizations($client);
166
        $result  = $organization->leaveOrganization('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
167
168
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
169
        $this->assertEquals('Left organization.', $result->message);
170
    }
171
172
    public function testChangeOwner()
173
    {
174
        $response = $this->getPsr7GzipResponseForFixture('Endpoints/Organizations/changeOwner.json');
175
        $client = $this->getMockClient($response);
176
177
        /** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
178
        $organization = new Organizations($client);
179
        $result  = $organization->changeOwner(
180
            '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851',
181
            '82cff7ec-2f09-11e9-b210-d663bd873d93'
182
        );
183
184
        $this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
185
        $this->assertEquals("Changed organization owner.", $result->message);
186
    }
187
}
188