FirewallSettingsTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. class FirewallSettingsTest extends TestCase
  3. {
  4. public function testGetSecurityLevelSetting()
  5. {
  6. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSecurityLevelSetting.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/security_level')
  13. );
  14. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  15. $result = $firewallSettingsMock->getSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  16. $this->assertEquals('medium', $result);
  17. }
  18. public function testGetChallengeTTLSetting()
  19. {
  20. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getChallengeTTLSetting.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/challenge_ttl')
  27. );
  28. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  29. $result = $firewallSettingsMock->getChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  30. $this->assertEquals(1800, $result);
  31. }
  32. public function testGetBrowserIntegrityCheckSetting()
  33. {
  34. $response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserIntegrityCheckSetting.json');
  35. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  36. $mock->method('get')->willReturn($response);
  37. $mock->expects($this->once())
  38. ->method('get')
  39. ->with(
  40. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/browser_check')
  41. );
  42. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  43. $result = $firewallSettingsMock->getBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  44. $this->assertEquals('on', $result);
  45. }
  46. public function testUpdateSecurityLevelSetting()
  47. {
  48. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSecurityLevelSetting.json');
  49. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  50. $mock->method('patch')->willReturn($response);
  51. $mock->expects($this->once())
  52. ->method('patch')
  53. ->with(
  54. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/security_level'),
  55. $this->equalTo(['value' => 'medium'])
  56. );
  57. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  58. $result = $firewallSettingsMock->updateSecurityLevelSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'medium');
  59. $this->assertTrue($result);
  60. }
  61. public function testUpdateChallengeTTLSetting()
  62. {
  63. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateChallengeTTLSetting.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/challenge_ttl'),
  70. $this->equalTo(['value' => 1800])
  71. );
  72. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  73. $result = $firewallSettingsMock->updateChallengeTTLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 1800);
  74. $this->assertTrue($result);
  75. }
  76. public function testUpdateBrowserIntegrityCheckSetting()
  77. {
  78. $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserIntegrityCheckSetting.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/browser_check'),
  85. $this->equalTo(['value' => 'on'])
  86. );
  87. $firewallSettingsMock = new \Cloudflare\API\Endpoints\FirewallSettings($mock);
  88. $result = $firewallSettingsMock->updateBrowserIntegrityCheckSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'on');
  89. $this->assertTrue($result);
  90. }
  91. }