Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct(
* @throws NotLoggedInException Not logged in or not an admin user
* @throws NotAdminException Not logged in or not an admin user
* @throws OCSBadRequestException Invalid arguments to save value
* @NoSubAdminRequired
*
* 200: Value set successfully
*/
Expand All @@ -69,6 +70,7 @@ public function setValue(string $app, string $formId, string $fieldId, mixed $va
* @throws NotLoggedInException Not logged in or not an admin user
* @throws NotAdminException Not logged in or not an admin user
* @throws OCSBadRequestException Invalid arguments to save value
* @NoSubAdminRequired
*
* 200: Value set successfully
*/
Expand Down
1 change: 1 addition & 0 deletions lib/private/Settings/DeclarativeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ private function getInternalValue(IUser $user, string $app, string $formId, stri
}

private function saveInternalValue(IUser $user, string $app, string $formId, string $fieldId, mixed $value): void {
$value = is_array($value) ? json_encode($value, JSON_THROW_ON_ERROR) : (string)$value;
$sectionType = $this->getSectionType($app, $fieldId);

$field = $this->getSchemaField($app, $formId, $fieldId);
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/Settings/DeclarativeManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\Settings\IDeclarativeManager;
use OCP\Settings\IDeclarativeSettingsForm;
use OCP\Settings\IDeclarativeSettingsFormWithHandlers;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
Expand Down Expand Up @@ -528,6 +529,28 @@ public function testSetInternalValue(): void {
$this->assertEquals('120m', $someRealSettingField['value']);
}

public static function dataSetInternalValue(): array {
return [
'switch' => [1, '1'],
'float' => [1.5, '1.5'],
'bool' => [true, '1'],
'list' => [['foo', 'bar'], '["foo","bar"]'],
];
}

#[DataProvider('dataSetInternalValue')]
public function testSetInternalValueIsStoredAsString(mixed $value, string $stored): void {
$app = 'testing';
$schema = self::validSchemaAllFields;
$this->declarativeManager->registerSchema($app, $schema);

$this->appConfig->expects($this->once())
->method('setValueString')
->with($app, 'test_field_4', $stored);

$this->declarativeManager->setValue($this->adminUser, $app, $schema['id'], 'test_field_4', $value);
}

public function testSetExternalValue(): void {
$app = 'testing';
$schema = self::validSchemaAllFields;
Expand Down
Loading