Skip to content

Adds set/save to ParseConfig #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Parse/ParseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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'];
}
}
20 changes: 20 additions & 0 deletions tests/Parse/ParseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public static function setUpBeforeClass()
Helper::setUp();
}

public function tearDown()
{
// clear config on tear down
Helper::clearClass('_GlobalConfig');
}

/**
* @group parse-config
*/
Expand Down Expand Up @@ -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');
}
}