Writes guides for the nine cities with no old page and adds Best time to visit to all. The import now fills only empty fields and re-runs once, so sites that already imported get the new values without losing edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
||
/**
|
||
* VC_City_Guide unit tests: bundled guide data and season months.
|
||
*/
|
||
|
||
function vc_test_bundled_guides() {
|
||
return include dirname( __DIR__ ) . '/data/city-guides.php';
|
||
}
|
||
|
||
function test_bundled_guides_use_known_fields() {
|
||
$fields = VC_City_Guide::fields();
|
||
foreach ( vc_test_bundled_guides() as $slug => $guide ) {
|
||
vc_assert_same( array(), array_values( array_diff( array_keys( $guide ), array_keys( $fields ) ) ), "unknown fields for $slug" );
|
||
}
|
||
}
|
||
|
||
function test_bundled_guides_have_core_text() {
|
||
foreach ( vc_test_bundled_guides() as $slug => $guide ) {
|
||
foreach ( array( 'tagline', 'language', 'currency', 'timezone', 'best_time', 'about_title', 'about' ) as $key ) {
|
||
vc_assert_same( true, ! empty( $guide[ $key ] ), "$slug.$key empty" );
|
||
}
|
||
vc_assert_same( false, (bool) preg_match( '/elementor|\{|\}/', implode( ' ', $guide ) ), "$slug has page junk" );
|
||
}
|
||
}
|
||
|
||
function test_bundled_guides_cover_structure_cities() {
|
||
vc_assert_same(
|
||
array( 'boston', 'chicago', 'las-vegas', 'los-angeles', 'miami', 'montreal', 'new-orleans', 'new-york-city', 'san-diego', 'san-francisco', 'seattle', 'toronto', 'vancouver', 'victoria', 'washington-dc' ),
|
||
( function ( $k ) { sort( $k ); return $k; } )( array_keys( vc_test_bundled_guides() ) )
|
||
);
|
||
}
|
||
|
||
function test_empty_guide_detection() {
|
||
$blank = array_fill_keys( array_keys( VC_City_Guide::fields() ), '' );
|
||
vc_assert_same( true, VC_City_Guide::is_empty( $blank ) );
|
||
vc_assert_same( true, VC_City_Guide::is_empty( array_merge( $blank, array( 'southern' => true, 'about_image' => 'https://x/y.jpg' ) ) ) );
|
||
vc_assert_same( false, VC_City_Guide::is_empty( array_merge( $blank, array( 'winter' => 'Skate.' ) ) ) );
|
||
}
|
||
|
||
function test_season_months_flip_south() {
|
||
$north = VC_City_Guide::season_months( false );
|
||
$south = VC_City_Guide::season_months( true );
|
||
vc_assert_same( 'March – May', $north['spring'] );
|
||
vc_assert_same( 'September – November', $south['spring'] );
|
||
vc_assert_same( 'June – August', $south['winter'] );
|
||
}
|
||
|
||
function test_fill_empty_keeps_entered_text() {
|
||
$guide = VC_City_Guide::fill_empty(
|
||
array( 'tagline' => 'Mine', 'best_time' => '' ),
|
||
array( 'tagline' => 'Bundled', 'best_time' => 'May – June' )
|
||
);
|
||
vc_assert_same( 'Mine', $guide['tagline'] );
|
||
vc_assert_same( 'May – June', $guide['best_time'] );
|
||
}
|