CryptoTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. class CryptoTest extends TestCase
  3. {
  4. public function testGetOpportunisticEncryptionSetting()
  5. {
  6. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getOpportunisticEncryptionSetting.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('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption')
  13. );
  14. $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
  15. $result = $cryptoMock->getOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  16. $this->assertEquals('off', $result);
  17. }
  18. public function testGetOnionRoutingSetting()
  19. {
  20. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getOnionRoutingSetting.json');
  21. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  22. $mock->method('get')->willReturn($response);
  23. $mock->expects($this->once())
  24. ->method('get')
  25. ->with(
  26. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion')
  27. );
  28. $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
  29. $result = $cryptoMock->getOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  30. $this->assertEquals('off', $result);
  31. }
  32. public function testUpdateOpportunisticEncryptionSetting()
  33. {
  34. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOpportunisticEncryptionSetting.json');
  35. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  36. $mock->method('patch')->willReturn($response);
  37. $mock->expects($this->once())
  38. ->method('patch')
  39. ->with(
  40. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_encryption'),
  41. $this->equalTo(['value' => 'off'])
  42. );
  43. $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
  44. $result = $cryptoMock->updateOpportunisticEncryptionSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
  45. $this->assertTrue($result);
  46. }
  47. public function testUpdateOnionRoutingSetting()
  48. {
  49. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateOnionRoutingSetting.json');
  50. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  51. $mock->method('patch')->willReturn($response);
  52. $mock->expects($this->once())
  53. ->method('patch')
  54. ->with(
  55. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/opportunistic_onion'),
  56. $this->equalTo(['value' => 'off'])
  57. );
  58. $cryptoMock = new \Cloudflare\API\Endpoints\Crypto($mock);
  59. $result = $cryptoMock->updateOnionRoutingSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
  60. $this->assertTrue($result);
  61. }
  62. }