MembershipTest.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. class MembershipTest extends TestCase
  3. {
  4. public function testListMemberships()
  5. {
  6. $response = $this->getPsr7JsonResponseForFixture('Endpoints/listMemberships.json');
  7. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  8. $mock->method('get')->willReturn($response);
  9. $mock->expects($this->once())
  10. ->method('get')
  11. ->with(
  12. $this->equalTo('memberships'),
  13. $this->equalTo([
  14. 'page' => 1,
  15. 'per_page' => 20,
  16. 'account.name' => 'Demo Account',
  17. 'status' => 'accepted',
  18. 'order' => 'status',
  19. 'direction' => 'desc',
  20. ])
  21. );
  22. $zones = new \Cloudflare\API\Endpoints\Membership($mock);
  23. $result = $zones->listMemberships('Demo Account', 'accepted', 1, 20, 'status', 'desc');
  24. $this->assertObjectHasAttribute('result', $result);
  25. $this->assertObjectHasAttribute('result_info', $result);
  26. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $result->result[0]->id);
  27. $this->assertEquals(1, $result->result_info->page);
  28. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $zones->getBody()->result[0]->id);
  29. }
  30. public function testGetMembershipDetails()
  31. {
  32. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getMembershipDetails.json');
  33. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  34. $mock->method('get')->willReturn($response);
  35. $membership = new \Cloudflare\API\Endpoints\Membership($mock);
  36. $details = $membership->getMembershipDetails('4536bcfad5faccb111b47003c79917fa');
  37. $this->assertObjectHasAttribute('id', $details);
  38. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $details->id);
  39. $this->assertObjectHasAttribute('code', $details);
  40. $this->assertEquals('05dd05cce12bbed97c0d87cd78e89bc2fd41a6cee72f27f6fc84af2e45c0fac0', $details->code);
  41. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
  42. }
  43. public function testUpdateMembershipDetails()
  44. {
  45. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateMembershipStatus.json');
  46. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  47. $mock->method('put')->willReturn($response);
  48. $mock->expects($this->once())
  49. ->method('put')
  50. ->with(
  51. $this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'),
  52. $this->equalTo([
  53. 'status' => 'accepted'
  54. ])
  55. );
  56. $membership = new \Cloudflare\API\Endpoints\Membership($mock);
  57. $membership->updateMembershipStatus('4536bcfad5faccb111b47003c79917fa', 'accepted');
  58. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
  59. }
  60. public function testDeleteMembership()
  61. {
  62. $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteMembership.json');
  63. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  64. $mock->method('delete')->willReturn($response);
  65. $mock->expects($this->once())
  66. ->method('delete')
  67. ->with($this->equalTo('memberships/4536bcfad5faccb111b47003c79917fa'));
  68. $membership = new \Cloudflare\API\Endpoints\Membership($mock);
  69. $membership->deleteMembership('4536bcfad5faccb111b47003c79917fa');
  70. $this->assertEquals('4536bcfad5faccb111b47003c79917fa', $membership->getBody()->result->id);
  71. }
  72. }