'8:00 AM - 10:00 PM', 'mon' => '8:00 AM - 10:00 PM', 'tue' => '8:00 AM - 10:00 PM', 'wed' => '8:00 AM - 10:00 PM', 'thu' => '8:00 AM - 10:00 PM', 'fri' => '8:00 AM - 5:00 PM', 'sat' => '', ); check( 'Sun-Thu / Friday / Saturday condenses to three groups', array( 'Sun – Thu|8:00 AM - 10:00 PM', 'Friday|8:00 AM - 5:00 PM', 'Saturday|Closed' ), flat( $sun_thu ) ); check( 'Hide Closed Days drops the closed group only', array( 'Sun – Thu|8:00 AM - 10:00 PM', 'Friday|8:00 AM - 5:00 PM' ), flat( $sun_thu, true ) ); // Rule 5: identical days separated by a different schedule must NOT merge. // Split mid-week so the Sat/Sun boundary is not involved — that is a separate // rule and conflating the two hides whichever one breaks. check( 'non-consecutive identical schedules stay separate', array( 'Sun – Tue|9-5', 'Wednesday|Closed', 'Thu – Sat|9-5' ), flat( array( 'sun' => '9-5', 'mon' => '9-5', 'tue' => '9-5', 'wed' => '', 'thu' => '9-5', 'fri' => '9-5', 'sat' => '9-5', ) ) ); // The wrap is capped at three days. A six-day wrap would technically be one // circular run, but "Tue – Sun" forces the reader to work out that Monday is // the exception — so these stay as separate, self-explanatory rows. check( 'a long wrap is refused in favour of rows that read plainly', array( 'Sunday|9-5', 'Monday|Closed', 'Tue – Sat|9-5' ), flat( array( 'sun' => '9-5', 'mon' => '', 'tue' => '9-5', 'wed' => '9-5', 'thu' => '9-5', 'fri' => '9-5', 'sat' => '9-5', ) ) ); // The week boundary: Sat + Sun share hours, weekdays differ. check( 'a Sat/Sun weekend merges across the week boundary, and reads last', array( 'Mon – Fri|9-5', 'Sat – Sun|10-4' ), flat( array( 'sun' => '10-4', 'mon' => '9-5', 'tue' => '9-5', 'wed' => '9-5', 'thu' => '9-5', 'fri' => '9-5', 'sat' => '10-4', ) ) ); // A uniform week is one run; the boundary merge must not fire and produce // something like "Sat – Sat" for seven identical days. check( 'seven identical days are one honest range', array( 'Sun – Sat|9-5' ), flat( array_fill_keys( a1tools_hours_day_order(), '9-5' ) ) ); check( 'consecutive closed days group together', array( 'Mon – Fri|9-5', 'Sat – Sun|Closed' ), flat( array( 'sun' => '', 'mon' => '9-5', 'tue' => '9-5', 'wed' => '9-5', 'thu' => '9-5', 'fri' => '9-5', 'sat' => '', ) ) ); check( 'a fully closed week is one group, and Hide Closed empties it', array(), flat( array(), true ) ); echo "\nComparison vs display\n"; // Dash variants and casing decide EQUALITY only; the shown value is the // original, so a site keeps its own typography. $dashes = array( 'sun' => '8:00 AM – 10:00 PM', // en dash 'mon' => '8:00 AM - 10:00 PM', // hyphen 'tue' => '8:00 AM — 10:00 PM', // em dash 'wed' => '', 'thu' => '', 'fri' => '', 'sat' => '', ); $g = a1tools_group_operating_hours( $dashes ); check( 'dash variants count as the same schedule', 1, count( $g[0]['days'] ) === 3 ? 1 : 0 ); check( 'the original dash is what gets displayed', '8:00 AM – 10:00 PM', $g[0]['time'] ); check( '"Closed" as text is the same state as an empty value', array( 'Sun – Sat|Closed' ), flat( array_fill_keys( a1tools_hours_day_order(), 'Closed' ) ) ); check( 'differing whitespace does not split a run', array( 'Sun – Mon|9 - 5', 'Tue – Sat|Closed' ), flat( array( 'sun' => '9 - 5', 'mon' => '9 - 5' ) ) ); check( 'a custom closed label is used', 'By appointment', a1tools_group_operating_hours( array(), 'By appointment' )[0]['time'] ); echo "\nA1 host gate\n"; foreach ( array( 'a-1chimney.com', 'www.a-1chimney.com', 'nj.a-1chimney.com', 'cle.a-1chimney.com', 'A-1CHIMNEY.COM', 'nj.a-1chimney.com:8080' ) as $h ) { check( "$h is a website host", true, a1tools_is_a1chimney_site( $h ) ); } foreach ( array( 'app.a-1chimney.com', 'tools.a-1chimney.com', 'crm.a-1chimney.com', 'tech.a-1chimney.com', 'calls.a-1chimney.com', 'report.a-1chimney.com' ) as $h ) { check( "$h is internal, not a website", false, a1tools_is_a1chimney_site( $h ) ); } foreach ( array( 'example.com', 'a-1chimney.com.evil.net', 'nota-1chimney.com', '' ) as $h ) { check( "'$h' is not an A1 host", false, a1tools_is_a1chimney_site( $h ) ); } echo $failures ? "\n$failures failure(s)\n" : "\nAll passed\n"; exit( $failures ? 1 : 0 );