fix: harden CHRNX theme foundation
This commit is contained in:
4 files changed
+49
-4
No files matched your search
+1
-1
@@ -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'",
|
||||
|
||||
@@ -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' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user