Files
hoponhopofftickets/viator-collector/tests/test-city-guide.php
Amir Bagheri 25debff066 feat: starter guides for all 15 structure cities
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>
2026-10-31 10:10:01 +03:30

56 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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'] );
}