From 6a5305e0b1057f6bea2710e5d8ed5d9490bf517a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 15 Jun 2016 17:40:23 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/functions.php | 93 +++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index e28e65f752..bfad5ce39f 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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