Skip to content
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
2 changes: 1 addition & 1 deletion src/Document/Data/Adapter/AbstractPageSnippetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function setEditableData(PageSnippet $document, array $data): void
$this->setAppendEditables($document, $data);
$editableData = $data[DocumentFieldKeys::EDITABLE_DATA->value];
foreach ($editableData as $name => $value) {
$document->setRawEditable($name, $value['type'], $value['data'] ?? null);
$document->setRawEditable((string) $name, $value['type'], $value['data'] ?? null);
}
}

Expand Down
66 changes: 66 additions & 0 deletions tests/Unit/Document/Data/Adapter/PageAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\Tests\Unit\Document\Data\Adapter;

use Codeception\Test\Unit;
use Pimcore\Bundle\StudioBackendBundle\Document\Data\Adapter\PageAdapter;
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\Document\DocumentFieldKeys;
use Pimcore\Document\StaticPageGenerator;
use Pimcore\Model\Document\Page;
use Pimcore\Model\UserInterface;

/**
* @internal
*/
final class PageAdapterTest extends Unit
{
public function testSetDataAcceptsPurelyNumericEditableNames(): void
{
$setEditables = [];
$document = $this->createMock(Page::class);
$document->method('setRawEditable')->willReturnCallback(
function (string $name, string $type, mixed $data) use (&$setEditables, $document): Page {
$setEditables[$name] = [$type, $data];

return $document;
}
);

$adapter = new PageAdapter(
$this->createMock(SecurityServiceInterface::class),
$this->createMock(StaticPageGenerator::class)
);

// json_decode() turns the purely numeric editable name "123" into the integer array key 123
$adapter->setData(
$document,
[
DocumentFieldKeys::EDITABLE_DATA->value => [
'123' => ['type' => 'input', 'data' => 'numeric'],
'headline' => ['type' => 'input', 'data' => 'text'],
],
],
$this->createMock(UserInterface::class)
);

$this->assertSame(
[
'123' => ['input', 'numeric'],
'headline' => ['input', 'text'],
],
$setEditables
);
}
}
Loading