Implement admin controller api test

This commit is contained in:
Dennis Eichhorn 2017-12-01 23:54:17 +01:00
parent 879691d68d
commit e556fbed49
2 changed files with 13 additions and 3 deletions

View File

@ -56,7 +56,7 @@ trait OptionsTrait
*/ */
public function setOption($key, $value, bool $overwrite = true) : bool public function setOption($key, $value, bool $overwrite = true) : bool
{ {
if ($overwrite || !array_key_exists($key, $this->options)) { if ($overwrite || !isset($this->options[$key])) {
$this->options[$key] = $value; $this->options[$key] = $value;
return true; return true;

View File

@ -84,6 +84,7 @@ abstract class SettingsAbstract implements OptionsInterface
* @return mixed Option value * @return mixed Option value
* *
* @since 1.0.0 * @since 1.0.0
* @todo: don't db request if exists. check exists()
*/ */
public function get($columns) public function get($columns)
{ {
@ -110,7 +111,7 @@ abstract class SettingsAbstract implements OptionsInterface
break; break;
} }
return $options; return count($options) > 1 ? $options : reset($options);
} catch (\PDOException $e) { } catch (\PDOException $e) {
$exception = DatabaseExceptionFactory::createException($e); $exception = DatabaseExceptionFactory::createException($e);
$message = DatabaseExceptionFactory::createExceptionMessage($e); $message = DatabaseExceptionFactory::createExceptionMessage($e);
@ -134,7 +135,16 @@ abstract class SettingsAbstract implements OptionsInterface
$this->setOptions($options); $this->setOptions($options);
if ($store) { if ($store) {
// save to db foreach($this->options as $key => $option) {
$query = new Builder($this->connection);
$sql = $query->update($this->connection->prefix . static::$table)
->set([static::$columns[1] => $option])
->where(static::$columns[0], '=', $key)
->toSql();
$sth = $this->connection->con->prepare($sql);
$sth->execute();
}
} }
} }
} }