SSLTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. class SSLTest extends TestCase
  3. {
  4. public function testGetSSLSetting()
  5. {
  6. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.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/ssl')
  13. );
  14. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  15. $result = $sslMock->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  16. $this->assertEquals('off', $result);
  17. }
  18. public function testGetSSLVerificationStatus()
  19. {
  20. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.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/ssl/verification')
  27. );
  28. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  29. $result = $sslMock->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  30. $this->assertObjectHasAttribute('result', $result);
  31. $this->assertEquals('active', $result->result[0]->certificate_status);
  32. }
  33. public function testGetHTTPSRedirectSetting()
  34. {
  35. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRedirectSetting.json');
  36. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  37. $mock->method('get')->willReturn($response);
  38. $mock->expects($this->once())
  39. ->method('get')
  40. ->with(
  41. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https')
  42. );
  43. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  44. $result = $sslMock->getHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  45. $this->assertEquals('off', $result);
  46. }
  47. public function testGetHTTPSRewritesSetting()
  48. {
  49. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getHTTPSRewritesSetting.json');
  50. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  51. $mock->method('get')->willReturn($response);
  52. $mock->expects($this->once())
  53. ->method('get')
  54. ->with(
  55. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites')
  56. );
  57. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  58. $result = $sslMock->getHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  59. $this->assertEquals('off', $result);
  60. }
  61. public function testUpdateSSLSetting()
  62. {
  63. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.json');
  64. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  65. $mock->method('patch')->willReturn($response);
  66. $mock->expects($this->once())
  67. ->method('patch')
  68. ->with(
  69. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl'),
  70. $this->equalTo(['value' => 'full'])
  71. );
  72. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  73. $result = $sslMock->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full');
  74. $this->assertTrue($result);
  75. }
  76. public function testUpdateHTTPSRedirectSetting()
  77. {
  78. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRedirectSetting.json');
  79. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  80. $mock->method('patch')->willReturn($response);
  81. $mock->expects($this->once())
  82. ->method('patch')
  83. ->with(
  84. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/always_use_https'),
  85. $this->equalTo(['value' => 'off'])
  86. );
  87. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  88. $result = $sslMock->updateHTTPSRedirectSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
  89. $this->assertTrue($result);
  90. }
  91. public function testUpdateHTTPSRewritesSetting()
  92. {
  93. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHTTPSRewritesSetting.json');
  94. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  95. $mock->method('patch')->willReturn($response);
  96. $mock->expects($this->once())
  97. ->method('patch')
  98. ->with(
  99. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/automatic_https_rewrites'),
  100. $this->equalTo(['value' => 'off'])
  101. );
  102. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  103. $result = $sslMock->updateHTTPSRewritesSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'off');
  104. $this->assertTrue($result);
  105. }
  106. public function testUpdateSSLCertificatePackValidationMethod()
  107. {
  108. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLCertificatePackValidationMethod.json');
  109. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  110. $mock->method('patch')->willReturn($response);
  111. $mock->expects($this->once())
  112. ->method('patch')
  113. ->with(
  114. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification/a77f8bd7-3b47-46b4-a6f1-75cf98109948'),
  115. $this->equalTo(['validation_method' => 'txt'])
  116. );
  117. $sslMock = new \Cloudflare\API\Endpoints\SSL($mock);
  118. $result = $sslMock->updateSSLCertificatePackValidationMethod('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'a77f8bd7-3b47-46b4-a6f1-75cf98109948', 'txt');
  119. $this->assertTrue($result);
  120. }
  121. }