Files
preland/tests/check-theme-preference.php

21 lines
1.5 KiB
PHP

<?php
/** preland#13: local manual не переписывает рекламную UTM; строгий standalone canonical format. */
require dirname(__DIR__) . '/components/theme-preference.php';
$revision = str_repeat('a', 16);
$checks = 0;
foreach (['light','dark'] as $theme) foreach (['manual','preland'] as $source) {
$_COOKIE['theme_choice'] = "v1:$theme:$source:$revision";
if (prelandThemePreference() !== ['theme'=>$theme,'source'=>$source,'revision'=>$revision]
|| prelandThemeResolve($theme === 'light' ? 'dark' : 'light') !== $theme) throw new RuntimeException('Canonical preference не побеждает fallback');
$checks++;
}
foreach ([null, [], false, 1, '', "v1:light:manual:$revision\n", 'v1:dark:other:'.$revision, 'v1:dark:manual:'.str_repeat('a',15), 'v1:dark:manual:'.str_repeat('a',65), str_repeat('a',129)] as $value) {
$_COOKIE['theme_choice'] = $value;
if (prelandThemePreference() !== null || prelandThemeResolve('light') !== 'light') throw new RuntimeException('Невалидная preference принята');
$checks++;
}
$source = file_get_contents(dirname(__DIR__) . '/components/form.php');
if (!str_contains($source, 'const shownTheme = window.ZoomzillaTheme.current();')
|| !str_contains($source, "targetUrl += '&shown_theme=' + encodeURIComponent(shownTheme)")) throw new RuntimeException('Handoff должен читать показанную тему в момент навигации');
echo "OK: $checks standalone theme cases + dynamic shown_theme handoff\n";