set_404(); status_header( 404 ); update_option( 'fe_custom_message', '

Sorry, we moved things around.

' ); update_option( 'fe_enabled_post_types', array( 'post', 'page' ) ); update_option( 'fe_suggestions_per_page', 3 ); ob_start(); include __DIR__ . '/templates/404.php'; $html = ob_get_clean(); $fail = 0; function check( $label, $cond, $extra = '' ) { global $fail; if ( ! $cond ) { $fail++; } printf( "%s %-52s %s\n", $cond ? 'PASS' : 'FAIL', $label, $extra ); } check( 'renders without fatal', strlen( $html ) > 500, 'len=' . strlen( $html ) ); check( 'has .fe-404 wrapper', false !== strpos( $html, 'class="fe-404"' ) ); check( 'has heading', false !== strpos( $html, 'fe-404-heading' ) ); check( 'shows requested path', false !== strpos( $html, '/this-page-does-not-exist-2024/' ) ); check( 'shows custom message', false !== strpos( $html, 'Sorry, we moved things around.' ) ); check( 'has search form', false !== strpos( $html, 'fe-search-form' ) && false !== strpos( $html, 'name="s"' ) ); check( 'search prefilled from URL tokens', false !== strpos( $html, 'value="this does exist 2024"' ), '' ); check( 'has did-you-mean or sections container', false !== strpos( $html, 'fe-did-you-mean' ) || false !== strpos( $html, 'fe-section' ) ); check( 'stylesheet enqueued on 404', wp_style_is( 'fe-404', 'enqueued' ), '' ); check( 'no PHP warnings in output', false === strpos( $html, 'Warning:' ) && false === strpos( $html, 'Fatal error' ) && false === strpos( $html, 'Notice:' ) ); echo $fail ? "\nRENDER RESULT: $fail FAILURES\n" : "\nRENDER RESULT: ALL PASS\n"; exit( $fail ? 1 : 0 );