Add Account Id To Zone Creation (#195)
This commit is contained in:
@@ -27,18 +27,20 @@ class Zones implements API
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param bool $jumpStart
|
* @param bool $jumpStart
|
||||||
* @param string $organizationID
|
* @param string $accountId
|
||||||
* @return \stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
|
public function addZone(string $name, bool $jumpStart = false, string $accountId = ''): \stdClass
|
||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'jump_start' => $jumpStart
|
'jump_start' => $jumpStart
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($organizationID)) {
|
if (!empty($accountId)) {
|
||||||
$options['organization'] = ['id' => $organizationID];
|
$options['account'] = [
|
||||||
|
'id' => $accountId,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->adapter->post('zones', $options);
|
$user = $this->adapter->post('zones', $options);
|
||||||
|
|||||||
78
tests/Endpoints/ZoneCacheTest.php
Normal file
78
tests/Endpoints/ZoneCacheTest.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ZoneCacheTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCachePurgeEverything()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||||
|
$this->equalTo(['purge_everything' => true])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCachePurgeHost()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||||
|
$this->equalTo(
|
||||||
|
[
|
||||||
|
'files' => [],
|
||||||
|
'tags' => [],
|
||||||
|
'hosts' => ['dash.cloudflare.com']
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCachePurge()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
||||||
|
$this->equalTo(['files' => [
|
||||||
|
'https://example.com/file.jpg',
|
||||||
|
]
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
|
||||||
|
'https://example.com/file.jpg',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,9 @@ class ZonesTest extends TestCase
|
|||||||
$this->equalTo([
|
$this->equalTo([
|
||||||
'name' => 'example.com',
|
'name' => 'example.com',
|
||||||
'jump_start' => true,
|
'jump_start' => true,
|
||||||
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
|
'account' => [
|
||||||
|
'id' => '01a7362d577a6c3019a474fd6f485823',
|
||||||
|
],
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -49,6 +51,33 @@ class ZonesTest extends TestCase
|
|||||||
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
$this->assertEquals('9a7806061c88ada191ed06f989cc3dac', $zones->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAddZoneWithAccountId()
|
||||||
|
{
|
||||||
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addZone.json');
|
||||||
|
|
||||||
|
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
||||||
|
$mock->method('post')->willReturn($response);
|
||||||
|
|
||||||
|
$mock->expects($this->once())
|
||||||
|
->method('post')
|
||||||
|
->with(
|
||||||
|
$this->equalTo('zones'),
|
||||||
|
$this->equalTo([
|
||||||
|
'name' => 'example.com',
|
||||||
|
'jump_start' => false,
|
||||||
|
'account' => [
|
||||||
|
'id' => '023e105f4ecef8ad9ca31a8372d0c353',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
||||||
|
$result = $zones->addZone('example.com', false, '023e105f4ecef8ad9ca31a8372d0c353');
|
||||||
|
|
||||||
|
$this->assertObjectHasAttribute('id', $result);
|
||||||
|
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->account->id);
|
||||||
|
}
|
||||||
|
|
||||||
public function testActivationTest()
|
public function testActivationTest()
|
||||||
{
|
{
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
|
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
|
||||||
@@ -188,78 +217,4 @@ class ZonesTest extends TestCase
|
|||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$this->assertEquals('development_mode', $zones->getBody()->result->id);
|
$this->assertEquals('development_mode', $zones->getBody()->result->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCachePurgeEverything()
|
|
||||||
{
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
|
||||||
$mock->method('post')->willReturn($response);
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
|
||||||
->method('post')
|
|
||||||
->with(
|
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
|
||||||
$this->equalTo(['purge_everything' => true])
|
|
||||||
);
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
|
||||||
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCachePurgeHost()
|
|
||||||
{
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
|
||||||
$mock->method('post')->willReturn($response);
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
|
||||||
->method('post')
|
|
||||||
->with(
|
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
|
||||||
$this->equalTo(
|
|
||||||
[
|
|
||||||
'files' => [],
|
|
||||||
'tags' => [],
|
|
||||||
'hosts' => ['dash.cloudflare.com']
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
|
||||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCachePurge()
|
|
||||||
{
|
|
||||||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
|
|
||||||
|
|
||||||
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
|
|
||||||
$mock->method('post')->willReturn($response);
|
|
||||||
|
|
||||||
$mock->expects($this->once())
|
|
||||||
->method('post')
|
|
||||||
->with(
|
|
||||||
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
|
|
||||||
$this->equalTo(['files' => [
|
|
||||||
'https://example.com/file.jpg',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
|
|
||||||
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
|
|
||||||
'https://example.com/file.jpg',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
"email": "user@example.com",
|
"email": "user@example.com",
|
||||||
"owner_type": "user"
|
"owner_type": "user"
|
||||||
},
|
},
|
||||||
|
"account": {
|
||||||
|
"id": "023e105f4ecef8ad9ca31a8372d0c353",
|
||||||
|
"name": "Demo Account"
|
||||||
|
},
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"#zone:read",
|
"#zone:read",
|
||||||
"#zone:edit"
|
"#zone:edit"
|
||||||
|
|||||||
Reference in New Issue
Block a user