diff --git a/src/Endpoints/Crypto.php b/src/Endpoints/Crypto.php index d8077a7..faf30c1 100644 --- a/src/Endpoints/Crypto.php +++ b/src/Endpoints/Crypto.php @@ -44,7 +44,7 @@ class Crypto implements API ); $body = json_decode($return->getBody()); if ($body->result) { - return $body->result; + return $body; } return false; } diff --git a/tests/Endpoints/CryptoTest.php b/tests/Endpoints/CryptoTest.php index 747d8a7..84c0110 100644 --- a/tests/Endpoints/CryptoTest.php +++ b/tests/Endpoints/CryptoTest.php @@ -2,5 +2,69 @@ class CryptoTest extends TestCase { - + public function testGetSSLSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLSetting.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl') + ); + + $zoneSSLSetting = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $zoneSSLSetting->getSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertEquals('off', $result); + } + + public function testGetSSLVerificationStatus() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getSSLVerificationStatus.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/ssl/verification') + ); + + $zoneVerificationStatus = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $zoneVerificationStatus->getSSLVerificationStatus('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); + + $this->assertObjectHasAttribute('result', $result); + $this->assertEquals('active', $result->result{0}->certificate_status); + } + + + + + + + public function testUpdateSSLSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateSSLSetting.json'); + + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once()) + ->method('patch') + ->with( + $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/ssl'), + $this->equalTo(['value' => 'full']) + ); + + $zoneSSLSetting = new \Cloudflare\API\Endpoints\Crypto($mock); + $result = $zoneSSLSetting->updateSSLSetting('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', 'full'); + + $this->assertTrue($result); + } + + } diff --git a/tests/Fixtures/Endpoints/getSSLSetting.json b/tests/Fixtures/Endpoints/getSSLSetting.json new file mode 100644 index 0000000..43fa3ee --- /dev/null +++ b/tests/Fixtures/Endpoints/getSSLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "ssl", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/getSSLVerificationStatus.json b/tests/Fixtures/Endpoints/getSSLVerificationStatus.json new file mode 100644 index 0000000..5e2a4f3 --- /dev/null +++ b/tests/Fixtures/Endpoints/getSSLVerificationStatus.json @@ -0,0 +1,16 @@ +{ + "result": [ + { + "certificate_status": "active", + "verification_type": "cname", + "verification_status": true, + "verification_info": { + "record_name": "b3b90cfedd89a3e487d3e383c56c4267.example.com", + "record_target": "6979be7e4cfc9e5c603e31df7efac9cc60fee82d.comodoca.com" + }, + "brand_check": false, + "validation_method": "txt", + "cert_pack_uuid": "a77f8bd7-3b47-46b4-a6f1-75cf98109948" + } + ] +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateSSLSetting.json b/tests/Fixtures/Endpoints/updateSSLSetting.json new file mode 100644 index 0000000..43fa3ee --- /dev/null +++ b/tests/Fixtures/Endpoints/updateSSLSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "ssl", + "value": "off", + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file