'use strict'; const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const root = path.resolve(__dirname, '..', '..'); const read = (file) => fs.readFileSync(path.join(root, file), 'utf8'); const join = (files) => files.map(read).join('\n'); const articleFiles = [ 'src/Settings/PostDisplay.php', 'src/Admin/Schema/PostList/SchemaPostListList.php', 'src/Admin/Schema/SchemaPostList.php', 'assets/admin/src/schema/sections/post-list/list.js', 'assets/admin/src/schema/sections/post-list/thumb.js', 'assets/admin/src/schema/sections/post-list/page.js', 'inc/helpers/posts-renderer/config.php', 'inc/helpers/posts-renderer/post-data.php', 'inc/helpers/posts-renderer/markup.php', 'inc/helpers/aksrt-archive.php', 'inc/helpers/aksrt-single-render.php', ]; test('the article stream exposes only the new typed renderer contract', () => { const markup = read('inc/helpers/posts-renderer/markup.php'); const consumers = join([ 'index.php', 'category.php', 'tag.php', 'search.php', 'archive-resources.php', 'src/Admin/Admin.php', 'src/Admin/GlobalController.php', 'src/Core/Shortcodes.php', 'src/WidgetSystem/PostRenderer.php', 'inc/helpers/homepage/content.php', 'templates/parts/user-home/panel-posts.php', 'templates/parts/user-home/panel-favorites.php', ]); assert.match(markup, /function aksrt_render_post_list\(array \$args = \[\], \?WP_Query \$query = null, bool \$echo = true\): string/); assert.doesNotMatch(consumers, /function_exists\(['"]aksrt_render_post_list/); assert.doesNotMatch(consumers, /aksrt_render_post_list\(\s*\$query\s*,/); assert.doesNotMatch(consumers, /content-post-card|aksrt_homepage_render_post_card/); }); test('settings use legacy list modes, grouped options, and destructive related keys', () => { const source = join(articleFiles); const listSchema = read('assets/admin/src/schema/sections/post-list/list.js'); const pageSchema = read('assets/admin/src/schema/sections/post-list/page.js'); const legacyKeys = [ 'post_card_style', 'list_list_style', 'list_card_style', 'grid-cms', 'large_thumb', 'multi_thumb', 'layout_override', 'homepage_card_style', 'homepage_multi_thumb', 'homepage_default_view', 'post_related_enabled', 'post_related_count', 'post_related_style', 'post_related_source', 'post_related_title', ]; assert.match(listSchema, /list_type: 'thumb'/); for (const value of ['text', 'thumb', 'thumb_if_has', 'card']) { assert.match(listSchema, new RegExp(`value: '${value}'`)); } assert.match(listSchema, /list_list_option: \{ style: 'null', img_position: 'left', scale: 70 \}/); assert.match(listSchema, /list_card_option: \{ style: 'null', scale: 70 \}/); assert.match(pageSchema, /post_related_s: true/); assert.match(pageSchema, /post_related_type: 'img'/); assert.match(pageSchema, /related_title: '相关推荐'/); assert.match(pageSchema, /post_related_n: 6/); assert.match(pageSchema, /post_related_orderby: 'views'/); for (const key of legacyKeys) { assert.equal(source.includes(key), false, `legacy article key remains: ${key}`); } assert.doesNotMatch(source, /list_card_topics|is_topics|\btopics\b/); }); test('forced mode wins and thumb_if_has ignores spare and lazy placeholders', () => { const config = read('inc/helpers/posts-renderer/config.php'); const data = read('inc/helpers/posts-renderer/post-data.php'); const forced = config.indexOf("$is_forced = in_array($forced_type, ['list', 'card'], true)"); const globalCard = config.indexOf("$list_type === 'card'"); const contextCard = config.indexOf("$list['list_card_tag']"); const categoryCard = config.indexOf("$list['list_card_cat']"); assert.ok(forced >= 0 && forced < globalCard && globalCard < contextCard && contextCard < categoryCard); assert.match(config, /\$is_card = \$forced_type === 'card' \|\| \(!\$is_forced/); const hasReal = config.indexOf("$has_real = $primary !== '';"); const spareCall = config.lastIndexOf('aksrt_renderer_spare_image($thumb)'); const lazy = config.lastIndexOf('aksrt_get_lazy_thumb'); assert.ok(hasReal >= 0 && hasReal < spareCall && spareCall < lazy); assert.match(data, /'thumb_if_has' && empty\(\$images\['has_real'\]\)/); assert.match(data, /count\(\$gallery\) > 2/); assert.match(data, /has_post_format\(\['image', 'gallery'\]/); }); test('image resolution counts only content images and applies the configured WordPress size', () => { const config = read('inc/helpers/posts-renderer/config.php'); const data = read('inc/helpers/posts-renderer/post-data.php'); const thumbSchema = read('assets/admin/src/schema/sections/post-list/thumb.js'); const phpSchema = read('src/Admin/Schema/SchemaPostList.php'); assert.match(config, /function aksrt_renderer_content_images\(int \$post_id, string \$size\)/); assert.match(config, /strip_shortcodes\(\(string\) get_post_field\('post_content'/); assert.match(config, /\$slides = aksrt_renderer_curated_images\(\$post_id, \$size\);\s*\$gallery = aksrt_renderer_content_images\(\$post_id, \$size\);/); assert.match(config, /get_post_thumbnail_id\(\$post_id\).*aksrt_renderer_sized_image\(\(string\) \$thumbnail_id, \$size\)/s); assert.match(config, /aksrt_renderer_category_image\(\$post_id, \$size\)/); assert.doesNotMatch(config, /aksrt_get_post_gallery_images|cover_images|featured_video_episode|_aksrt_featured_video|_video_url|_aksrt_thumbnail_url|_thumbnail_url/); assert.doesNotMatch(config, /\['aksrt_category_cover_id',/); assert.match(data, /'gallery_count'\s*=>\s*count\(\$content_images\)/); assert.match(data, /\(int\) \$data\['gallery_count'\] - 4/); assert.match(thumbSchema, /spareThumbnailDefault = \[\{ img: `\$\{themeRoot\}\/assets\/img\/thumbnail\.svg` \}\]/); assert.match(phpSchema, /'spare_thumbnail'.*'default' => \[\['img' => get_template_directory_uri\(\) \. '\/assets\/img\/thumbnail\.svg'\]\]/); }); test('list, card, media, badge and Mini DOM follow dedicated legacy structures', () => { const markup = read('inc/helpers/posts-renderer/markup.php'); const data = read('inc/helpers/posts-renderer/post-data.php'); const card = markup.slice(markup.indexOf('function aksrt_renderer_card'), markup.indexOf('function aksrt_renderer_mini')); const mini = markup.slice(markup.indexOf('function aksrt_renderer_mini'), markup.indexOf('function aksrt_render_post')); assert.match(markup, /\['posts-item', 'list', 'ajax-item'\]/); assert.match(markup, /\$classes\[\] = .*'flex xx'.*'flex'/s); assert.match(markup, /
]+style=/); assert.match(data, /\['c-blue', 'c-yellow', 'c-green', 'c-purple', 'c-red'\]/); assert.match(data, /查看更多分类文章/); assert.match(data, /usort\(\$tags,.*->count.*->count/s); assert.match(data, /查看此标签更多文章/); const commentMeta = data.indexOf("aksrt_renderer_svg_icon('comment')"); const viewMeta = data.indexOf("aksrt_renderer_svg_icon('view')", commentMeta); const likeMeta = data.indexOf("aksrt_renderer_svg_icon('like')", viewMeta); assert.ok(commentMeta >= 0 && commentMeta < viewMeta && viewMeta < likeMeta); assert.match(data, /comments_open.*close_comments/s); assert.match(data, /show_like.*post_type.*=== 'post'/s); assert.match(data, /\s*'list'/); assert.match(author, /'no_author'\s*=>\s*true/); assert.match(author, /'no_margin'\s*=>\s*true/); assert.match(author, /'wrapper_class'\s*=>\s*'aksrt-user-home__post-list'/); assert.match(author, /aksrt_render_user_home_pagination\(\(int\) \$author_posts->max_num_pages, \(int\) \$posts_page\)/); assert.doesNotMatch(author, /aksrt_render_pagination|aksrt_render_profile_pagination|\$_GET|add_query_arg/); assert.match(widgets, /aksrt_render_mini_list/); assert.match(widgets, /swiper-container swiper-scroll/); }); test('AJAX pagination can recover, caps auto loading and rehydrates appended media', () => { const php = read('inc/helpers/template-tags/pagination-permissions.php'); const homepage = read('inc/helpers/homepage/content.php'); const admin = read('src/Admin/Admin.php'); const js = read('assets/js/core/pagination.js'); const ajaxList = read('assets/js/core/ajax-list.js'); const media = read('assets/js/core/misc.js'); assert.match(php, /class="text-center theme-pagination ajax-pag"/); assert.match(php, /class="next-page order-ajax-next ias-btn/); assert.doesNotMatch(php, /next-page ajax-next/); assert.match(php, /lazyload-action="ias"/); assert.match(js, /lazybeforeunveil/); assert.match(php, /class="post_ajax_loader"/); assert.match(php, /data-page-var/); assert.match(admin, /'author', 'author_name'/); assert.match(admin, /'category__in'.*'tag__in'/s); assert.match(admin, /\$query_vars\['paged'\] = \$page/); assert.match(js, /failed = false;\s*loadNextPage\(fromAuto\)/); assert.match(js, /successfulAutoLoads >= iasMax/); assert.match(js, /AksrtFrontend\.rehydrate\(target, "ajax"\)/); assert.match(js, /classList\.add\("lazyload"\)/); assert.match(homepage, /aksrt_render_pagination\(\$query,[\s\S]*?'query_context'\s*=>\s*\$contract\['query_context'\]/); assert.doesNotMatch(homepage, /href="javascript:;" class="ajax-next aksrt-load-more-btn"/); assert.match(ajaxList, /if \(link\.closest\("\[data-aksrt-pagination\], \.aksrt-comment-pagination"\)\) return;/); assert.match(media, /thumb-dplayer-playing/); assert.doesNotMatch(media, /new Swiper|data-post-thumb-slider/); assert.match(read('assets/js/runtime/main.min.js'), /new-swiper/); assert.match(media, /data-post-thumb-video/); assert.match(media, /window\.Grade\(container/); assert.match(media, /linear-gradient\(135deg/); assert.match(media, /aksrtGradientState/); assert.match(read('src/Core/ScriptsPart1c.php'), /'aksrt-grade'/); }); test('the pinned visual baseline records all source checksums', () => { const baseline = JSON.parse(read('tests/visual/zibll-9.0-article-baseline.json')); assert.equal(baseline.theme, 'Zibll'); assert.equal(baseline.version, '9.0'); const files = Object.values(baseline.files); assert.ok(files.length >= 6); for (const file of files) { assert.match(file.sha256, /^[a-f0-9]{64}$/); } }); test('single posts reserve a sidebar column only when its widget stack has content', () => { const layout = read('inc/helpers/template-tags/site-layout.php'); const single = read('inc/helpers/aksrt-single.php'); const aside = read('inc/helpers/aksrt-single-aside.php'); assert.match(layout, /if \(is_single\(\) && !aksrt_has_current_sidebar_widgets\(\)\) \{\s*return false;/); assert.match(single, /\$show_aside = get_post_type\(\$post_id\) === 'post'[\s\S]*?&& aksrt_is_show_sidebar\(\);/); assert.match(aside, /get_post_type\(\$post_id\) !== 'post' \|\| empty\(\$ctx\['show_aside'\]\)/); }); test('article visual matrix pins every breakpoint, state and strict threshold', () => { const matrix = JSON.parse(read('tests/visual/article-visual-matrix-v1.json')); assert.deepEqual(matrix.viewports.map((item) => item.width), [1440, 1024, 768, 767, 641, 640, 390]); assert.deepEqual(matrix.colorSchemes, ['light', 'dark']); assert.deepEqual(matrix.layouts, ['sidebar', 'no-sidebar']); assert.deepEqual(matrix.listModes, ['thumb', 'text', 'thumb_if_has', 'card']); assert.deepEqual(matrix.styles, ['default', 'style2', 'style3']); assert.ok(matrix.routes.some((route) => route.id === 'author-a')); assert.ok(matrix.routes.some((route) => route.states.includes('infinite'))); assert.ok(matrix.postScenarios.includes('no-image')); assert.ok(matrix.postScenarios.includes('multi')); assert.ok(matrix.postScenarios.includes('video')); assert.ok(matrix.postScenarios.includes('slides')); assert.equal(matrix.acceptance.dimensionDeltaPxMax, 1); assert.equal(matrix.acceptance.pixelDifferencePercentMax, 1.5); }); test('profile routes load versioned leaf styles and keep dialogs hidden initially', () => { const scripts = read('src/Core/ScriptsPart1b.php'); const accountModals = read('inc/helpers/user-center-renderers/profile-account-modals.php'); const settingsSecurity = read('inc/helpers/user-center-renderers/settings-security.php'); const userCenterJs = read('assets/js/routes/user-center.js'); const userHomeCss = read('assets/css/routes/user-home.css'); const profileLayoutCss = read('assets/css/routes/profile/layout.css'); const profileModalsCss = read('assets/css/routes/profile/modals.css'); assert.ok(scripts.includes("$profile_parts = ['layout', 'lists', 'modals'];")); for (const part of ['user-center/shell', 'user-center/credits', 'user-center/vip', 'user-center/level', 'user-center/settings', 'revenue', 'user-center/revenue', 'user-center/revenue-earnings', 'user-center/responsive']) { assert.ok(scripts.includes(`'${part}'`), `missing direct route leaf ${part}`); } assert.match(scripts, /assets\/css\/routes\/profile\/' \. \$part \. '\.css/); assert.match(scripts, /assets\/css\/routes\/' \. \$part \. '\.css/); assert.match(scripts, /filemtime\(\$part_path\)/); assert.doesNotMatch(scripts, /assets\/css\/routes\/profile\.css/); assert.doesNotMatch(scripts, /assets\/css\/routes\/user-center\.css/); assert.match(accountModals, /id="pwd-modal" class="aksrt-modal" hidden/); assert.match(accountModals, /id="email-modal" class="aksrt-modal" hidden/); assert.match(userCenterJs, /function closeModal\(m\)[\s\S]*?m\.hidden = true;/); assert.match(userHomeCss, /\.aksrt-profile-details-modal\[hidden\]\s*\{\s*display:\s*none\s*!important;\s*\}/); assert.match(userHomeCss, /\.aksrt-user-home \.aksrt-user-home__post-list \.posts-item\s*\{[^}]*background:\s*transparent;[^}]*box-shadow:\s*none;/); assert.match(userHomeCss, /@media \(min-width: 992px\)\s*\{[\s\S]*?\.aksrt-user-home \.aksrt-user-home__post-list\s*\{[^}]*display:\s*grid;[^}]*grid-template-columns:\s*repeat\(2,\s*minmax\(0,\s*1fr\)\);/); assert.match(userHomeCss, /@media \(min-width: 992px\)\s*\{[\s\S]*?\.aksrt-user-home \.aksrt-user-home__post-list > \.posts-item\s*\{[^}]*width:\s*auto;[^}]*margin:\s*0 !important;/); assert.match(userHomeCss, /@media \(max-width: 767px\)\s*\{[\s\S]*?\.aksrt-user-home \.aksrt-user-home__post-list \.posts-item\s*\{[^}]*padding:\s*10px 0;/); const panelFavorites = read('templates/parts/user-home/panel-favorites.php'); assert.match(panelFavorites, /aksrt_render_user_home_pagination\(\(int\) \$favorites_query->max_num_pages, \(int\) \$favorites_page\)/); assert.match(panelFavorites, /array_merge\(\$user_home_render_config, \['wrapper_class' => 'aksrt-user-home__post-list'\]\), \$favorites_query\)/); assert.doesNotMatch(panelFavorites, /profile-list-item|\$_GET|add_query_arg/); assert.match(profileLayoutCss, /\.aksrt-cover-menu__panel\[hidden\]\s*\{\s*display:\s*none\s*!important;\s*\}/); assert.match(profileLayoutCss, /#aksrt-bg-file-input\[hidden\],[\s\S]*?#aksrt-avatar-file-input\[hidden\][\s\S]*?display:\s*none\s*!important;/); assert.match(settingsSecurity, /data-modal="email-modal"[\s\S]*?<\/button>\s*<\/div>\s*
[\s\S]*?data-modal="phone-modal"/); assert.match(accountModals, /id="phone-modal" class="aksrt-modal" hidden role="dialog"[\s\S]*?aksrt-modal__overlay" data-close-modal[\s\S]*?aksrt-modal__box/); assert.match(accountModals, /id="phone-modal"[\s\S]*?class="modal-field modal-field--code"[\s\S]*?class="code-input-group"[\s\S]*?class="aksrt-modal__footer"/); assert.doesNotMatch(accountModals, /id="phone-modal"[\s\S]*?aksrt-modal__(?:dialog|body|actions)/); assert.match(profileModalsCss, /\.modal-field input\[type="tel"\]/); }); test('public user home stays param-free and swaps panels via REST fragments', () => { const ctx = read('inc/helpers/aksrt-user-home.php'); const shell = read('templates/pages/page-user-home.php'); const follow = read('templates/parts/user-home/panel-follow.php'); const comments = read('templates/parts/user-home/panel-comments.php'); const favorites = read('templates/parts/user-home/panel-favorites.php'); const rest = read('src/User/Home.php'); const authorJs = read('assets/js/author.js'); // Context builder owns no request state; pages default to 1. assert.doesNotMatch(ctx, /\$_GET/); assert.match(ctx, /function aksrt_render_user_home_pagination\(int \$total_pages, int \$current\): void/); assert.match(ctx, /data-uh-page/); assert.match(ctx, /function aksrt_capture_user_home_panel\(string \$tab, array \$ctx\): string/); // Shell mounts panel wrappers from the tab registry with a user id hook. assert.match(shell, /data-user-id="<\?php echo \(int\) \$user_id; \?>">/); assert.match(shell, /get_template_part\('templates\/parts\/user-home\/panel', \$panel_tab, \$ctx\)/); // Follow panel: button-driven sub-tabs, pagination without URL building. assert.match(follow, /data-uh-sub="followers"/); assert.match(follow, /data-uh-sub="following"/); assert.match(follow, /aksrt_render_user_home_pagination\(\$total_pages, \$follow_page\)/); assert.doesNotMatch(follow, /add_query_arg|\$_GET|paginate_links/); assert.match(comments, /aksrt_render_user_home_pagination\(/); assert.match(favorites, /aksrt_render_user_home_pagination\(/); assert.doesNotMatch(comments + favorites, /add_query_arg|\$_GET/); // REST fragment endpoint serves public panel bodies. assert.ok(rest.includes("'/user-home/panel/(?P\\d+)/(?P[a-z0-9_-]+)'")); assert.match(rest, /'permission_callback'\s*=>\s*'__return_true'/); assert.match(rest, /aksrt_capture_user_home_panel\(\$tab, \$context\)/); // Runtime never reads or writes URL params; fragments replace panel bodies. assert.doesNotMatch(authorJs, /searchParams|pushState|replaceState/); assert.match(authorJs, /\/user-home\/panel\/' \+ userId \+ '/); assert.match(authorJs, /data-uh-sub/); assert.match(authorJs, /AksrtFrontend\.rehydrate\(panel, 'ajax'\)/); });