fix(widgets): restore article table of contents behavior and styles
This commit is contained in:
1 parent
fc04bf65e6
commit
ea80cd96cc
15 files changed
+965
-407
No files matched your search
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/** Exercise the production TOC widget and article asset resolver. */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace AKSRT\Settings {
|
||||
final class Settings {
|
||||
public static function get_comment_display_settings(): array { return []; }
|
||||
}
|
||||
}
|
||||
|
||||
namespace AKSRT\WidgetSystem {
|
||||
final class AssetManager {
|
||||
public static function enqueue_for(WidgetDefinition $definition): void {}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
function get_post_meta(int $id, string $key, bool $single = false) { return $GLOBALS['toc_meta'][$key] ?? []; }
|
||||
function get_post_type(int $id): string { return 'post'; }
|
||||
function post_password_required(int $id): bool { return false; }
|
||||
function comments_open(int $id): bool { return false; }
|
||||
function get_comments_number(int $id): int { return 0; }
|
||||
function aksrt_resolve_single_post_display_settings(int $id): array { return $GLOBALS['toc_settings']; }
|
||||
class TocPost extends WP_Post { public string $post_content = '[dynamic_headings]'; }
|
||||
$GLOBALS['aksrt_test_state']['singular'] = true;
|
||||
$GLOBALS['aksrt_test_state']['current_id'] = 8;
|
||||
$GLOBALS['aksrt_test_state']['current_post'] = new TocPost(8);
|
||||
$GLOBALS['toc_settings'] = [];
|
||||
$GLOBALS['toc_meta'] = [];
|
||||
$resolver = new class {
|
||||
use \AKSRT\Core\ScriptsPart1c { resolve_singular_asset_requirements as public requirements; }
|
||||
};
|
||||
$cases = ['dynamic_headings' => $resolver->requirements(true, false, false)['has_toc']];
|
||||
$GLOBALS['toc_settings'] = ['article_nav' => false];
|
||||
$cases['global_disabled'] = $resolver->requirements(true, false, false)['has_toc'];
|
||||
$GLOBALS['toc_settings'] = ['article_nav' => true];
|
||||
$GLOBALS['toc_meta'][\AKSRT\Core\DomainModel::POST_META_KEY] = ['no_article-navs' => true];
|
||||
$cases['post_disabled'] = $resolver->requirements(true, false, false)['has_toc'];
|
||||
$GLOBALS['toc_meta'] = [];
|
||||
$cases['other_page'] = $resolver->requirements(false, false, false)['has_toc'];
|
||||
$definition = \AKSRT\WidgetSystem\WidgetRegistry::get('posts_toc');
|
||||
$cases['widget_fields'] = array_column($definition->fields(), 'id');
|
||||
$widget = new \AKSRT\WidgetSystem\SchemaWidget($definition);
|
||||
$widget->_set(2);
|
||||
ob_start();
|
||||
$widget->widget(['before_widget' => '<aside>', 'after_widget' => '</aside>'], ['title' => '目录 & 标题', 'mini_title' => '副标题', 'in_affix' => true]);
|
||||
$cases['widget'] = ob_get_clean();
|
||||
$GLOBALS['aksrt_test_state']['singular'] = false;
|
||||
ob_start();
|
||||
$widget->widget([], []);
|
||||
$cases['non_article_widget'] = ob_get_clean();
|
||||
echo json_encode($cases, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
|
||||
}
|
||||
Reference in new issue
Block a user