'player.css', 'lamgc-asciiplayer-style' => 'style-index.css', 'lamgc-asciiplayer-editor-style' => 'index.css' ) as $handle => $file ) { same( $versions[ $file ], $GLOBALS['ap_test']['styles'][ $handle ]['version'], 'Each stylesheet uses its own content hash.' ); } } same( 'asciiplayer', $GLOBALS['ap_test']['shortcodes'][0][0], 'Legacy shortcode stays registered.' ); contains( '/build', $GLOBALS['ap_test']['blocks'][0]['path'], 'Block uses local metadata.' ); same( 'LamGC\\Asciiplayer\\render_block', $GLOBALS['ap_test']['blocks'][0]['args']['render_callback'], 'Block is server rendered.' ); foreach ( $GLOBALS['ap_test']['scripts'] as $script ) { contains( 'https://wordpress.test/wp-content/plugins/wp-asciiplayer/build/', $script['src'], 'Runtime JavaScript is locally bundled.' ); same( true, $script['footer'], 'Scripts load in footer.' ); } same( true, in_array( 'lamgc-asciiplayer-player', $GLOBALS['ap_test']['scripts']['lamgc-asciiplayer-view']['deps'], true ), 'Frontend adapter depends on local player.' ); same( true, in_array( 'wp-i18n', $GLOBALS['ap_test']['scripts']['lamgc-asciiplayer-view']['deps'], true ), 'Frontend translations dependency registered.' ); same( array( 'lamgc-asciiplayer-player-style' ), $GLOBALS['ap_test']['styles']['lamgc-asciiplayer-style']['deps'], 'Frontend style depends on player stylesheet.' ); contains( 'window.wpAsciiplayerSettings = ', $GLOBALS['ap_test']['inline_scripts'][0]['source'], 'Editor iframe receives trusted runtime URLs.' ); same( 'before', $GLOBALS['ap_test']['inline_scripts'][0]['position'], 'Settings are available before editor boot.' ); contains( 'player.js?ver=' . $GLOBALS['ap_test']['scripts']['lamgc-asciiplayer-player']['version'], $GLOBALS['ap_test']['inline_scripts'][0]['source'], 'Bridge JavaScript cache-buster matches registered asset version.' ); contains( 'player.css?ver=' . $GLOBALS['ap_test']['styles']['lamgc-asciiplayer-player-style']['version'], $GLOBALS['ap_test']['inline_scripts'][0]['source'], 'Bridge CSS cache-buster matches registered asset version.' ); // Source validation covers script, HTML, credential and relative-URL attacks. foreach ( array( '', 'javascript:alert(1)', 'data:text/html,test', 'file:///tmp/a.cast', '//evil.test/a.cast', '/\\evil.test/a.cast', "https://example.test/a\n.cast", 'https://x.test/" onmouseover="alert(1)', 'https://user:secret@example.test/a.cast', 'https:///a.cast', 'a.cast', array( 'bad' ) ) as $source ) { same( '', sanitize_source( $source ), 'Reject unsafe or unsupported source.' ); } foreach ( array( 'https://example.test/a.cast', 'http://example.test:8080/a.cast?x=1&y=2', '/wp-content/uploads/demo.cast', '/cast/demo.cast?x=1&y=2' ) as $source ) { same( $source, sanitize_source( $source ), 'Allow HTTP(S) or root-relative source.' ); } same( 'https://example.test/a.cast?a=1&b=2', sanitize_source( ' https://example.test/a.cast?a=1&b=2 ' ), 'Decode editor entities and trim outer whitespace.' ); foreach ( array( false, 'false', '0', 0, 'off', 'no' ) as $value ) { same( false, parse_boolean( $value ), 'Explicit false remains false.' ); } foreach ( array( true, 'true', '1', 1, 'on', 'yes' ) as $value ) { same( true, parse_boolean( $value ), 'Recognized true values.' ); } same( null, parse_boolean( 'garbage' ), 'Unrecognized bool is ignored.' ); same( null, parse_number( 'INF', 0, 100 ), 'Infinity is rejected.' ); same( null, parse_number( true, 0, 100 ), 'Boolean is not a numeric option.' ); same( null, parse_number( -1, 0, 100 ), 'Negative time is rejected.' ); same( 0.0, parse_time( '0' ), 'Zero start time is retained.' ); same( 123.0, parse_time( '2:03' ), 'Legacy mm:ss start time.' ); same( 3723.5, parse_time( '1:02:03.5' ), 'Legacy hh:mm:ss fractional time.' ); same( null, parse_time( '1:99' ), 'Invalid time components are rejected.' ); $attrs = normalize_attributes( array( 'autoplay' => 'false', 'startat' => '2:03', 'idle-time-limit' => '2', 'fontSize' => '15px', 'fontfamily' => "'Fira Code', monospace", 'lineheight' => 1.4, 'logger' => 'console', 'unknown' => 'bad', 0 => 'bare', 'rows' => array( 2 ) ) ); same( false, isset( $attrs['unknown'] ), 'Unknown attributes are discarded.' ); same( false, isset( $attrs['logger'] ), 'No executable logger objects.' ); same( false, isset( $attrs['rows'] ), 'Nested option values are discarded.' ); $options = player_options( $attrs ); same( false, $options['autoPlay'], 'Lowercase autoplay normalizes and respects false.' ); same( 123.0, $options['startAt'], 'Lowercase startAt normalizes.' ); same( 2.0, $options['idleTimeLimit'], 'Hyphenated idleTimeLimit normalizes.' ); same( '15px', $options['terminalFontSize'], 'Legacy font aliases map to current player options.' ); same( "'Fira Code', monospace", $options['terminalFontFamily'], 'Font lists survive safely.' ); same( 1.4, $options['terminalLineHeight'], 'Legacy lineHeight maps to current name.' ); $options = player_options( normalize_attributes( array( 'controls' => 'false', 'preload' => 'false', 'loop' => 'false', 'fit' => 'false' ) ) ); same( false, $options['controls'], 'controls=false is a boolean, never a truthy string.' ); same( false, $options['preload'], 'preload=false is retained.' ); same( false, $options['loop'], 'loop=false is retained.' ); same( 'none', $options['fit'], 'Legacy fit=false maps to none.' ); foreach ( array( 'always' => true, 'never' => false, 'auto' => 'auto' ) as $input => $expected ) { same( $expected, player_options( array( 'controls' => $input ) )['controls'], 'Block control enum converts to player API.' ); } same( 3, player_options( array( 'loop' => '3' ) )['loop'], 'Finite replay counts stay supported in shortcodes.' ); $options = player_options( array( 'speed' => -1, 'idleTimeLimit' => 0, 'cols' => 4.5, 'rows' => 1001, 'startAt' => -1, 'terminalFontSize' => '12px; color:red', 'terminalFontFamily' => 'url(https://bad.test)', 'theme' => 'x" onclick=bad', 'poster' => 'javascript:alert(1)' ) ); same( array( 'autoPlay' => false, 'preload' => true, 'fit' => 'width' ), $options, 'Invalid options omitted, safe defaults retained.' ); same( 'auto/dracula', player_options( array( 'theme' => 'auto/dracula' ) )['theme'], 'Player theme fallback syntax retained.' ); same( 'npt:1:23', player_options( array( 'poster' => 'npt:1:23' ) )['poster'], 'Safe NPT poster supported.' ); same( 'data:text/plain,', player_options( array( 'poster' => 'data:text/plain,' ) )['poster'], 'Plain terminal-text posters are supported.' ); reset_enqueues(); same( '', render_shortcode( array() ), 'Unclosed/empty shortcode returns no player.' ); same( '', render_player( array( 'source' => 'javascript:alert(1)' ) ), 'Invalid source emits no HTML.' ); same( array(), $GLOBALS['ap_test']['enqueued_scripts'], 'Invalid source does not enqueue assets.' ); $html = render_shortcode( array( 'controls' => 'false', 'autoPlay' => 'true', 'startAt' => '12', 'idleTimeLimit' => '2' ), 'https://example.test/demo.cast?a=1&b=2' ); contains( 'class="asciiplayer-container"', $html, 'Render adapter class.' ); contains( 'data-ap-src="https://example.test/demo.cast?a=1&b=2"', $html, 'URL is escaped for an HTML attribute.' ); same( false, options_from( $html )['controls'], 'Markup has typed JSON false.' ); same( true, options_from( $html )['autoPlay'], 'CamelCase boolean handled.' ); same( 12, options_from( $html )['startAt'], 'JSON numeric startAt.' ); same( 2, options_from( $html )['idleTimeLimit'], 'JSON numeric idleTimeLimit.' ); same( true, isset( $GLOBALS['ap_test']['enqueued_scripts']['lamgc-asciiplayer-view'] ), 'Every valid render requests the frontend adapter.' ); same( true, isset( $GLOBALS['ap_test']['enqueued_styles']['lamgc-asciiplayer-style'] ), 'Every valid render requests CSS.' ); $html = render_block( array( 'source' => '/demo.cast', 'poster' => 'data:text/plain,">', 'legacyStyle' => 'width:80%;color:red;background:url(javascript:alert(1))' ) ); same( false, false !== strpos( $html, '