Files
chrnxandClaude Opus 5 0a90e78783 fix: declare the language each post is actually written in
Half the journal is Spanish, but every route declared en-US, so screen
readers pronounced Spanish posts with English phonetics and crawlers
indexed them as English. The chrnx_language taxonomy already recorded the
answer per post and nothing read it.

Map its terms onto the html lang attribute for single posts and for the
language archives, replacing only the language so dir and any plugin
attribute survive. Posts with no language term keep the site default.

Also stop advertising a comments feed. Comments are unsupported theme-wide,
yet the head still linked one, because feed_links_extra also fires for old
posts carrying a non-zero comment_count. The core filter covers both that
and the site-wide link while leaving topic, author and search feeds alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-14 19:05:55 -05:00

147 lines
4.6 KiB
PHP

<?php
/**
* Tests for theme setup.
*
* @package CHRNX
*/
/**
* Verify the theme's WordPress setup contract.
*/
class ThemeSetupTest extends WP_UnitTestCase {
/**
* Ensure the required theme supports are registered.
*/
public function test_required_theme_supports_are_registered() {
$this->assertTrue( current_theme_supports( 'title-tag' ) );
$this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
$this->assertTrue( current_theme_supports( 'responsive-embeds' ) );
$this->assertTrue( current_theme_supports( 'editor-styles' ) );
}
/**
* Ensure the card crop is available to future card components.
*/
public function test_card_image_size_is_registered() {
$this->assertTrue( has_image_size( 'chrnx-card' ) );
}
/**
* Ensure the base stylesheet is available in the editor.
*/
public function test_base_editor_stylesheet_is_registered() {
global $editor_styles;
$this->assertContains( 'assets/css/base.css', $editor_styles );
$this->assertContains( 'assets/css/layout.css', $editor_styles );
$this->assertContains( 'assets/css/components.css', $editor_styles );
}
/**
* Ensure a Spanish post declares a Spanish document language.
*/
public function test_language_attributes_follow_a_spanish_post() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_singular( 'post' ) );
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure an English post keeps the English document language.
*/
public function test_language_attributes_follow_an_english_post() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'en', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the direction attribute survives the language swap.
*/
public function test_language_attributes_preserve_other_attributes() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="es-MX" dir="ltr"', chrnx_filter_language_attributes( 'lang="en-US" dir="ltr"' ) );
}
/**
* Ensure a post without a language term is left untouched.
*/
public function test_language_attributes_ignore_a_post_without_a_language() {
$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure a language archive declares the language it lists.
*/
public function test_language_attributes_follow_a_language_archive() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_term_link( 'es', 'chrnx_language' ) );
$this->assertTrue( is_tax( 'chrnx_language' ) );
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the home page keeps the site language.
*/
public function test_language_attributes_leave_the_home_page_alone() {
$this->go_to( home_url( '/' ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the head never advertises a comments feed the theme cannot render.
*/
public function test_comments_feed_is_not_advertised() {
$this->assertFalse( apply_filters( 'feed_links_show_comments_feed', true ) );
}
/**
* Ensure the local base stylesheet is enqueued with the theme version.
*/
public function test_base_stylesheet_is_enqueued_locally_with_theme_version() {
wp_dequeue_style( 'chrnx-base' );
wp_deregister_style( 'chrnx-base' );
try {
do_action( 'wp_enqueue_scripts' );
$styles = wp_styles();
$this->assertTrue( wp_style_is( 'chrnx-base', 'enqueued' ) );
$this->assertArrayHasKey( 'chrnx-base', $styles->registered );
$base = $styles->registered['chrnx-base'];
$this->assertSame( get_theme_file_uri( 'assets/css/base.css' ), $base->src );
$this->assertSame( CHRNX_VERSION, $base->ver );
$this->assertTrue( wp_style_is( 'chrnx-layout', 'enqueued' ) );
$this->assertSame( array( 'chrnx-base' ), $styles->registered['chrnx-layout']->deps );
$this->assertSame( get_theme_file_uri( 'assets/css/layout.css' ), $styles->registered['chrnx-layout']->src );
} finally {
wp_dequeue_style( 'chrnx-base' );
wp_deregister_style( 'chrnx-base' );
wp_dequeue_style( 'chrnx-layout' );
wp_deregister_style( 'chrnx-layout' );
}
}
}