feat: add new-tab links and removable media previews (1.7.3)
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s

This commit is contained in:
kantarci committed 2026-09-14 11:48:44 +02:00
1 parent b8991ddd5c
commit 6d21c452bd
28 files changed
+496 -46

No files matched your search

+65
View File
@@ -2569,6 +2569,69 @@ final class CmsTest extends TestCase
$this->partials->delete($this->partials->findByKind('header')['id']);
}
public function testNewTabLinksPersistForBlocksAndNestedMenus(): void
{
$document = DemoContent::starter('Links');
$document['schemaVersion'] = 20;
$types = [
'button' => ['text' => 'Öffnen'],
'image' => ['src' => '/bild.png', 'width' => 120, 'height' => 80, 'alt' => 'Bild', 'decorative' => false, 'click' => 'link'],
'iconcard' => ['title' => 'Karte', 'text' => '', 'icon' => 'star'],
'cta' => ['title' => 'Aufruf', 'text' => '', 'buttonText' => 'Öffnen'],
'icon' => ['icon' => 'star', 'size' => 24, 'decorative' => false, 'label' => 'Öffnen'],
];
foreach ($types as $type => $props) {
$document['blocks'][] = ['id' => 'new-'.$type, 'type' => $type, 'props' => [...$props, 'href' => '/kontakt', 'newTab' => true]];
}
$revision = $this->pages->saveDraft('page-1', $document, 0);
$this->pages->publish('page-1', $revision, 1);
$this->menus->save('header', 'Links', [['label' => 'Eltern', 'type' => 'url', 'url' => '/', 'newTab' => true, 'children' => [['label' => 'Kind', 'type' => 'url', 'url' => '/kontakt', 'newTab' => true]]]], 0);
$crawler = new \Symfony\Component\DomCrawler\Crawler($this->request('/')->getContent());
foreach (['#new-button', '#new-image a', '#new-iconcard a', '#new-cta a', '#new-icon'] as $selector) {
self::assertSame('_blank', $crawler->filter($selector)->attr('target'));
self::assertSame('noopener', $crawler->filter($selector)->attr('rel'));
}
self::assertCount(2, $crawler->filter('.site-header .menu-list a[target="_blank"][rel="noopener"]'));
$document['blocks'][array_key_last($document['blocks'])]['props']['newTab'] = 'yes';
$this->expectException(InvalidDocument::class);
(new DocumentValidator())->validate($document);
}
public function testNewTabAndRemovedBackgroundRequireSchemaTwenty(): void
{
foreach ([['type' => 'button', 'props' => ['text' => 'Link', 'href' => '/', 'newTab' => true]], ['type' => 'section', 'style' => ['tablet' => ['backgroundImage' => 'none']], 'children' => []]] as $block) {
$document = DemoContent::starter('Schema');
$document['schemaVersion'] = 19;
$document['blocks'][] = ['id' => 'new-option', ...$block];
try {
(new DocumentValidator())->validate($document);
self::fail('An explicit schema upgrade is required.');
} catch (InvalidDocument) {
$document['schemaVersion'] = 20;
(new DocumentValidator())->validate($document);
self::assertSame(20, $document['schemaVersion']);
}
}
}
public function testRemovingAnInheritedBackgroundAlsoRemovesItOnNarrowerDevices(): void
{
$id = str_repeat('a', 32);
$this->db->insert('media', ['id' => $id, 'title' => 'Klein', 'alt' => '', 'variants' => json_encode([['src' => '/media/'.$id.'/192', 'width' => 192, 'height' => 64, 'bytes' => 1]]), 'archived' => 0, 'version' => 1, 'created_at' => gmdate('Y-m-d H:i:s')]);
$compiler = new StyleCompiler(new MediaLibrary($this->db, $this->path.'-media'));
$document = ['blocks' => [['id' => 'background', 'style' => ['desktop' => ['backgroundImage' => $id], 'tablet' => ['backgroundImage' => 'none']]]]];
$css = $compiler->compileDocument($document);
self::assertStringContainsString('#background{background-image:url("/media/'.$id.'/192")}', $css);
self::assertStringContainsString('@media (max-width:1024px){#background{background-image:none}}', $css);
self::assertStringContainsString('@media (max-width:767px){#background{background-image:none}}', $css);
$document['blocks'][0]['style']['desktop'] += ['gradientFrom' => '#000000', 'gradientTo' => '#ffffff', 'gradientAngle' => 90];
$gradientCss = $compiler->compileDocument($document);
self::assertStringContainsString('@media (max-width:1024px){#background{background-image:linear-gradient(90deg,#000000,#ffffff)}}', $gradientCss);
self::assertStringContainsString('@media (max-width:767px){#background{background-image:linear-gradient(90deg,#000000,#ffffff)}}', $gradientCss);
unset($document['blocks'][0]['style']['tablet']);
self::assertStringNotContainsString('background-image:none', $compiler->compileDocument($document));
}
/**
* @return iterable<string, array{string, string}>
*/
@@ -2585,6 +2648,8 @@ final class CmsTest extends TestCase
yield 'removes an iframe' => ['<iframe src="https://evil.example"></iframe>ok', 'ok'];
yield 'closes unbalanced markup' => ['<strong>unge<em>schlossen', '<strong>unge<em>schlossen</em></strong>'];
yield 'keeps a local link' => ['<a href="/kontakt">hier</a>', '<a href="/kontakt">hier</a>'];
yield 'new local tab has no opener' => ['<a href="/kontakt" target="_blank" rel="opener">hier</a>', '<a href="/kontakt" target="_blank" rel="noopener">hier</a>'];
yield 'rejects named frames' => ['<a href="/kontakt" target="_top">hier</a>', '<a href="/kontakt">hier</a>'];
yield 'marks an external link' => ['<a href="https://example.com">dort</a>', '<a href="https://example.com" rel="noopener">dort</a>'];
yield 'escapes plain text and keeps the line break' => ["Eins <3\nZwei", 'Eins &lt;3<br>Zwei'];
}
+17 -1
View File
@@ -145,7 +145,7 @@ final class EditorSecurityTest extends WebTestCase
public function testLiveSearchDoesNotExposeContentToAnonymousRequests(): void
{
$client = self::createClient();
foreach (['/admin', '/admin/posts', '/admin/media'] as $url) {
foreach (['/admin', '/admin/posts', '/admin/media', '/admin/api/media/'.str_repeat('a', 32)] as $url) {
$client->request('GET', $url.'?q=secret', server: ['HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest', 'HTTP_ACCEPT' => 'application/json']);
self::assertResponseRedirects('http://localhost/admin/login');
self::assertStringNotContainsString('"html":', $client->getResponse()->getContent());
@@ -547,6 +547,22 @@ final class EditorSecurityTest extends WebTestCase
}
}
public function testMediaPreviewReadsSmallAndArchivedImagesWithoutListingTheLibrary(): void
{
$id = str_repeat('a', 32);
$this->db->insert('media', ['id' => $id, 'title' => 'Kleines Logo', 'alt' => 'Logo', 'variants' => json_encode([['src' => '/media/'.$id.'/192', 'width' => 192, 'height' => 64, 'bytes' => 1]]), 'archived' => 1, 'version' => 1, 'created_at' => gmdate('Y-m-d H:i:s')]);
$client = $this->login('editor');
$client->request('GET', '/admin/api/media/'.$id);
self::assertResponseIsSuccessful();
$data = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
self::assertSame($id, $data['item']['id']);
self::assertSame(192, $data['item']['variants'][0]['width']);
self::assertTrue($data['item']['archived']);
self::assertArrayNotHasKey('items', $data);
$client->request('GET', '/admin/api/media/'.str_repeat('b', 32));
self::assertResponseStatusCodeSame(404);
}
public function testTheMediaScreenUploadsAndEditsWithoutJavaScript(): void
{
$client = $this->login('editor');
+39
View File
@@ -305,6 +305,45 @@ test('free styles inherit from the wider device, reset individually and leave no
assert.deepEqual(history.document, fixture());
});
test('removing an inherited background upgrades the schema and can be reset or undone', () => {
const history = new EditorHistory(fixture());
history.change(doc => setStyle(doc, 's1', 'desktop', 'backgroundImage', 'a'.repeat(32)));
assert.equal(history.document.schemaVersion, 10);
history.change(doc => setStyle(doc, 's1', 'tablet', 'backgroundImage', 'none'));
const block = () => locate(history.document.blocks, 's1').block;
assert.equal(history.document.schemaVersion, 20);
assert.deepEqual(effectiveStyle(block(), 'mobile', 'backgroundImage'), { value: 'none', source: 'tablet' });
history.change(doc => setStyle(doc, 's1', 'tablet', 'backgroundImage', ''));
assert.deepEqual(effectiveStyle(block(), 'mobile', 'backgroundImage'), { value: 'a'.repeat(32), source: 'desktop' });
history.undo();
assert.equal(block().style.tablet.backgroundImage, 'none');
history.undo();
assert.equal(history.document.schemaVersion, 10);
});
test('replacing an image preserves its link, caption and layout and remains one undo step', () => {
const history = new EditorHistory(fixture());
const first = { id: 'a'.repeat(32), alt: 'First', variants: [{ src: '/media/a/192.webp', width: 192, height: 96 }] };
const second = { id: 'b'.repeat(32), alt: 'Second', variants: [{ src: '/media/b/480.webp', width: 480, height: 320 }] };
const galleryId = history.change(doc => insertMedia(doc, 's1', [first]));
const id = locate(history.document.blocks, galleryId).block.children[0].id;
history.change(doc => {
const block = locate(doc.blocks, id).block;
Object.assign(block.props, { href: '/kontakt', click: 'link', newTab: true, caption: 'Meine Bildunterschrift' });
setStyle(doc, id, 'desktop', 'width', '50%'); upgradeDocument(doc, 20);
});
const before = structuredClone(history.document);
history.change(doc => insertMedia(doc, id, [second]));
const replaced = locate(history.document.blocks, id).block;
assert.equal(replaced.props.mediaId, second.id);
assert.equal(replaced.props.width, 480); assert.equal(replaced.props.height, 320);
assert.equal(replaced.props.alt, 'Second'); assert.equal(replaced.props.href, '/kontakt');
assert.equal(replaced.props.click, 'link'); assert.equal(replaced.props.newTab, true);
assert.equal(replaced.props.caption, 'Meine Bildunterschrift');
assert.equal(replaced.style.desktop.width, '50%');
history.undo(); assert.deepEqual(history.document, before);
});
test('a row arrives with its columns, inside the selected container', () => {
const history = new EditorHistory(fixture());