|
| 1 | +<?php |
| 2 | + |
| 3 | +use Cloudflare\API\Adapter\Adapter; |
| 4 | +use Cloudflare\API\Endpoints\ZoneSubscriptions; |
| 5 | + |
| 6 | +class ZoneSubscriptionsTest extends TestCase |
| 7 | +{ |
| 8 | + public function testListZoneSubscriptions() |
| 9 | + { |
| 10 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json'); |
| 11 | + |
| 12 | + $mock = $this->getMockBuilder(Adapter::class)->getMock(); |
| 13 | + $mock->method('get')->willReturn($response); |
| 14 | + |
| 15 | + $mock->expects($this->once()) |
| 16 | + ->method('get') |
| 17 | + ->with( |
| 18 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscriptions') |
| 19 | + ); |
| 20 | + |
| 21 | + $zoneSubscriptions = new ZoneSubscriptions($mock); |
| 22 | + $zoneSubscriptions->listZoneSubscriptions('023e105f4ecef8ad9ca31a8372d0c353'); |
| 23 | + |
| 24 | + $this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result[0]->id); |
| 25 | + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result[0]->zone->id); |
| 26 | + } |
| 27 | + |
| 28 | + public function testAddZoneSubscriptionIfMissing() |
| 29 | + { |
| 30 | + $postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json'); |
| 31 | + $getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listEmptyZoneSubscriptions.json'); |
| 32 | + |
| 33 | + $mock = $this->getMockBuilder(Adapter::class)->getMock(); |
| 34 | + $mock->method('post')->willReturn($postResponse); |
| 35 | + $mock->method('get')->willReturn($getResponse); |
| 36 | + |
| 37 | + $mock->expects($this->once()) |
| 38 | + ->method('post') |
| 39 | + ->with( |
| 40 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'), |
| 41 | + $this->equalTo([ |
| 42 | + 'rate_plan' => [ |
| 43 | + 'id' => 'PARTNER_PRO', |
| 44 | + ], |
| 45 | + ]) |
| 46 | + ); |
| 47 | + |
| 48 | + $zoneSubscriptions = new ZoneSubscriptions($mock); |
| 49 | + $zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO'); |
| 50 | + |
| 51 | + $this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id); |
| 52 | + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id); |
| 53 | + } |
| 54 | + |
| 55 | + public function testAddZoneSubscriptionIfExisting() |
| 56 | + { |
| 57 | + $postResponse = $this->getPsr7JsonResponseForFixture('Endpoints/createZoneSubscription.json'); |
| 58 | + $getResponse = $this->getPsr7JsonResponseForFixture('Endpoints/listZoneSubscriptions.json'); |
| 59 | + |
| 60 | + $mock = $this->getMockBuilder(Adapter::class)->getMock(); |
| 61 | + $mock->method('put')->willReturn($postResponse); |
| 62 | + $mock->method('get')->willReturn($getResponse); |
| 63 | + |
| 64 | + $mock->expects($this->once()) |
| 65 | + ->method('put') |
| 66 | + ->with( |
| 67 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/subscription'), |
| 68 | + $this->equalTo([ |
| 69 | + 'rate_plan' => [ |
| 70 | + 'id' => 'PARTNER_PRO', |
| 71 | + ], |
| 72 | + ]) |
| 73 | + ); |
| 74 | + |
| 75 | + $zoneSubscriptions = new ZoneSubscriptions($mock); |
| 76 | + $zoneSubscriptions->addZoneSubscription('023e105f4ecef8ad9ca31a8372d0c353', 'PARTNER_PRO'); |
| 77 | + |
| 78 | + $this->assertEquals('506e3185e9c882d175a2d0cb0093d9f2', $zoneSubscriptions->getBody()->result->id); |
| 79 | + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zoneSubscriptions->getBody()->result->zone->id); |
| 80 | + } |
| 81 | +} |
0 commit comments