Extracted the wp_insert_post/wp_update_post argument construction into a private build_postarr() helper so the post_date/post_date_gmt derivation from the feed timestamp can be exercised in isolation. Added smoke tests that pin down the create-path behavior (feed timestamp becomes post_date) and the fallback path (no feed date leaves post_date unset for WordPress to fill in at import time). Added minimal get_date_from_gmt and get_gmt_from_date stubs to the test bootstrap so the new tests run without WordPress loaded.
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* PHPUnit bootstrap.
|
|
*
|
|
* @package RSS2CPT
|
|
*/
|
|
|
|
define( 'ABSPATH', dirname( __DIR__ ) . '/' );
|
|
define( 'MINUTE_IN_SECONDS', 60 );
|
|
|
|
/**
|
|
* Minimal option stub for isolated settings tests.
|
|
*
|
|
* @param string $option Option name.
|
|
* @param mixed $default_value Default value.
|
|
* @return mixed
|
|
*/
|
|
function get_option( $option, $default_value = false ) {
|
|
unset( $option );
|
|
return $default_value;
|
|
}
|
|
|
|
/**
|
|
* Minimal wp_parse_args stub for isolated settings tests.
|
|
*
|
|
* @param array $args Supplied values.
|
|
* @param array $defaults Default values.
|
|
* @return array
|
|
*/
|
|
function wp_parse_args( $args, $defaults = array() ) {
|
|
return array_merge( $defaults, $args );
|
|
}
|
|
|
|
/**
|
|
* Minimal get_date_from_gmt stub matching WordPress's MySQL-string behavior.
|
|
*
|
|
* @param string $date_string GMT timestamp in MySQL date format.
|
|
* @return string Timestamp converted to the site's local timezone.
|
|
*/
|
|
function get_date_from_gmt( $date_string ) {
|
|
return get_gmt_from_date( $date_string );
|
|
}
|
|
|
|
/**
|
|
* Minimal get_gmt_from_date stub: the inverse of get_date_from_gmt.
|
|
*
|
|
* @param string $date_string Local timestamp in MySQL date format.
|
|
* @return string Timestamp converted to GMT (UTC).
|
|
*/
|
|
function get_gmt_from_date( $date_string ) {
|
|
$timestamp = strtotime( $date_string . ' UTC' );
|
|
if ( false === $timestamp ) {
|
|
return $date_string;
|
|
}
|
|
return gmdate( 'Y-m-d H:i:s', $timestamp );
|
|
}
|
|
|
|
require_once dirname( __DIR__ ) . '/src/Options.php';
|
|
require_once dirname( __DIR__ ) . '/src/Import/Importer.php';
|