Skip to content

Commit 12ac2bb

Browse files
authored
Add Account Id To Zone Creation (cloudflare#195)
1 parent 99d8cfb commit 12ac2bb

4 files changed

Lines changed: 118 additions & 79 deletions

File tree

src/Endpoints/Zones.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ public function __construct(Adapter $adapter)
2727
*
2828
* @param string $name
2929
* @param bool $jumpStart
30-
* @param string $organizationID
30+
* @param string $accountId
3131
* @return \stdClass
3232
*/
33-
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
33+
public function addZone(string $name, bool $jumpStart = false, string $accountId = ''): \stdClass
3434
{
3535
$options = [
3636
'name' => $name,
3737
'jump_start' => $jumpStart
3838
];
3939

40-
if (!empty($organizationID)) {
41-
$options['organization'] = ['id' => $organizationID];
40+
if (!empty($accountId)) {
41+
$options['account'] = [
42+
'id' => $accountId,
43+
];
4244
}
4345

4446
$user = $this->adapter->post('zones', $options);

tests/Endpoints/ZoneCacheTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
class ZoneCacheTest extends TestCase
4+
{
5+
public function testCachePurgeEverything()
6+
{
7+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
8+
9+
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
10+
$mock->method('post')->willReturn($response);
11+
12+
$mock->expects($this->once())
13+
->method('post')
14+
->with(
15+
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
16+
$this->equalTo(['purge_everything' => true])
17+
);
18+
19+
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
20+
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
21+
22+
$this->assertTrue($result);
23+
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
24+
}
25+
26+
public function testCachePurgeHost()
27+
{
28+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
29+
30+
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
31+
$mock->method('post')->willReturn($response);
32+
33+
$mock->expects($this->once())
34+
->method('post')
35+
->with(
36+
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
37+
$this->equalTo(
38+
[
39+
'files' => [],
40+
'tags' => [],
41+
'hosts' => ['dash.cloudflare.com']
42+
]
43+
)
44+
);
45+
46+
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
47+
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
48+
49+
$this->assertTrue($result);
50+
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
51+
}
52+
53+
public function testCachePurge()
54+
{
55+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
56+
57+
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
58+
$mock->method('post')->willReturn($response);
59+
60+
$mock->expects($this->once())
61+
->method('post')
62+
->with(
63+
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
64+
$this->equalTo(['files' => [
65+
'https://example.com/file.jpg',
66+
]
67+
])
68+
);
69+
70+
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
71+
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
72+
'https://example.com/file.jpg',
73+
]);
74+
75+
$this->assertTrue($result);
76+
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
77+
}
78+
}

tests/Endpoints/ZonesTest.php

Lines changed: 30 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function testAddZone()
4040
$this->equalTo([
4141
'name' => 'example.com',
4242
'jump_start' => true,
43-
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
43+
'account' => [
44+
'id' => '01a7362d577a6c3019a474fd6f485823',
45+
],
4446
])
4547
);
4648

@@ -49,6 +51,33 @@ public function testAddZone()
4951
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
5052
}
5153

54+
public function testAddZoneWithAccountId()
55+
{
56+
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.json');
57+
58+
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
59+
$mock->method('post')->willReturn($response);
60+
61+
$mock->expects($this->once())
62+
->method('post')
63+
->with(
64+
$this->equalTo('zones'),
65+
$this->equalTo([
66+
'name' => 'example.com',
67+
'jump_start' => false,
68+
'account' => [
69+
'id' => '023e105f4ecef8ad9ca31a8372d0c353',
70+
],
71+
])
72+
);
73+
74+
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
75+
$result = $zones->addZone('example.com', false, '023e105f4ecef8ad9ca31a8372d0c353');
76+
77+
$this->assertObjectHasAttribute('id', $result);
78+
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->account->id);
79+
}
80+
5281
public function testActivationTest()
5382
{
5483
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
@@ -188,78 +217,4 @@ public function testChangeDevelopmentMode()
188217
$this->assertTrue($result);
189218
$this->assertEquals('development_mode', $zones->getBody()->result->id);
190219
}
191-
192-
public function testCachePurgeEverything()
193-
{
194-
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
195-
196-
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
197-
$mock->method('post')->willReturn($response);
198-
199-
$mock->expects($this->once())
200-
->method('post')
201-
->with(
202-
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
203-
$this->equalTo(['purge_everything' => true])
204-
);
205-
206-
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
207-
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
208-
209-
$this->assertTrue($result);
210-
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
211-
}
212-
213-
public function testCachePurgeHost()
214-
{
215-
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
216-
217-
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
218-
$mock->method('post')->willReturn($response);
219-
220-
$mock->expects($this->once())
221-
->method('post')
222-
->with(
223-
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
224-
$this->equalTo(
225-
[
226-
'files' => [],
227-
'tags' => [],
228-
'hosts' => ['dash.cloudflare.com']
229-
]
230-
)
231-
);
232-
233-
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
234-
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
235-
236-
$this->assertTrue($result);
237-
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
238-
}
239-
240-
public function testCachePurge()
241-
{
242-
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
243-
244-
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
245-
$mock->method('post')->willReturn($response);
246-
247-
$mock->expects($this->once())
248-
->method('post')
249-
->with(
250-
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
251-
$this->equalTo(['files' => [
252-
'https://example.com/file.jpg',
253-
]
254-
])
255-
);
256-
257-
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
258-
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
259-
'https://example.com/file.jpg',
260-
]);
261-
262-
$this->assertTrue($result);
263-
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
264-
}
265220
}

tests/Fixtures/Endpoints/addZone.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"email": "user@example.com",
2424
"owner_type": "user"
2525
},
26+
"account": {
27+
"id": "023e105f4ecef8ad9ca31a8372d0c353",
28+
"name": "Demo Account"
29+
},
2630
"permissions": [
2731
"#zone:read",
2832
"#zone:edit"

0 commit comments

Comments
 (0)