From ab305c98d16baea31d23764dcc8678b05a789639 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Tue, 11 Aug 2026 14:23:35 -0500 Subject: [PATCH] fix: harden CHRNX theme foundation --- package.json | 2 +- tests/php/ThemeSetupTest.php | 34 +++++++++++++++++++++++++++++ tests/smoke/theme-contract.test.mjs | 15 +++++++++++-- theme.json | 2 +- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fa6b499..430ab4e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "phpcs": "npm run composer -- exec phpcs -- -q", "test:smoke": "node --test tests/smoke/*.test.mjs", "test:js": "wp-scripts test-unit-js --runInBand", - "test:php": "wp-env run cli --env-cwd=wp-content/themes/chrnx composer exec phpunit", + "test:php": "wp-env run cli --env-cwd=wp-content/themes/chrnx -- composer exec phpunit --", "test:e2e": "playwright test", "lint:js": "wp-scripts lint-js assets/js tests/js scripts", "lint:css": "wp-scripts lint-style 'assets/css/**/*.css' 'blocks/**/*.css'", diff --git a/tests/php/ThemeSetupTest.php b/tests/php/ThemeSetupTest.php index abb13bc..f231ccb 100644 --- a/tests/php/ThemeSetupTest.php +++ b/tests/php/ThemeSetupTest.php @@ -25,4 +25,38 @@ class ThemeSetupTest extends WP_UnitTestCase { 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 ); + } + + /** + * 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 ); + } finally { + wp_dequeue_style( 'chrnx-base' ); + wp_deregister_style( 'chrnx-base' ); + } + } } diff --git a/tests/smoke/theme-contract.test.mjs b/tests/smoke/theme-contract.test.mjs index 912bed1..ac03cdb 100644 --- a/tests/smoke/theme-contract.test.mjs +++ b/tests/smoke/theme-contract.test.mjs @@ -12,7 +12,7 @@ test('Composer provides the PHPUnit Polyfills version required by WordPress test assert.equal(composer['require-dev']['phpunit/phpunit'], '^9.6'); assert.equal( packageConfig.scripts['test:php'], - 'wp-env run cli --env-cwd=wp-content/themes/chrnx composer exec phpunit', + 'wp-env run cli --env-cwd=wp-content/themes/chrnx -- composer exec phpunit --', ); }); @@ -32,10 +32,21 @@ test('style.css declares the supported WordPress theme contract', async () => { assert.match(stylesheet, /^Requires PHP:\s*8\.1$/m); }); +test('the stylesheet and PHP asset versions remain synchronized', async () => { + const stylesheet = await readProjectFile('style.css'); + const functions = await readProjectFile('functions.php'); + const stylesheetVersion = stylesheet.match(/^Version:\s*(\S+)$/m)?.[1]; + const phpVersion = functions.match(/define\( 'CHRNX_VERSION', '([^']+)' \);/)?.[1]; + + assert.ok(stylesheetVersion, 'style.css must declare Version metadata'); + assert.ok(phpVersion, 'functions.php must define the literal CHRNX_VERSION constant'); + assert.equal(phpVersion, stylesheetVersion); +}); + test('theme.json declares the v3 schema and layout widths', async () => { const theme = JSON.parse(await readProjectFile('theme.json')); - assert.equal(theme.$schema, 'https://schemas.wp.org/trunk/theme.json'); + assert.equal(theme.$schema, 'https://schemas.wp.org/wp/6.9/theme.json'); assert.equal(theme.version, 3); assert.equal(theme.settings.layout.contentSize, '720px'); assert.equal(theme.settings.layout.wideSize, '1120px'); diff --git a/theme.json b/theme.json index 705c164..78e7ffe 100644 --- a/theme.json +++ b/theme.json @@ -1,5 +1,5 @@ { - "$schema": "https://schemas.wp.org/trunk/theme.json", + "$schema": "https://schemas.wp.org/wp/6.9/theme.json", "version": 3, "settings": { "appearanceTools": true,