From 583e6579837e571e653b8dcc4357aa0918abd5f0 Mon Sep 17 00:00:00 2001 From: Benjamin Friedman Date: Tue, 7 Nov 2017 14:59:40 -0800 Subject: [PATCH] adds the ability to set/save in ParseConfig --- src/Parse/ParseConfig.php | 30 ++++++++++++++++++++++++++++++ tests/Parse/ParseConfigTest.php | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/Parse/ParseConfig.php b/src/Parse/ParseConfig.php index a20d2f55..0d9160db 100644 --- a/src/Parse/ParseConfig.php +++ b/src/Parse/ParseConfig.php @@ -43,6 +43,17 @@ public function get($key) return null; } + /** + * Sets a config value + * + * @param string $key Key to set value on + * @param mixed $value Value to set + */ + public function set($key, $value) + { + $this->currentConfig[$key] = $value; + } + /** * Gets a config value with html characters encoded * @@ -76,4 +87,23 @@ public function getConfig() { return $this->currentConfig; } + + /** + * Saves the current config + * + * @return bool + */ + public function save() + { + $response = ParseClient::_request( + 'PUT', + 'config', + null, + json_encode([ + 'params' => $this->currentConfig + ]), + true + ); + return $response['result']; + } } diff --git a/tests/Parse/ParseConfigTest.php b/tests/Parse/ParseConfigTest.php index 2a35df31..a61c4abf 100644 --- a/tests/Parse/ParseConfigTest.php +++ b/tests/Parse/ParseConfigTest.php @@ -11,6 +11,12 @@ public static function setUpBeforeClass() Helper::setUp(); } + public function tearDown() + { + // clear config on tear down + Helper::clearClass('_GlobalConfig'); + } + /** * @group parse-config */ @@ -52,4 +58,18 @@ public function testEscapeConfig() // check normal value $this->assertEquals('bar', $config->escape('foo')); } + + /** + * @group parse-config + */ + public function testSaveConfig() + { + $config = new ParseConfig(); + $this->assertNull($config->get('key')); + $config->set('key', 'value'); + $config->save(); + + $config = new ParseConfig(); + $this->assertEquals($config->get('key'), 'value'); + } }