ZoneSubscriptionsTest.php 3.3 KB

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