diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index 2335b1c..fd9e18b 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -27,18 +27,20 @@ class Zones implements API * * @param string $name * @param bool $jumpStart - * @param string $organizationID + * @param string $accountId * @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 = [ 'name' => $name, 'jump_start' => $jumpStart ]; - if (!empty($organizationID)) { - $options['organization'] = ['id' => $organizationID]; + if (!empty($accountId)) { + $options['account'] = [ + 'id' => $accountId, + ]; } $user = $this->adapter->post('zones', $options); diff --git a/tests/Endpoints/ZoneCacheTest.php b/tests/Endpoints/ZoneCacheTest.php new file mode 100644 index 0000000..bdefeec --- /dev/null +++ b/tests/Endpoints/ZoneCacheTest.php @@ -0,0 +1,78 @@ +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); + } +} diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index 02addeb..b4412f7 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -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); - } } diff --git a/tests/Fixtures/Endpoints/addZone.json b/tests/Fixtures/Endpoints/addZone.json index d3903c1..685e8cd 100644 --- a/tests/Fixtures/Endpoints/addZone.json +++ b/tests/Fixtures/Endpoints/addZone.json @@ -23,6 +23,10 @@ "email": "user@example.com", "owner_type": "user" }, + "account": { + "id": "023e105f4ecef8ad9ca31a8372d0c353", + "name": "Demo Account" + }, "permissions": [ "#zone:read", "#zone:edit"