feat: establish CHRNX block theme foundation
This commit is contained in:
21 files changed
+2394
-13
No files matched your search
@@ -0,0 +1,28 @@
|
||||
<?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' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap for the CHRNX theme.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
$chrnx_tests_dir = getenv( 'WP_TESTS_DIR' );
|
||||
|
||||
if ( ! $chrnx_tests_dir ) {
|
||||
$chrnx_tests_dir = '/wordpress-phpunit';
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
|
||||
define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__, 2 ) . '/vendor/yoast/phpunit-polyfills' );
|
||||
|
||||
require_once $chrnx_tests_dir . '/includes/functions.php';
|
||||
|
||||
/**
|
||||
* Activate the mapped theme before WordPress finishes bootstrapping.
|
||||
*/
|
||||
function chrnx_tests_load_theme() {
|
||||
switch_theme( 'chrnx' );
|
||||
}
|
||||
|
||||
tests_add_filter( 'muplugins_loaded', 'chrnx_tests_load_theme' );
|
||||
|
||||
require $chrnx_tests_dir . '/includes/bootstrap.php';
|
||||
@@ -41,5 +41,5 @@ test('PHP quality tools enforce the CHRNX conventions and cannot pass an empty s
|
||||
assert.match(phpcs, /name="prefixes"[^>]+value="chrnx_"/);
|
||||
assert.match(phpunit, /bootstrap="tests\/php\/bootstrap\.php"/);
|
||||
assert.match(phpunit, /failOnEmptyTestSuite="true"/);
|
||||
assert.match(phpunit, /<directory suffix="\.php">tests\/php<\/directory>/);
|
||||
assert.match(phpunit, /<directory suffix="Test\.php">tests\/php<\/directory>/);
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { access, readFile } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
const readProjectFile = (path) => readFile(new URL(`../../${path}`, import.meta.url), 'utf8');
|
||||
|
||||
test('Composer provides the PHPUnit Polyfills version required by WordPress tests', async () => {
|
||||
const composer = JSON.parse(await readProjectFile('composer.json'));
|
||||
const packageConfig = JSON.parse(await readProjectFile('package.json'));
|
||||
|
||||
assert.equal(composer['require-dev']['yoast/phpunit-polyfills'], '^2.0.5');
|
||||
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',
|
||||
);
|
||||
});
|
||||
|
||||
test('PHPUnit discovers native test filenames without treating bootstrap as a test', async () => {
|
||||
const config = await readProjectFile('phpunit.xml.dist');
|
||||
|
||||
assert.match(config, /<directory suffix="Test\.php">tests\/php<\/directory>/);
|
||||
await access(new URL('../../tests/php/ThemeSetupTest.php', import.meta.url));
|
||||
});
|
||||
|
||||
test('style.css declares the supported WordPress theme contract', async () => {
|
||||
const stylesheet = await readProjectFile('style.css');
|
||||
|
||||
assert.match(stylesheet, /^Theme Name:\s*CHRNX$/m);
|
||||
assert.match(stylesheet, /^Text Domain:\s*chrnx$/m);
|
||||
assert.match(stylesheet, /^Requires at least:\s*6\.9$/m);
|
||||
assert.match(stylesheet, /^Requires PHP:\s*8\.1$/m);
|
||||
});
|
||||
|
||||
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.version, 3);
|
||||
assert.equal(theme.settings.layout.contentSize, '720px');
|
||||
assert.equal(theme.settings.layout.wideSize, '1120px');
|
||||
});
|
||||
|
||||
test('theme.json exposes the complete dark and warm-light palette with stable semantic slugs', async () => {
|
||||
const theme = JSON.parse(await readProjectFile('theme.json'));
|
||||
const palette = Object.fromEntries(
|
||||
theme.settings.color.palette.map(({ slug, color }) => [slug, color.toUpperCase()]),
|
||||
);
|
||||
const expectedTokens = {
|
||||
night: '#0D1117',
|
||||
panel: '#161B22',
|
||||
violet: '#7C6CF0',
|
||||
green: '#5FB88A',
|
||||
text: '#E6EDF3',
|
||||
muted: '#8B949E',
|
||||
paper: '#F6F2E9',
|
||||
surface: '#FFFDF7',
|
||||
ink: '#25221F',
|
||||
'light-muted': '#625C54',
|
||||
'light-violet': '#674CA4',
|
||||
'light-green': '#327854',
|
||||
border: '#DED6C7',
|
||||
};
|
||||
|
||||
assert.deepEqual(palette, expectedTokens);
|
||||
});
|
||||
|
||||
test('the local Zen Maru Gothic files and license are present', async () => {
|
||||
await Promise.all([
|
||||
'assets/fonts/zen-maru-gothic-latin-500.woff2',
|
||||
'assets/fonts/zen-maru-gothic-latin-700.woff2',
|
||||
'assets/fonts/OFL.txt',
|
||||
].map((path) => access(new URL(`../../${path}`, import.meta.url))));
|
||||
});
|
||||
|
||||
test('the index template has header, semantic query content, and footer regions', async () => {
|
||||
const template = await readProjectFile('templates/index.html');
|
||||
|
||||
assert.match(template, /<!-- wp:template-part \{"slug":"header","tagName":"header"\} \/-->/);
|
||||
assert.match(template, /<!-- wp:group \{"tagName":"main"[^>]*-->/);
|
||||
assert.match(template, /<!-- wp:query\b/);
|
||||
assert.match(template, /<!-- wp:post-template -->/);
|
||||
assert.match(template, /<!-- wp:post-(?:content|excerpt)\b/);
|
||||
assert.match(template, /<!-- wp:template-part \{"slug":"footer","tagName":"footer"\} \/-->/);
|
||||
});
|
||||
Reference in new issue
Block a user