style: integrate CHRNX navigation and footer
This commit is contained in:
8 files changed
+437
-26
No files matched your search
+15
-1
@@ -11,6 +11,7 @@
|
||||
|
||||
html {
|
||||
color-scheme: dark;
|
||||
--chrnx-focus-ring: var(--wp--preset--color--green);
|
||||
}
|
||||
|
||||
body {
|
||||
@@ -39,8 +40,21 @@ a:hover {
|
||||
}
|
||||
|
||||
:focus-visible {
|
||||
outline: 3px solid var(--wp--preset--color--green);
|
||||
border-radius: 0.4rem;
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 3px;
|
||||
box-shadow: 0 0 0 3px var(--chrnx-focus-ring);
|
||||
}
|
||||
|
||||
html[data-theme="light"] {
|
||||
--chrnx-focus-ring: var(--wp--preset--color--light-green);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) {
|
||||
--chrnx-focus-ring: var(--wp--preset--color--light-green);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
@@ -83,7 +83,66 @@ footer a {
|
||||
|
||||
.chrnx-primary-navigation a,
|
||||
.chrnx-footer-navigation a {
|
||||
color: var(--chrnx-link);
|
||||
position: relative;
|
||||
color: var(--chrnx-muted);
|
||||
font-family: var(--wp--preset--font-family--heading);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.035em;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation a::after,
|
||||
.chrnx-footer-navigation a::after {
|
||||
position: absolute;
|
||||
right: 0.55rem;
|
||||
bottom: 0.3rem;
|
||||
left: 0.55rem;
|
||||
height: 2px;
|
||||
border-radius: 999px;
|
||||
background: currentcolor;
|
||||
content: "";
|
||||
opacity: 0;
|
||||
transform: scaleX(0.35);
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation a:hover,
|
||||
.chrnx-primary-navigation a:focus-visible,
|
||||
.chrnx-primary-navigation a[aria-current="page"],
|
||||
.chrnx-footer-navigation a:hover,
|
||||
.chrnx-footer-navigation a:focus-visible,
|
||||
.chrnx-footer-navigation a[aria-current="page"] {
|
||||
color: var(--chrnx-green);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.chrnx-primary-navigation a:hover::after,
|
||||
.chrnx-primary-navigation a:focus-visible::after,
|
||||
.chrnx-primary-navigation a[aria-current="page"]::after,
|
||||
.chrnx-footer-navigation a:hover::after,
|
||||
.chrnx-footer-navigation a:focus-visible::after,
|
||||
.chrnx-footer-navigation a[aria-current="page"]::after {
|
||||
opacity: 1;
|
||||
transform: scaleX(1);
|
||||
}
|
||||
|
||||
.chrnx-site-footer__site {
|
||||
font-family: var(--wp--preset--font-family--heading);
|
||||
font-size: var(--wp--preset--font-size--large);
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.chrnx-site-footer__site a {
|
||||
color: var(--chrnx-text);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.chrnx-site-footer__credit,
|
||||
.chrnx-site-footer__line {
|
||||
color: var(--chrnx-muted);
|
||||
font-family: var(--wp--preset--font-family--metadata);
|
||||
}
|
||||
|
||||
.wp-site-blocks h1,
|
||||
|
||||
+5
-18
@@ -70,6 +70,7 @@ html[data-theme="light"] header.wp-block-template-part {
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-block: clamp(1.5rem, 3vw, 2.5rem);
|
||||
}
|
||||
|
||||
.chrnx-skip-link {
|
||||
@@ -257,17 +258,18 @@ main#chrnx-main {
|
||||
|
||||
footer.wp-block-template-part {
|
||||
margin-top: var(--wp--preset--spacing--60);
|
||||
border-top: 1px solid color-mix(in srgb, var(--wp--preset--color--muted) 40%, transparent);
|
||||
border-top: 2px solid var(--chrnx-line);
|
||||
background: var(--chrnx-surface);
|
||||
}
|
||||
|
||||
html[data-theme="light"] footer.wp-block-template-part {
|
||||
border-top-color: var(--wp--preset--color--border);
|
||||
border-top-color: var(--chrnx-line);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) footer.wp-block-template-part {
|
||||
border-top-color: var(--wp--preset--color--border);
|
||||
border-top-color: var(--chrnx-line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,21 +457,6 @@ html[data-theme="light"] footer.wp-block-template-part {
|
||||
min-height: 44px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
html[data-theme="light"] .chrnx-header-search button:focus-visible,
|
||||
html[data-theme="light"] .chrnx-theme-control > [data-chrnx-theme-button]:focus-visible,
|
||||
html[data-theme="light"] .chrnx-mobile-menu-toggle:focus-visible {
|
||||
outline-color: var(--wp--preset--color--light-green);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
|
||||
:root:not([data-theme]) .chrnx-header-search button:focus-visible,
|
||||
:root:not([data-theme]) .chrnx-theme-control > [data-chrnx-theme-button]:focus-visible,
|
||||
:root:not([data-theme]) .chrnx-mobile-menu-toggle:focus-visible {
|
||||
outline-color: var(--wp--preset--color--light-green);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
|
||||
@@ -28,6 +28,7 @@ $chrnx_footer_links = array(
|
||||
),
|
||||
);
|
||||
$chrnx_site_name = get_bloginfo( 'name' );
|
||||
$chrnx_current_url = chrnx_get_current_navigation_destination();
|
||||
$chrnx_copyright = sprintf(
|
||||
/* translators: 1: current year, 2: site name. */
|
||||
__( '© %1$s %2$s', 'chrnx' ),
|
||||
@@ -46,7 +47,7 @@ $chrnx_copyright = sprintf(
|
||||
<nav class="chrnx-footer-navigation" aria-label="<?php echo esc_attr__( 'Footer navigation', 'chrnx' ); ?>">
|
||||
<ul>
|
||||
<?php foreach ( $chrnx_footer_links as $chrnx_link ) : ?>
|
||||
<li><a href="<?php echo esc_url( $chrnx_link['url'] ); ?>"><?php echo esc_html( $chrnx_link['label'] ); ?></a></li>
|
||||
<li><a href="<?php echo esc_url( $chrnx_link['url'] ); ?>"<?php echo $chrnx_current_url === $chrnx_link['url'] ? ' aria-current="page"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Fixed attribute fragment. ?>><?php echo esc_html( $chrnx_link['label'] ); ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -30,11 +30,12 @@ $chrnx_header_links = array(
|
||||
$chrnx_search_label = __( 'Search', 'chrnx' );
|
||||
$chrnx_search_id = wp_unique_id( 'chrnx-search-' );
|
||||
$chrnx_search_panel_id = wp_unique_id( 'chrnx-search-panel-' );
|
||||
$chrnx_current_url = chrnx_get_current_navigation_destination();
|
||||
?>
|
||||
<nav id="chrnx-primary-navigation" class="chrnx-primary-navigation" aria-label="<?php echo esc_attr__( 'Primary navigation', 'chrnx' ); ?>">
|
||||
<ul>
|
||||
<?php foreach ( $chrnx_header_links as $chrnx_link ) : ?>
|
||||
<li><a href="<?php echo esc_url( $chrnx_link['url'] ); ?>"><?php echo esc_html( $chrnx_link['label'] ); ?></a></li>
|
||||
<li><a href="<?php echo esc_url( $chrnx_link['url'] ); ?>"<?php echo $chrnx_current_url === $chrnx_link['url'] ? ' aria-current="page"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Fixed attribute fragment. ?>><?php echo esc_html( $chrnx_link['label'] ); ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -17,6 +17,39 @@ function chrnx_get_heading_level( $value, $fallback_level = 2 ) {
|
||||
return in_array( $level, array( 2, 3, 4, 5, 6 ), true ) ? $level : $fallback_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the canonical primary-navigation URL for the current main query.
|
||||
*
|
||||
* @return string Current navigation destination URL, or an empty string.
|
||||
*/
|
||||
function chrnx_get_current_navigation_destination() {
|
||||
$journal_url = home_url( '/journal/' );
|
||||
|
||||
if ( is_404() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( is_home() || is_search() || is_singular( 'post' ) || is_tax( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) ) ) {
|
||||
return $journal_url;
|
||||
}
|
||||
|
||||
if ( is_front_page() || ! is_page() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$page = get_queried_object();
|
||||
if ( ! $page instanceof WP_Post || 'page' !== $page->post_type ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$page_uri = get_page_uri( $page );
|
||||
if ( ! in_array( $page_uri, array( 'journal', 'projects', 'music', 'podcasts', 'about' ), true ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return home_url( '/' . $page_uri . '/' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate localized reading time from stored post content without rendering it.
|
||||
*
|
||||
|
||||
@@ -89,6 +89,22 @@ function contrastRatio( first, second ) {
|
||||
return ( lighter + 0.05 ) / ( darker + 0.05 );
|
||||
}
|
||||
|
||||
function firstComputedColor( value ) {
|
||||
return value.match( /(?:rgba?\([^)]*\)|color\(srgb[^)]*\))/ )?.[ 0 ] ?? '';
|
||||
}
|
||||
|
||||
function colorAlpha( value ) {
|
||||
if ( value === 'transparent' ) {
|
||||
return 0;
|
||||
}
|
||||
const slashAlpha = value.match( /\/\s*([\d.]+)\s*\)$/ );
|
||||
if ( slashAlpha ) {
|
||||
return Number.parseFloat( slashAlpha[ 1 ] );
|
||||
}
|
||||
const channels = value.match( /[\d.]+/g )?.map( Number ) ?? [];
|
||||
return value.startsWith( 'rgba(' ) && channels.length >= 4 ? channels[ 3 ] : 1;
|
||||
}
|
||||
|
||||
async function expectContainedTarget( locator, viewportWidth ) {
|
||||
const box = await getBox( locator );
|
||||
expect( box.x ).toBeGreaterThanOrEqual( 0 );
|
||||
@@ -98,6 +114,123 @@ async function expectContainedTarget( locator, viewportWidth ) {
|
||||
}
|
||||
|
||||
test.describe( 'site navigation shell', () => {
|
||||
for ( const theme of [ 'light', 'dark' ] ) {
|
||||
test( `${ theme } navigation and footer expose the integrated editorial treatment`, async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.setViewportSize( { width: 1280, height: 800 } );
|
||||
await page.goto( '/' );
|
||||
await page.evaluate( ( value ) => localStorage.setItem( 'chrnx-theme', value ), theme );
|
||||
await page.goto( '/music/' );
|
||||
await expect( page.locator( 'html' ) ).toHaveAttribute( 'data-theme', theme );
|
||||
|
||||
const header = page.getByRole( 'banner' );
|
||||
const footer = page.getByRole( 'contentinfo' );
|
||||
const headerNav = header.getByRole( 'navigation', { name: 'Primary navigation' } );
|
||||
const footerNav = footer.getByRole( 'navigation', { name: 'Footer navigation' } );
|
||||
for ( const nav of [ headerNav, footerNav ] ) {
|
||||
const current = nav.getByRole( 'link', { name: 'Music', exact: true } );
|
||||
await expect( nav.locator( '[aria-current="page"]' ) ).toHaveCount( 1 );
|
||||
await expect( current ).toHaveAttribute( 'aria-current', 'page' );
|
||||
const currentStyle = await current.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const marker = window.getComputedStyle( element, '::after' );
|
||||
const surface = window.getComputedStyle( element.closest( 'header, footer' ) );
|
||||
return {
|
||||
color: style.color,
|
||||
decoration: style.textDecorationLine,
|
||||
fontFamily: style.fontFamily,
|
||||
fontWeight: Number.parseInt( style.fontWeight, 10 ),
|
||||
fontSize: Number.parseFloat( style.fontSize ),
|
||||
letterSpacing: Number.parseFloat( style.letterSpacing ),
|
||||
markerContent: marker.content,
|
||||
markerWidth: Number.parseFloat( marker.width ),
|
||||
markerHeight: Number.parseFloat( marker.height ),
|
||||
markerOpacity: Number.parseFloat( marker.opacity ),
|
||||
surface: surface.backgroundColor,
|
||||
};
|
||||
} );
|
||||
expect( currentStyle.decoration ).toBe( 'none' );
|
||||
expect( currentStyle.fontFamily ).toContain( 'Zen Maru Gothic' );
|
||||
expect( currentStyle.fontWeight ).toBe( 500 );
|
||||
expect( currentStyle.fontSize ).toBeLessThanOrEqual( 16 );
|
||||
expect( currentStyle.letterSpacing ).toBeGreaterThan( 0 );
|
||||
expect( contrastRatio( currentStyle.color, currentStyle.surface ) ).toBeGreaterThanOrEqual(
|
||||
4.5,
|
||||
);
|
||||
expect( currentStyle.markerContent ).not.toBe( 'none' );
|
||||
expect( currentStyle.markerWidth ).toBeGreaterThan( 0 );
|
||||
expect( currentStyle.markerHeight ).toBeGreaterThanOrEqual( 2 );
|
||||
expect( currentStyle.markerOpacity ).toBe( 1 );
|
||||
|
||||
const hover = nav.getByRole( 'link', { name: 'Projects', exact: true } );
|
||||
await hover.hover();
|
||||
const hoverStyle = await hover.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const marker = window.getComputedStyle( element, '::after' );
|
||||
const surface = window.getComputedStyle( element.closest( 'header, footer' ) );
|
||||
return {
|
||||
color: style.color,
|
||||
decoration: style.textDecorationLine,
|
||||
markerOpacity: Number.parseFloat( marker.opacity ),
|
||||
surface: surface.backgroundColor,
|
||||
};
|
||||
} );
|
||||
expect( hoverStyle.decoration ).toBe( 'none' );
|
||||
expect( hoverStyle.markerOpacity ).toBe( 1 );
|
||||
expect( contrastRatio( hoverStyle.color, hoverStyle.surface ) ).toBeGreaterThanOrEqual(
|
||||
4.5,
|
||||
);
|
||||
}
|
||||
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( 'header [aria-current], footer [aria-current]' ) ).toHaveCount(
|
||||
0,
|
||||
);
|
||||
await page.goto( '/music/' );
|
||||
const footerStyle = await footer.evaluate( ( element ) => {
|
||||
const style = window.getComputedStyle( element );
|
||||
const innerStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__inner' ),
|
||||
);
|
||||
const siteStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__site' ),
|
||||
);
|
||||
const creditStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__credit' ),
|
||||
);
|
||||
const lineStyle = window.getComputedStyle(
|
||||
element.querySelector( '.chrnx-site-footer__line' ),
|
||||
);
|
||||
return {
|
||||
background: style.backgroundColor,
|
||||
borderStyle: style.borderTopStyle,
|
||||
borderWidth: Number.parseFloat( style.borderTopWidth ),
|
||||
borderColor: style.borderTopColor,
|
||||
paddingTop: Number.parseFloat( innerStyle.paddingTop ),
|
||||
paddingBottom: Number.parseFloat( innerStyle.paddingBottom ),
|
||||
siteFamily: siteStyle.fontFamily,
|
||||
siteWeight: Number.parseInt( siteStyle.fontWeight, 10 ),
|
||||
siteSize: Number.parseFloat( siteStyle.fontSize ),
|
||||
creditFamily: creditStyle.fontFamily,
|
||||
creditSize: Number.parseFloat( creditStyle.fontSize ),
|
||||
lineFamily: lineStyle.fontFamily,
|
||||
};
|
||||
} );
|
||||
expect( colorAlpha( footerStyle.background ) ).toBe( 1 );
|
||||
expect( footerStyle.borderStyle ).not.toBe( 'none' );
|
||||
expect( footerStyle.borderWidth ).toBeGreaterThanOrEqual( 1 );
|
||||
expect( colorAlpha( footerStyle.borderColor ) ).toBeGreaterThan( 0 );
|
||||
expect( footerStyle.paddingTop ).toBeGreaterThanOrEqual( 24 );
|
||||
expect( footerStyle.paddingBottom ).toBeGreaterThanOrEqual( 24 );
|
||||
expect( footerStyle.siteFamily ).toContain( 'Zen Maru Gothic' );
|
||||
expect( footerStyle.siteWeight ).toBeGreaterThanOrEqual( 700 );
|
||||
expect( footerStyle.siteSize ).toBeGreaterThan( footerStyle.creditSize );
|
||||
expect( footerStyle.creditFamily ).toMatch( /monospace|Menlo|Monaco|Consolas/ );
|
||||
expect( footerStyle.lineFamily ).toBe( footerStyle.creditFamily );
|
||||
} );
|
||||
}
|
||||
|
||||
test( 'desktop has a stable accessible header, approved local brand, and compact footer', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
@@ -405,7 +538,7 @@ test.describe( 'site navigation shell', () => {
|
||||
}
|
||||
|
||||
for ( const colorScheme of [ 'light', 'dark' ] ) {
|
||||
test( `compact mobile header has contrasting ${ colorScheme } focus outlines`, async ( {
|
||||
test( `compact mobile header has contrasting rounded ${ colorScheme } focus halos`, async ( {
|
||||
page,
|
||||
} ) => {
|
||||
await page.emulateMedia( { colorScheme } );
|
||||
@@ -427,15 +560,20 @@ test.describe( 'site navigation shell', () => {
|
||||
const controlStyle = window.getComputedStyle( element );
|
||||
const headerStyle = window.getComputedStyle( element.closest( 'header' ) );
|
||||
return {
|
||||
boxShadow: controlStyle.boxShadow,
|
||||
borderRadius: Number.parseFloat( controlStyle.borderRadius ),
|
||||
outline: controlStyle.outlineColor,
|
||||
outlineStyle: controlStyle.outlineStyle,
|
||||
outlineWidth: Number.parseFloat( controlStyle.outlineWidth ),
|
||||
background: headerStyle.backgroundColor,
|
||||
};
|
||||
} );
|
||||
const halo = firstComputedColor( colors.boxShadow );
|
||||
expect( colors.boxShadow ).not.toBe( 'none' );
|
||||
expect( halo ).not.toBe( '' );
|
||||
expect( colors.borderRadius ).toBeGreaterThan( 0 );
|
||||
expect( colors.outlineStyle ).not.toBe( 'none' );
|
||||
expect( colors.outlineWidth ).toBeGreaterThanOrEqual( 3 );
|
||||
expect( contrastRatio( colors.outline, colors.background ) ).toBeGreaterThanOrEqual( 3 );
|
||||
expect( colorAlpha( colors.outline ) ).toBe( 0 );
|
||||
expect( contrastRatio( halo, colors.background ) ).toBeGreaterThanOrEqual( 3 );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -175,6 +175,171 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
$this->assertStringNotContainsString( '<form', $output );
|
||||
}
|
||||
|
||||
/** Exact destination pages map to their canonical local navigation URLs. */
|
||||
public function test_current_navigation_destination_maps_exact_destination_pages() {
|
||||
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
|
||||
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
|
||||
return;
|
||||
}
|
||||
foreach ( array( 'journal', 'projects', 'music', 'podcasts', 'about' ) as $slug ) {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => $slug,
|
||||
'post_title' => ucfirst( $slug ),
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $page_id ) );
|
||||
$this->assertSame( home_url( '/' . $slug . '/' ), chrnx_get_current_navigation_destination(), $slug );
|
||||
}
|
||||
}
|
||||
|
||||
/** Editorial requests all map to Journal, including every public editorial taxonomy. */
|
||||
public function test_current_navigation_destination_maps_all_journal_contexts() {
|
||||
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
|
||||
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
|
||||
return;
|
||||
}
|
||||
$post_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'journal-entry',
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'post single' );
|
||||
|
||||
$this->go_to( home_url( '/?s=editorial' ) );
|
||||
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'search' );
|
||||
|
||||
foreach (
|
||||
array(
|
||||
'chrnx_topic' => 'code',
|
||||
'chrnx_language' => 'en',
|
||||
'chrnx_show' => 'silicon-ranch',
|
||||
) as $taxonomy => $slug
|
||||
) {
|
||||
$term = get_term_by( 'slug', $slug, $taxonomy );
|
||||
$this->assertInstanceOf( WP_Term::class, $term );
|
||||
$this->go_to( get_term_link( $term ) );
|
||||
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), $taxonomy );
|
||||
}
|
||||
|
||||
$previous_show_on_front = get_option( 'show_on_front' );
|
||||
$previous_page_for_posts = get_option( 'page_for_posts' );
|
||||
try {
|
||||
update_option( 'show_on_front', 'posts' );
|
||||
update_option( 'page_for_posts', 0 );
|
||||
$this->go_to( home_url( '/' ) );
|
||||
$this->assertTrue( is_home() );
|
||||
$this->assertSame( home_url( '/journal/' ), chrnx_get_current_navigation_destination(), 'Journal listing' );
|
||||
} finally {
|
||||
update_option( 'show_on_front', $previous_show_on_front );
|
||||
update_option( 'page_for_posts', $previous_page_for_posts );
|
||||
}
|
||||
}
|
||||
|
||||
/** Front, unrelated, boundary-lookalike, and missing requests select no destination. */
|
||||
public function test_current_navigation_destination_rejects_false_positives() {
|
||||
$this->assertTrue( function_exists( 'chrnx_get_current_navigation_destination' ) );
|
||||
if ( ! function_exists( 'chrnx_get_current_navigation_destination' ) ) {
|
||||
return;
|
||||
}
|
||||
$previous_show_on_front = get_option( 'show_on_front' );
|
||||
$previous_page_on_front = get_option( 'page_on_front' );
|
||||
$front_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'home',
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
update_option( 'show_on_front', 'page' );
|
||||
update_option( 'page_on_front', $front_id );
|
||||
$this->go_to( home_url( '/' ) );
|
||||
$this->assertTrue( is_front_page() );
|
||||
$this->assertSame( '', chrnx_get_current_navigation_destination(), 'front page' );
|
||||
} finally {
|
||||
update_option( 'show_on_front', $previous_show_on_front );
|
||||
update_option( 'page_on_front', $previous_page_on_front );
|
||||
}
|
||||
|
||||
foreach ( array( 'contact', 'music-notes' ) as $slug ) {
|
||||
$page_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => $slug,
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $page_id ) );
|
||||
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/' . $slug . '/' );
|
||||
}
|
||||
|
||||
$parent_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'collection',
|
||||
)
|
||||
);
|
||||
$nested_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'music',
|
||||
'post_parent' => $parent_id,
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $nested_id ) );
|
||||
$this->assertSame( '', chrnx_get_current_navigation_destination(), '/collection/music/' );
|
||||
|
||||
$this->go_to( home_url( '/definitely-missing-chrnx-route/' ) );
|
||||
$GLOBALS['wp_query']->is_404 = true;
|
||||
$this->assertTrue( is_404() );
|
||||
$this->assertSame( '', chrnx_get_current_navigation_destination(), '404' );
|
||||
}
|
||||
|
||||
/** Header and footer each expose exactly one matching aria-current link. */
|
||||
public function test_navigation_blocks_render_one_current_page_for_the_active_destination() {
|
||||
$music_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'music',
|
||||
'post_title' => 'Music',
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $music_id ) );
|
||||
|
||||
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
|
||||
$output = $this->render_navigation_block( $block_name );
|
||||
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
|
||||
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/music/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Music<\/a>/', $output );
|
||||
}
|
||||
}
|
||||
|
||||
/** Journal semantics apply to post singles without marking lookalike destinations. */
|
||||
public function test_navigation_blocks_mark_only_journal_for_post_singles() {
|
||||
$post_id = self::factory()->post->create(
|
||||
array(
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'music-notes',
|
||||
)
|
||||
);
|
||||
$this->go_to( get_permalink( $post_id ) );
|
||||
|
||||
foreach ( array( 'chrnx/header-tools', 'chrnx/footer-content' ) as $block_name ) {
|
||||
$output = $this->render_navigation_block( $block_name );
|
||||
$this->assertSame( 1, substr_count( $output, 'aria-current="page"' ), $block_name );
|
||||
$this->assertMatchesRegularExpression( '/<a[^>]+href="' . preg_quote( esc_url( home_url( '/journal/' ) ), '/' ) . '"[^>]+aria-current="page"[^>]*>Journal<\/a>/', $output );
|
||||
$this->assertDoesNotMatchRegularExpression( '/href="[^"]*music[^"]*"[^>]+aria-current="page"/', $output );
|
||||
}
|
||||
}
|
||||
|
||||
/** The approved local wordmark links to the portable site home URL. */
|
||||
public function test_site_brand_renders_escaped_local_home_and_wordmark_urls() {
|
||||
$output = render_block(
|
||||
@@ -906,6 +1071,19 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/** Render one navigation block for the current main query. */
|
||||
private function render_navigation_block( $block_name ) {
|
||||
return render_block(
|
||||
array(
|
||||
'blockName' => $block_name,
|
||||
'attrs' => array(),
|
||||
'innerBlocks' => array(),
|
||||
'innerHTML' => '',
|
||||
'innerContent' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** Render one dynamic post-context block for a specific post. */
|
||||
private function render_for_post( $block_name, $post_id ) {
|
||||
global $post;
|
||||
|
||||
Reference in new issue
Block a user