From fab493d2d38e989e227606f55a58da3ef8e22ea8 Mon Sep 17 00:00:00 2001 From: bnalonezi <40964604+bnalonezi@users.noreply.github.com> Date: Tue, 7 Jul 2020 13:18:40 +0300 Subject: [PATCH] Add Browser Cache TTL endpoint (#127) Co-authored-by: bnalonezi --- src/Endpoints/ZoneSettings.php | 31 +++++++++++++++++++ tests/Endpoints/ZoneSettingsTest.php | 30 ++++++++++++++++++ .../Endpoints/getBrowserCacheTtlSetting.json | 11 +++++++ .../updateBrowserCacheTtlSetting.json | 11 +++++++ 4 files changed, 83 insertions(+) create mode 100644 tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json create mode 100644 tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json diff --git a/src/Endpoints/ZoneSettings.php b/src/Endpoints/ZoneSettings.php index b7baf48..5c237eb 100644 --- a/src/Endpoints/ZoneSettings.php +++ b/src/Endpoints/ZoneSettings.php @@ -106,6 +106,37 @@ class ZoneSettings implements API return false; } + public function getBrowserCacheTtlSetting($zoneID) + { + $return = $this->adapter->get( + 'zones/' . $zoneID . '/settings/browser_cache_ttl' + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return $body->result->value; + } + + return false; + } + + public function updateBrowserCacheTtlSetting($zoneID, $value) + { + $return = $this->adapter->patch( + 'zones/' . $zoneID . '/settings/browser_cache_ttl', + [ + 'value' => $value + ] + ); + $body = json_decode($return->getBody()); + + if ($body->success) { + return true; + } + + return false; + } + public function updateMinifySetting($zoneID, $html, $css, $javascript) { $return = $this->adapter->patch( diff --git a/tests/Endpoints/ZoneSettingsTest.php b/tests/Endpoints/ZoneSettingsTest.php index 05bc2a7..e4d2d8d 100644 --- a/tests/Endpoints/ZoneSettingsTest.php +++ b/tests/Endpoints/ZoneSettingsTest.php @@ -36,4 +36,34 @@ class ZoneSettingsTest extends TestCase $this->assertSame('on', $result); } + + public function testGetBrowserCacheTtlSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getBrowserCacheTtlSetting.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('get')->willReturn($response); + + $mock->expects($this->once())->method('get'); + + $zones = new ZoneSettings($mock); + $result = $zones->getBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353'); + + $this->assertSame(14400, $result); + } + + public function testUpdateBrowserCacheTtlSetting() + { + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateBrowserCacheTtlSetting.json'); + + $mock = $this->getMockBuilder(Adapter::class)->getMock(); + $mock->method('patch')->willReturn($response); + + $mock->expects($this->once())->method('patch'); + + $zones = new ZoneSettings($mock); + $result = $zones->updateBrowserCacheTtlSetting('023e105f4ecef8ad9ca31a8372d0c353', 16070400); + + $this->assertTrue($result); + } } diff --git a/tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json b/tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json new file mode 100644 index 0000000..be08512 --- /dev/null +++ b/tests/Fixtures/Endpoints/getBrowserCacheTtlSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "browser_cache_ttl", + "value": 14400, + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file diff --git a/tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json b/tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json new file mode 100644 index 0000000..be08512 --- /dev/null +++ b/tests/Fixtures/Endpoints/updateBrowserCacheTtlSetting.json @@ -0,0 +1,11 @@ +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "browser_cache_ttl", + "value": 14400, + "editable": true, + "modified_on": "2014-01-01T05:20:00.12345Z" + } +} \ No newline at end of file