-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathAccountsTest.php
More file actions
116 lines (93 loc) · 3.83 KB
/
Copy pathAccountsTest.php
File metadata and controls
116 lines (93 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
use Cloudflare\API\Endpoints\Accounts;
/**
* User: kanasite
* Date: 01/28/2019
* Time: 10:00
*/
class AccountsTest extends TestCase
{
public function testListZones()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccounts.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'direction' => 'desc',
])
);
$accounts = new Accounts($mock);
$result = $accounts->listAccounts(1, 20, 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
}
public function testAddAccountWithDefaultType()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createStandardAccount.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'name' => 'Foo Bar',
'type' => 'standard',
])
);
$accounts = new Accounts($mock);
$accounts->addAccount('Foo Bar');
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
}
public function testAddAccountWithCustomType()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createEnterpriseAccount.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('accounts'),
$this->equalTo([
'name' => 'Foo Bar',
'type' => 'enterprise',
])
);
$accounts = new Accounts($mock);
$accounts->addAccount('Foo Bar', 'enterprise');
$this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
}
public function testUpdateAccount()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccount.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('put')->willReturn($response);
$data = [
'id' => '01a7362d577a6c3019a474fd6f485823',
'name' => 'Demo Account',
'settings' => [
'enforce_twofactor' => false,
'use_account_custom_ns_by_default' => false,
],
];
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('accounts/01a7362d577a6c3019a474fd6f485823'),
$this->equalTo($data)
);
$accounts = new \Cloudflare\API\Endpoints\Accounts($mock);
$result = $accounts->updateAccount('01a7362d577a6c3019a474fd6f485823', 'Demo Account', false, false);
$this->assertEquals('01a7362d577a6c3019a474fd6f485823', $result->id);
$this->assertEquals('01a7362d577a6c3019a474fd6f485823', $accounts->getBody()->result->id);
}
}