Add Account Id To Zone Creation (#195)

This commit is contained in:
Phil Young
2021-10-13 04:31:32 +01:00
committed by GitHub
parent 99d8cfb71c
commit 12ac2bbd76
4 changed files with 118 additions and 79 deletions

View File

@@ -40,7 +40,9 @@ class ZonesTest extends TestCase
$this->equalTo([
'name' => 'example.com',
'jump_start' => true,
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
'account' => [
'id' => '01a7362d577a6c3019a474fd6f485823',
],
])
);
@@ -49,6 +51,33 @@ class ZonesTest extends TestCase
$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()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/activationTest.json');
@@ -188,78 +217,4 @@ class ZonesTest extends TestCase
$this->assertTrue($result);
$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);
}
}