$primary, 'phone_cities_default' => $tier_default, ); $overrides = array(); a1tools_add_override( $overrides, 'phone_primary', array( 'phone' => $page_phone ), 'phone' ); a1tools_add_phone_default( $overrides, $variables, 'phone_cities_default' ); $merged = array_merge( $variables, $overrides ); return $merged['phone_primary']; } echo "phone cascade\n"; // The headline case from the spec: A1 Chimney ATL. check( 'city with its own phone beats both upper tiers', '(888) 283-1000', resolve( '(888) 283-1000', '(888) 283-2000', '(888) 283-2999' ) ); check( 'city with no phone falls to the all-cities default', '(888) 283-2000', resolve( '', '(888) 283-2000', '(888) 283-2999' ) ); check( 'no city phone and no default falls all the way to primary', '(888) 283-2999', resolve( '', '', '(888) 283-2999' ) ); // Blank-ish values must not win — a whitespace-only column is "unset". check( 'whitespace-only city phone is treated as unset', '(888) 283-2000', resolve( ' ', '(888) 283-2000', '(888) 283-2999' ) ); check( 'whitespace-only default is skipped', '(888) 283-2999', resolve( '', ' ', '(888) 283-2999' ) ); // Regression guard: the default must never overwrite a page that set its own, // which is the one way this cascade can silently invert. $overrides = array( 'phone_primary' => '(888) 283-1000' ); a1tools_add_phone_default( $overrides, array( 'phone_cities_default' => '(888) 283-2000' ), 'phone_cities_default' ); check( 'default never overwrites an existing page override', '(888) 283-1000', $overrides['phone_primary'] ); // A site that has not adopted the feature must behave exactly as before. $overrides = array(); a1tools_add_phone_default( $overrides, array( 'phone_primary' => '(888) 283-2999' ), 'phone_cities_default' ); check( 'missing default column is a no-op', '', isset( $overrides['phone_primary'] ) ? $overrides['phone_primary'] : '' ); // Page-cache purge: on a site with no caching plugin installed, every direct // call must be guarded away and only the (harmless) hooks fire. If this ever // fatals, saving site variables fatals with it. echo "\npage cache purge\n"; $GLOBALS['a1_actions'] = array(); a1tools_purge_page_cache(); check( 'survives with no cache plugin installed', 'yes', 'yes' ); check( 'fires the SiteGround + LiteSpeed purge hooks', 'sg_cachepress_purge_cache,litespeed_purge_all', implode( ',', $GLOBALS['a1_actions'] ) ); echo $failures ? "\n$failures FAILED\n" : "\nall passed\n"; exit( $failures ? 1 : 0 );