Message Board Tests - Source Excerpt 01
Summary
This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/antichrist-message-board/tests/message-board-tests.php so readers can inspect the evidence without opening the full source file.
**Source path:** Antichrist.net/wp-content/plugins/antichrist-message-board/tests/message-board-tests.php
<?php
/**
* Runtime unit tests for Antichrist.net Message Board.
*
* Run with:
* studio wp eval-file wp-content/plugins/antichrist-message-board/tests/message-board-tests.php
*
* @package AntichristMessageBoard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit( 1 );
}
if ( ! defined( 'ACNMB_DISABLE_RATE_LIMITS' ) ) {
define( 'ACNMB_DISABLE_RATE_LIMITS', true );
}
if ( ! function_exists( 'acnmb_insert_topic' ) ) {
fwrite( STDERR, "Antichrist.net Message Board plugin is not loaded.\n" );
exit( 1 );
}
$GLOBALS['acnmb_failures'] = array();
$GLOBALS['acnmb_cleanup_posts'] = array();
$GLOBALS['acnmb_cleanup_comments'] = array();
$GLOBALS['acnmb_cleanup_terms'] = array();
$GLOBALS['acnmb_cleanup_users'] = array();
/**
* Assert helper.
*
* @param bool $condition Condition.
* @param string $message Failure message.
* @throws Exception When assertion fails.
*/
function acnmb_test_assert( $condition, $message ) {
if ( ! $condition ) {
throw new Exception( $message );
}
}
/**
* Run one test.
*
* @param string $name Test name.
* @param callable $callback Test callback.
*/
function acnmb_test_case( $name, $callback ) {
global $acnmb_failures;
try {
call_user_func( $callback );
echo "PASS {$name}\n";
} catch ( Throwable $throwable ) {
$acnmb_failures[] = "{$name}: " . $throwable->getMessage();
echo "FAIL {$name}: " . $throwable->getMessage() . "\n";
}
}
/**
* Run a callback with a forced public locale.
*
* @param string $locale Locale tag.
* @param callable $callback Callback.
* @return mixed
*/
function acnmb_test_with_locale( $locale, $callback ) {
$locale_filter = function () use ( $locale ) {
return $locale;
};
add_filter( 'acnmb_current_locale', $locale_filter );
add_filter( 'acn_current_locale_tag', $locale_filter );
try {
return call_user_func( $callback );
} finally {
remove_filter( 'acnmb_current_locale', $locale_filter );
remove_filter( 'acn_current_locale_tag', $locale_filter );
}
}
/**
* Collapse rendered HTML to searchable text.
*
* @param string $html HTML.
* @return string
*/
function acnmb_test_rendered_text( $html ) {
return trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( (string) $html ) ) );
}
/**
* Create a disposable board test user.
*
* @return int
*/
function acnmb_test_create_user() {
global $acnmb_cleanup_users;
$user_id = wp_insert_user(
array(
'user_login' => 'acnmb_test_' . wp_generate_password( 8, false ),
'user_pass' => wp_generate_password( 20, true ),
'user_email' => 'acnmb-test-' . wp_generate_password( 6, false ) . '@example.test',
'display_name' => 'Board Test User',
'role' => 'subscriber',
)
);
acnmb_test_assert( ! is_wp_error( $user_id ), 'Could not create test user.' );
$acnmb_cleanup_users[] = (int) $user_id;
return (int) $user_id;
}
acnmb_register_content_types();
acnmb_seed_defaults();
acnmb_write_ns12_dictionaries();
acnmb_test_case(
'registers public topic type and hierarchical categories',
function () {
$taxonomy = get_taxonomy( ACNMB_CATEGORY_TAXONOMY );
acnmb_test_assert( post_type_exists( ACNMB_TOPIC_POST_TYPE ), 'Topic post type missing.' );
acnmb_test_assert( taxonomy_exists( ACNMB_CATEGORY_TAXONOMY ), 'Board category taxonomy missing.' );
acnmb_test_assert( $taxonomy && $taxonomy->hierarchical, 'Board category taxonomy is not hierarchical.' );
}
);
acnmb_test_case(
'seeds board page and default hierarchy',
function () {
$page = get_page_by_path( 'message-board' );
$research = get_term_by( 'slug', 'research', ACNMB_CATEGORY_TAXONOMY );
$texts = get_term_by( 'slug', 'texts-and-traditions', ACNMB_CATEGORY_TAXONOMY );
$pre_christian = get_term_by( 'slug', 'pre-christian-history', ACNMB_CATEGORY_TAXONOMY );
$eastern = get_term_by( 'slug', 'eastern-philosophy', ACNMB_CATEGORY_TAXONOMY );
$redeemer = get_term_by( 'slug', 'redeemer-claims', ACNMB_CATEGORY_TAXONOMY );
acnmb_test_assert( $page instanceof WP_Post, 'Message board page was not created.' );
acnmb_test_assert( false !== strpos( $page->post_content, '[acn_message_board]' ), 'Board page does not contain the shortcode.' );
acnmb_test_assert( $research instanceof WP_Term, 'Research category missing.' );
acnmb_test_assert( $texts instanceof WP_Term, 'Child category missing.' );
acnmb_test_assert( (int) $texts->parent === (int) $research->term_id, 'Child category parent is incorrect.' );
acnmb_test_assert( $pre_christian instanceof WP_Term, 'Pre-Christian category missing.' );
acnmb_test_assert( $eastern instanceof WP_Term, 'Eastern philosophy category missing.' );
acnmb_test_assert( $redeemer instanceof WP_Term, 'Redeemer claims category missing.' );
acnmb_test_assert( (int) $pre_christian->parent === (int) $research->term_id, 'Pre-Christian category parent is incorrect.' );
acnmb_test_assert( (int) $eastern->parent === (int) $research->term_id, 'Eastern philosophy category parent is incorrect.' );
acnmb_test_assert( (int) $redeemer->parent === (int) $research->term_id, 'Redeemer claims category parent is incorrect.' );
acnmb_test_assert( '' !== trim( $pre_christian->description ), 'Pre-Christian category description missing.' );
acnmb_test_assert( '' !== trim( $eastern->description ), 'Eastern philosophy category description missing.' );
acnmb_test_assert( '' !== trim( $redeemer->description ), 'Redeemer claims category description missing.' );
$general_ids = array();
foreach ( array( 'en-US', 'es-US', 'fr-FR', 'zh-CN' ) as $locale ) {
$localized_general = acnmb_category_term_for_base_slug( 'general', $locale );
$localized_research = acnmb_category_term_for_base_slug( 'research', $locale );
$localized_texts = acnmb_category_term_for_base_slug( 'texts-and-traditions', $locale );
acnmb_test_assert( $localized_general instanceof WP_Term, "{$locale} general category missing." );
acnmb_test_assert( $localized_research instanceof WP_Term, "{$locale} research category missing." );
acnmb_test_assert( $localized_texts instanceof WP_Term, "{$locale} texts category missing." );
acnmb_test_assert( $locale === acnmb_term_locale( $localized_general ), "{$locale} general category has wrong locale metadata." );
acnmb_test_assert( 'general' === acnmb_term_base_slug( $localized_general ), "{$locale} general category has wrong base slug." );
acnmb_test_assert( (int) $localized_texts->parent === (int) $localized_research->term_id, "{$locale} child category parent is incorrect." );
$general_ids[ $locale ] = (int) $localized_general->term_id;
}
acnmb_test_assert( count( array_unique( $general_ids ) ) === count( $general_ids ), 'Locale-specific general categories share the same term.' );
}
);
acnmb_test_case(
'keeps the locale switcher aligned with supported board locales',
function () {
if ( ! class_exists( '\UAIXLocaleRouter\LocaleRepository' ) && ! class_exists( '\Ns12LocaleRouter\LocaleRepository' ) ) {
return;
}
$repository = class_exists( '\UAIXLocaleRouter\LocaleRepository' ) ? '\UAIXLocaleRouter\LocaleRepository' : '\Ns12LocaleRouter\LocaleRepository';
$enabled = array();
foreach ( $repository::get_enabled_locales() as $record ) {
if ( ! empty( $record['tag'] ) ) {
$enabled[] = (string) $record['tag'];
}
}
$required = acnmb_required_locale_tags();
sort( $enabled );
sort( $required );
acnmb_test_assert( $required === $enabled, 'Locale switcher exposes unsupported locales: ' . implode( ', ', $enabled ) . '.' );
acnmb_test_assert( 'fr-FR' === acnmb_normalize_locale_tag( 'fr-FR' ), 'French locale should normalize to the French board.' );
acnmb_test_assert( 'fr-FR' === acnmb_normalize_locale_tag( 'fr_CA' ), 'French regional variants should normalize to the French board.' );
$current = acnmb_test_with_locale(
'fr-FR',
function () {
return acnmb_current_locale_tag();
}
);
acnmb_test_assert( 'fr-FR' === $current, 'Forced French locale should select the French board.' );
}
);
acnmb_test_case(
'rejects anonymous topic creation',
function () {
$term = acnmb_category_term_for_base_slug( 'general', 'en-US' );
$result = acnmb_insert_topic(
array(
'title' => 'Anonymous topic',
'content' => 'This should not be accepted.',
'category' => $term instanceof WP_Term ? $term->term_id : 0,
),
0
);
acnmb_test_assert( is_wp_error( $result ), 'Anonymous topic was accepted.' );
acnmb_test_assert( 'login_required' === $result->get_error_code(), 'Unexpected anonymous error code.' );
}
);
acnmb_test_case(
'creates logged-in topics with category assignment',
function () {
global $acnmb_cleanup_posts, $acnmb_cleanup_users;
$user_id = acnmb_test_create_user();
$term = acnmb_category_term_for_base_slug( 'general', 'en-US' );
acnmb_test_assert( $term instanceof WP_Term, 'General category missing.' );