I18N: Add a unit test for `wp_maybe_decline_date()`.

See #36790.

git-svn-id: https://develop.svn.wordpress.org/trunk@37716 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2016-06-15 17:40:23 +00:00
parent 86af710a3d
commit 6a5305e0b1
1 changed files with 93 additions and 0 deletions

View File

@ -830,6 +830,99 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertEquals( '', ob_get_clean() );
}
/**
* @ticket 36790
* @dataProvider data_wp_maybe_decline_date
*/
function test_wp_maybe_decline_date( $test_locale, $input, $output ) {
global $locale, $wp_locale;
$locale_original = $locale;
$wp_locale_original = $wp_locale;
add_filter( 'gettext_with_context', array( $this, '_enable_months_names_declension' ), 10, 4 );
$month_names = $this->_get_months_names( $test_locale );
$locale = $test_locale;
$wp_locale->month = $month_names['month'];
$wp_locale->month_genitive = $month_names['month_genitive'];
$this->assertEquals( $output, wp_maybe_decline_date( $input ) );
remove_filter( 'gettext_with_context', array( $this, '_enable_months_names_declension' ), 10, 4 );
$locale = $locale_original;
$wp_locale = $wp_locale_original;
}
function _enable_months_names_declension( $translation, $text, $context, $domain ) {
if ( 'decline months names: on or off' === $context ) {
$translation = 'on';
}
return $translation;
}
function _get_months_names( $locale ) {
switch ( $locale ) {
case 'ru_RU':
$months = array(
'month' => array( 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь' ),
'month_genitive' => array( 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря' ),
);
break;
case 'pl_PL':
$months = array(
'month' => array( 'Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień' ),
'month_genitive' => array( 'stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia' ),
);
break;
case 'hr':
$months = array(
'month' => array( 'Siječanj', 'Veljača', 'Ožujak', 'Travanj', 'Svibanj', 'Lipanj', 'Srpanj', 'Kolovoz', 'Rujan', 'Listopad', 'Studeni', 'Prosinac' ),
'month_genitive' => array( 'siječnja', 'veljače', 'ožujka', 'ožujka', 'svibnja', 'lipnja', 'srpnja', 'kolovoza', 'rujna', 'listopada', 'studenoga', 'prosinca' ),
);
break;
case 'ca':
$months = array(
'month' => array( 'gener', 'febrer', 'març', 'abril', 'maig', 'juny', 'juliol', 'agost', 'setembre', 'octubre', 'novembre', 'desembre' ),
'month_genitive' => array( 'gener', 'febrer', 'març', 'abril', 'maig', 'juny', 'juliol', 'agost', 'setembre', 'octubre', 'novembre', 'desembre' ),
);
break;
case 'cs_CZ':
$months = array(
'month' => array( 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec' ),
'month_genitive' => array( 'ledna', 'února', 'března', 'dubna', 'května', 'června', 'července', 'srpna', 'září', 'října', 'listopadu', 'prosince' ),
);
break;
default:
$months = array(
'month' => array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ),
'month_genitive' => array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' )
);
}
return $months;
}
function data_wp_maybe_decline_date() {
return array(
array( 'ru_RU', '21 Июнь', '21 июня' ),
array( 'ru_RU', '1 Январь 2016', '1 января 2016' ),
array( 'pl_PL', '1 Styczeń', '1 stycznia' ),
array( 'hr', '1. Siječanj', '1. siječnja' ),
array( 'ca', '1 de abril', "1 d'abril" ),
array( 'cs_CZ', '1. Červen', '1. června' ),
array( 'cs_CZ', '1. Červenec', '1. července' ),
);
}
/**
* @ticket 36054
* @dataProvider datetime_provider