AccountsTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. use Cloudflare\API\Endpoints\Accounts;
  3. /**
  4. * User: kanasite
  5. * Date: 01/28/2019
  6. * Time: 10:00
  7. */
  8. class AccountsTest extends TestCase
  9. {
  10. public function testListZones()
  11. {
  12. $response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccounts.json');
  13. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  14. $mock->method('get')->willReturn($response);
  15. $mock->expects($this->once())
  16. ->method('get')
  17. ->with(
  18. $this->equalTo('accounts'),
  19. $this->equalTo([
  20. 'page' => 1,
  21. 'per_page' => 20,
  22. 'direction' => 'desc',
  23. ])
  24. );
  25. $accounts = new Accounts($mock);
  26. $result = $accounts->listAccounts(1, 20, 'desc');
  27. $this->assertObjectHasAttribute('result', $result);
  28. $this->assertObjectHasAttribute('result_info', $result);
  29. $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
  30. $this->assertEquals(1, $result->result_info->page);
  31. $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $accounts->getBody()->result[0]->id);
  32. }
  33. public function testAddAccountWithDefaultType()
  34. {
  35. $response = $this->getPsr7JsonResponseForFixture('Endpoints/createStandardAccount.json');
  36. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  37. $mock->method('post')->willReturn($response);
  38. $mock->expects($this->once())
  39. ->method('post')
  40. ->with(
  41. $this->equalTo('accounts'),
  42. $this->equalTo([
  43. 'name' => 'Foo Bar',
  44. 'type' => 'standard',
  45. ])
  46. );
  47. $accounts = new Accounts($mock);
  48. $accounts->addAccount('Foo Bar');
  49. $this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
  50. }
  51. public function testAddAccountWithCustomType()
  52. {
  53. $response = $this->getPsr7JsonResponseForFixture('Endpoints/createEnterpriseAccount.json');
  54. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  55. $mock->method('post')->willReturn($response);
  56. $mock->expects($this->once())
  57. ->method('post')
  58. ->with(
  59. $this->equalTo('accounts'),
  60. $this->equalTo([
  61. 'name' => 'Foo Bar',
  62. 'type' => 'enterprise',
  63. ])
  64. );
  65. $accounts = new Accounts($mock);
  66. $accounts->addAccount('Foo Bar', 'enterprise');
  67. $this->assertEquals('2bab6ace8c72ed3f09b9eca6db1396bb', $accounts->getBody()->result->id);
  68. }
  69. }