Ticket #41305: 41305.diff
File 41305.diff, 39.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/class-wp-locale.php
diff --git a/src/wp-includes/class-wp-locale.php b/src/wp-includes/class-wp-locale.php index 287914e880..a12b2ce26c 100644
a b class WP_Locale { 127 127 $this->weekday[6] = /* translators: weekday */ __( 'Saturday' ); 128 128 129 129 // The first letter of each day. 130 $this->weekday_initial[ __( 'Sunday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Sunday initial' );131 $this->weekday_initial[ __( 'Monday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'M', 'Monday initial' );132 $this->weekday_initial[ __( 'Tuesday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Tuesday initial' );133 $this->weekday_initial[ __( 'Wednesday' )] = /* translators: one-letter abbreviation of the weekday */ _x( 'W', 'Wednesday initial' );134 $this->weekday_initial[ __( 'Thursday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Thursday initial' );135 $this->weekday_initial[ __( 'Friday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'F', 'Friday initial' );136 $this->weekday_initial[ __( 'Saturday' ) ]= /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Saturday initial' );130 $this->weekday_initial[ (string) $this->weekday[0] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Sunday initial' ); 131 $this->weekday_initial[ (string) $this->weekday[1] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'M', 'Monday initial' ); 132 $this->weekday_initial[ (string) $this->weekday[2] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Tuesday initial' ); 133 $this->weekday_initial[ (string) $this->weekday[3] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'W', 'Wednesday initial' ); 134 $this->weekday_initial[ (string) $this->weekday[4] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'T', 'Thursday initial' ); 135 $this->weekday_initial[ (string) $this->weekday[5] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'F', 'Friday initial' ); 136 $this->weekday_initial[ (string) $this->weekday[6] ] = /* translators: one-letter abbreviation of the weekday */ _x( 'S', 'Saturday initial' ); 137 137 138 138 // Abbreviations for each day. 139 $this->weekday_abbrev[ __( 'Sunday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Sun' );140 $this->weekday_abbrev[ __( 'Monday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Mon' );141 $this->weekday_abbrev[ __( 'Tuesday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Tue' );142 $this->weekday_abbrev[ __( 'Wednesday' )] = /* translators: three-letter abbreviation of the weekday */ __( 'Wed' );143 $this->weekday_abbrev[ __( 'Thursday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Thu' );144 $this->weekday_abbrev[ __( 'Friday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Fri' );145 $this->weekday_abbrev[ __( 'Saturday' ) ]= /* translators: three-letter abbreviation of the weekday */ __( 'Sat' );139 $this->weekday_abbrev[ (string) $this->weekday[0] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Sun' ); 140 $this->weekday_abbrev[ (string) $this->weekday[1] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Mon' ); 141 $this->weekday_abbrev[ (string) $this->weekday[2] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Tue' ); 142 $this->weekday_abbrev[ (string) $this->weekday[3] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Wed' ); 143 $this->weekday_abbrev[ (string) $this->weekday[4] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Thu' ); 144 $this->weekday_abbrev[ (string) $this->weekday[5] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Fri' ); 145 $this->weekday_abbrev[ (string) $this->weekday[6] ] = /* translators: three-letter abbreviation of the weekday */ __( 'Sat' ); 146 146 147 147 // The Months 148 148 $this->month['01'] = /* translators: month name */ __( 'January' ); … … class WP_Locale { 173 173 $this->month_genitive['12'] = /* translators: month name, genitive */ _x( 'December', 'genitive' ); 174 174 175 175 // Abbreviations for each month. 176 $this->month_abbrev[ __( 'January' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' );177 $this->month_abbrev[ __( 'February' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' );178 $this->month_abbrev[ __( 'March' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Mar', 'March abbreviation' );179 $this->month_abbrev[ __( 'April' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Apr', 'April abbreviation' );180 $this->month_abbrev[ __( 'May' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'May', 'May abbreviation' );181 $this->month_abbrev[ __( 'June' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Jun', 'June abbreviation' );182 $this->month_abbrev[ __( 'July' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Jul', 'July abbreviation' );183 $this->month_abbrev[ __( 'August' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Aug', 'August abbreviation' );184 $this->month_abbrev[ __( 'September' )] = /* translators: three-letter abbreviation of the month */ _x( 'Sep', 'September abbreviation' );185 $this->month_abbrev[ __( 'October' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Oct', 'October abbreviation' );186 $this->month_abbrev[ __( 'November' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Nov', 'November abbreviation' );187 $this->month_abbrev[ __( 'December' ) ]= /* translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' );176 $this->month_abbrev[ (string) $this->month['01'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Jan', 'January abbreviation' ); 177 $this->month_abbrev[ (string) $this->month['02'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Feb', 'February abbreviation' ); 178 $this->month_abbrev[ (string) $this->month['03'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Mar', 'March abbreviation' ); 179 $this->month_abbrev[ (string) $this->month['04'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Apr', 'April abbreviation' ); 180 $this->month_abbrev[ (string) $this->month['05'] ] = /* translators: three-letter abbreviation of the month */ _x( 'May', 'May abbreviation' ); 181 $this->month_abbrev[ (string) $this->month['06'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Jun', 'June abbreviation' ); 182 $this->month_abbrev[ (string) $this->month['07'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Jul', 'July abbreviation' ); 183 $this->month_abbrev[ (string) $this->month['08'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Aug', 'August abbreviation' ); 184 $this->month_abbrev[ (string) $this->month['09'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Sep', 'September abbreviation' ); 185 $this->month_abbrev[ (string) $this->month['10'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Oct', 'October abbreviation' ); 186 $this->month_abbrev[ (string) $this->month['11'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Nov', 'November abbreviation' ); 187 $this->month_abbrev[ (string) $this->month['12'] ] = /* translators: three-letter abbreviation of the month */ _x( 'Dec', 'December abbreviation' ); 188 188 189 189 // The Meridiems 190 190 $this->meridiem['am'] = __( 'am' ); … … class WP_Locale { 196 196 // See https://secure.php.net/number_format 197 197 198 198 /* translators: $thousands_sep argument for https://secure.php.net/number_format, default is , */ 199 $thousands_sep = __( 'number_format_thousands_sep' );199 $thousands_sep = (string) __( 'number_format_thousands_sep' ); 200 200 201 201 if ( version_compare( PHP_VERSION, '5.4', '>=' ) ) { 202 202 // Replace space with a non-breaking space to avoid wrapping. … … class WP_Locale { 209 209 $this->number_format['thousands_sep'] = ( 'number_format_thousands_sep' === $thousands_sep ) ? ',' : $thousands_sep; 210 210 211 211 /* translators: $dec_point argument for https://secure.php.net/number_format, default is . */ 212 $decimal_point = __( 'number_format_decimal_point' );212 $decimal_point = (string) __( 'number_format_decimal_point' ); 213 213 214 214 $this->number_format['decimal_point'] = ( 'number_format_decimal_point' === $decimal_point ) ? '.' : $decimal_point; 215 215 … … class WP_Locale { 250 250 * @return string Full translated weekday. 251 251 */ 252 252 public function get_weekday( $weekday_number ) { 253 return $this->weekday[ $weekday_number ];253 return $this->weekday[ (string) $weekday_number ]; 254 254 } 255 255 256 256 /** … … class WP_Locale { 267 267 * @return string Translated weekday initial. 268 268 */ 269 269 public function get_weekday_initial( $weekday_name ) { 270 return $this->weekday_initial[ $weekday_name ];270 return $this->weekday_initial[ (string) $weekday_name ]; 271 271 } 272 272 273 273 /** … … class WP_Locale { 282 282 * @return string Translated weekday abbreviation. 283 283 */ 284 284 public function get_weekday_abbrev( $weekday_name ) { 285 return $this->weekday_abbrev[ $weekday_name ];285 return $this->weekday_abbrev[ (string) $weekday_name ]; 286 286 } 287 287 288 288 /** … … class WP_Locale { 317 317 * @return string Translated abbreviated month. 318 318 */ 319 319 public function get_month_abbrev( $month_name ) { 320 return $this->month_abbrev[ $month_name ];320 return $this->month_abbrev[ (string) $month_name ]; 321 321 } 322 322 323 323 /** … … class WP_Locale { 331 331 * @return string Translated version 332 332 */ 333 333 public function get_meridiem( $meridiem ) { 334 return $this->meridiem[ $meridiem ];334 return $this->meridiem[ (string) $meridiem ]; 335 335 } 336 336 337 337 /** -
src/wp-includes/comment-template.php
diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index d0bdba5024..0bf35b905e 100644
a b function get_comments_number_text( $zero = false, $one = false, $more = false ) 906 906 /* translators: If comment number in your language requires declension, 907 907 * translate this to 'on'. Do not translate into your own language. 908 908 */ 909 if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {909 if ( 'on' === (string) _x( 'off', 'Comment number declension: on or off' ) ) { 910 910 $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more ); 911 911 $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities 912 912 $text = trim( strip_tags( $text ), '% ' ); -
src/wp-includes/functions.php
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index f3070315f6..a4140be71e 100644
a b function wp_maybe_decline_date( $date ) { 218 218 /* translators: If months in your language require a genitive case, 219 219 * translate this to 'on'. Do not translate into your own language. 220 220 */ 221 if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) {221 if ( 'on' === (string) _x( 'off', 'decline months names: on or off' ) ) { 222 222 // Match a format like 'j F Y' or 'j. F' 223 223 if ( @preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) { 224 224 $months = $wp_locale->month; … … function wp_die( $message = '', $title = '', $args = array() ) { 2915 2915 $function = apply_filters( 'wp_die_handler', '_default_wp_die_handler' ); 2916 2916 } 2917 2917 2918 call_user_func( $function, $message, $title, $args );2918 call_user_func( $function, (string) $message, $title, $args ); 2919 2919 } 2920 2920 2921 2921 /** -
src/wp-includes/l10n.php
diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 081f2cf7db..eaff94aee4 100644
a b function translate_with_gettext_context( $text, $context, $domain = 'default' ) 192 192 * If there is no translation, or the text domain isn't loaded, the original text is returned. 193 193 * 194 194 * @since 2.1.0 195 * @since 5.0.0 Returns a lazily-translating proxy object. 195 196 * 196 197 * @param string $text Text to translate. 197 198 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 198 199 * Default 'default'. 199 * @return string Translated text.200 * @return WP_String_Proxy Proxy object representing a string. 200 201 */ 201 202 function __( $text, $domain = 'default' ) { 202 return translate( $text, $domain );203 return new WP_Translation_Proxy( $text, $domain ); 203 204 } 204 205 205 206 /** … … function __( $text, $domain = 'default' ) { 208 209 * If there is no translation, or the text domain isn't loaded, the original text is returned. 209 210 * 210 211 * @since 2.8.0 212 * @since 5.0.0 Returns a lazily-translating proxy object. 211 213 * 212 214 * @param string $text Text to translate. 213 215 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 214 216 * Default 'default'. 215 * @return string Translated text on success, original text on failure.217 * @return WP_String_Proxy Proxy object representing a string. 216 218 */ 217 219 function esc_attr__( $text, $domain = 'default' ) { 218 return esc_attr( translate( $text, $domain ) ); 220 return new WP_Escape_Attribute_Proxy( 221 new WP_Translation_Proxy( $text, $domain ) 222 ); 219 223 } 220 224 221 225 /** … … function esc_attr__( $text, $domain = 'default' ) { 225 229 * is escaped and returned. 226 230 * 227 231 * @since 2.8.0 232 * @since 5.0.0 Returns a lazily-translating proxy object. 228 233 * 229 234 * @param string $text Text to translate. 230 235 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 231 236 * Default 'default'. 232 * @return string Translated text237 * @return WP_String_Proxy Proxy object representing a string. 233 238 */ 234 239 function esc_html__( $text, $domain = 'default' ) { 235 return esc_html( translate( $text, $domain ) ); 240 return new WP_Escape_HTML_Proxy( 241 new WP_Translation_Proxy( $text, $domain ) 242 ); 236 243 } 237 244 238 245 /** … … function esc_html_e( $text, $domain = 'default' ) { 284 291 * strings differently. 285 292 * 286 293 * @since 2.8.0 294 * @since 5.0.0 Returns a lazily-translating proxy object. 287 295 * 288 296 * @param string $text Text to translate. 289 297 * @param string $context Context information for the translators. 290 298 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 291 299 * Default 'default'. 292 * @return string Translated context string without pipe.300 * @return WP_String_Proxy Proxy object representing a string. 293 301 */ 294 302 function _x( $text, $context, $domain = 'default' ) { 295 return translate_with_gettext_context( $text, $context, $domain );303 return new WP_Contextual_Translation_Proxy( $text, $context, $domain ); 296 304 } 297 305 298 306 /** … … function _ex( $text, $context, $domain = 'default' ) { 314 322 * Translate string with gettext context, and escapes it for safe use in an attribute. 315 323 * 316 324 * @since 2.8.0 325 * @since 5.0.0 Returns a lazily-translating proxy object. 317 326 * 318 327 * @param string $text Text to translate. 319 328 * @param string $context Context information for the translators. 320 329 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 321 330 * Default 'default'. 322 * @return string Translated text331 * @return WP_String_Proxy Proxy object representing a string. 323 332 */ 324 333 function esc_attr_x( $text, $context, $domain = 'default' ) { 325 return esc_attr( translate_with_gettext_context( $text, $context, $domain ) ); 334 return new WP_Escape_Attribute_Proxy( 335 new WP_Contextual_Translation_Proxy( $text, $context, $domain ) 336 ); 326 337 } 327 338 328 339 /** 329 340 * Translate string with gettext context, and escapes it for safe use in HTML output. 330 341 * 331 342 * @since 2.9.0 343 * @since 5.0.0 Returns a lazily-translating proxy object. 332 344 * 333 345 * @param string $text Text to translate. 334 346 * @param string $context Context information for the translators. 335 347 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. 336 348 * Default 'default'. 337 * @return string Translated text.349 * @return WP_String_Proxy Proxy object representing a string. 338 350 */ 339 351 function esc_html_x( $text, $context, $domain = 'default' ) { 340 return esc_html( translate_with_gettext_context( $text, $context, $domain ) ); 352 return new WP_Escape_HTML_Proxy( 353 new WP_Contextual_Translation_Proxy( $text, $context, $domain ) 354 ); 341 355 } 342 356 343 357 /** -
src/wp-includes/wp-db.php
diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index ae08158f64..f9e31d37cd 100644
a b class wpdb { 1313 1313 } 1314 1314 1315 1315 foreach ( $args as $arg ) { 1316 if ( ! is_scalar( $arg ) && ! is_null( $arg ) ) {1316 if ( ! is_scalar( $arg ) && ! is_null( $arg ) && ! $arg instanceof WP_String_Proxy) { 1317 1317 wp_load_translations_early(); 1318 1318 _doing_it_wrong( 'wpdb::prepare', sprintf( __( 'Unsupported value type (%s).' ), gettype( $arg ) ), '4.8.2' ); 1319 1319 } -
src/wp-settings.php
diff --git a/src/wp-settings.php b/src/wp-settings.php index eb632238f0..ff7366d120 100644
a b require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.p 240 240 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' ); 241 241 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-term-meta-fields.php' ); 242 242 require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-user-meta-fields.php' ); 243 require( ABSPATH . WPINC . '/l10n/class-wp-string-proxy.php' ); 244 require( ABSPATH . WPINC . '/l10n/class-wp-translation-proxy.php' ); 245 require( ABSPATH . WPINC . '/l10n/class-wp-contextual-translation-proxy.php' ); 246 require( ABSPATH . WPINC . '/l10n/class-wp-escape-attribute-proxy.php' ); 247 require( ABSPATH . WPINC . '/l10n/class-wp-escape-html-proxy.php' ); 243 248 244 249 $GLOBALS['wp_embed'] = new WP_Embed(); 245 250 -
tests/phpunit/data/plugins/internationalized-plugin.php
diff --git a/tests/phpunit/data/plugins/internationalized-plugin.php b/tests/phpunit/data/plugins/internationalized-plugin.php index 4b56846ad3..2362cf6180 100644
a b Text Domain: internationalized-plugin 8 8 */ 9 9 10 10 function i18n_plugin_test() { 11 return __( 'This is a dummy plugin', 'internationalized-plugin' );11 return (string) __( 'This is a dummy plugin', 'internationalized-plugin' ); 12 12 } -
tests/phpunit/includes/testcase.php
diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index db3f0b9fb6..26fa83f75f 100644
a b class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 582 582 } 583 583 584 584 /** 585 * Assert that two elements are equal. 586 * 587 * Override to handle special cases for equality checks. 588 * 589 * @since 5.0.0 Added WP_String_Proxy object <=> string equality. 590 * 591 * @param mixed $expected 592 * @param mixed $actual 593 * @param string $message 594 * @param int $delta 595 * @param int $maxDepth 596 * @param bool $canonicalize 597 * @param bool $ignoreCase 598 */ 599 public static function assertEquals( $expected, $actual, $message = '', $delta = 0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false ) { 600 if ( is_array( $actual ) ) { 601 array_walk( $actual, 'WP_UnitTestCase::resolve_proxies', $expected ); 602 } 603 604 $actual = self::resolve_proxy( $actual ); 605 $expected = self::resolve_proxy( $expected ); 606 607 parent::assertEquals( $expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase ); 608 } 609 610 /** 611 * Resolve proxies in arrays to be tested. 612 * 613 * @since 5.0.0 614 * 615 * @param mixed $value Reference to the array value to be checked. 616 * @param string $key Index key of the array value to be checked. 617 */ 618 protected static function resolve_proxies( &$value, $key ) { 619 if ( is_array( $value ) ) { 620 array_walk( $value, 'WP_UnitTestCase::resolve_proxies' ); 621 } 622 623 $value = self::resolve_proxy( $value ); 624 } 625 626 /** 627 * Resolve an individual proxy. 628 * 629 * @since 0.1.0 630 * 631 * @param $value 632 * 633 * @return string 634 */ 635 protected static function resolve_proxy( $value ) { 636 if ( $value instanceof WP_String_Proxy ) { 637 return (string) $value; 638 } 639 640 return $value; 641 } 642 643 /** 644 * Asserts that two variables have the same type and value. 645 * Used on objects, it asserts that two variables reference 646 * the same object. 647 * 648 * Override to handle special cases for equality checks. 649 * 650 * @since 5.0.0 Added WP_String_Proxy object <=> string equality. 651 * 652 * @param mixed $expected 653 * @param mixed $actual 654 * @param string $message 655 */ 656 public static function assertSame( $expected, $actual, $message = '' ) { 657 if ( is_array( $actual ) ) { 658 array_walk( $actual, 'WP_UnitTestCase::resolve_proxies' ); 659 } 660 661 if ( is_array( $expected ) ) { 662 array_walk( $expected, 'WP_UnitTestCase::resolve_proxies' ); 663 } 664 665 $actual = self::resolve_proxy( $actual ); 666 $expected = self::resolve_proxy( $expected ); 667 668 parent::assertSame( $expected, $actual, $message ); 669 } 670 671 /** 672 * Asserts that a variable is of a given type. 673 * 674 * Override to handle special cases for equality checks. 675 * 676 * @since 5.0.0 Added WP_String_Proxy object <=> string equality. 677 * 678 * @param string $expected 679 * @param mixed $actual 680 * @param string $message 681 */ 682 public static function assertInternalType( $expected, $actual, $message = '' ) { 683 if ( 'string' === $expected ) { 684 $actual = self::resolve_proxy( $actual ); 685 } 686 687 parent::assertInternalType( $expected, $actual, $message ); 688 } 689 690 /** 585 691 * Sets the global state to as if a given URL has been requested. 586 692 * 587 693 * This sets: -
tests/phpunit/tests/customize/nav-menus.php
diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index e7387773ac..951d766fd9 100644
a b class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 390 390 $results = $menus->search_available_items_query( 391 391 array( 392 392 'pagenum' => 1, 393 's' => $title,393 's' => (string) $title, 394 394 ) 395 395 ); 396 396 $this->assertCount( 1, $results ); -
tests/phpunit/tests/l10n/loadTextdomainJustInTime.php
diff --git a/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php b/tests/phpunit/tests/l10n/loadTextdomainJustInTime.php index 7fb85a5427..49c40d480c 100644
a b class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 75 75 $expected_output = i18n_plugin_test(); 76 76 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-plugin' ); 77 77 78 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );79 80 78 $this->assertFalse( $is_textdomain_loaded_before ); 81 79 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_output ); 82 80 $this->assertTrue( $is_textdomain_loaded_after ); 81 82 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 83 83 } 84 84 85 85 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 94 94 95 95 $is_textdomain_loaded_before = is_textdomain_loaded( 'internationalized-theme' ); 96 96 $expected_output = i18n_theme_test(); 97 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-theme' );98 99 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );100 97 101 98 $this->assertFalse( $is_textdomain_loaded_before ); 102 99 $this->assertSame( 'Das ist ein Dummy Theme', $expected_output ); 100 101 $is_textdomain_loaded_after = is_textdomain_loaded( 'internationalized-theme' ); 103 102 $this->assertTrue( $is_textdomain_loaded_after ); 103 104 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 104 105 } 105 106 106 107 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 110 111 add_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 111 112 add_filter( 'override_load_textdomain', '__return_true' ); 112 113 $translations = get_translations_for_domain( 'internationalized-plugin' ); 113 remove_filter( 'override_load_textdomain', '__return_true' );114 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) );115 114 116 115 $this->assertTrue( $translations instanceof NOOP_Translations ); 116 117 remove_filter( 'override_load_textdomain', '__return_true' ); 118 remove_filter( 'locale', array( $this, 'filter_set_locale_to_german' ) ); 117 119 } 118 120 119 121 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 163 165 164 166 switch_to_locale( 'de_DE' ); 165 167 $expected = i18n_plugin_test(); 166 restore_previous_locale();167 168 168 169 $this->assertSame( 'Das ist ein Dummy Plugin', $expected ); 170 171 restore_previous_locale(); 169 172 } 170 173 171 174 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 180 183 switch_to_locale( 'es_ES' ); 181 184 $expected_es_ES = i18n_plugin_test(); 182 185 183 restore_current_locale();184 185 186 $this->assertSame( 'Das ist ein Dummy Plugin', $expected_de_DE ); 186 187 $this->assertSame( 'This is a dummy plugin', $expected_es_ES ); 188 189 restore_current_locale(); 187 190 } 188 191 189 192 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 196 199 197 200 switch_to_locale( 'de_DE' ); 198 201 $expected = i18n_theme_test(); 202 203 $this->assertSame( 'Das ist ein Dummy Theme', $expected ); 204 199 205 restore_previous_locale(); 200 206 201 207 switch_theme( WP_DEFAULT_THEME ); 202 203 $this->assertSame( 'Das ist ein Dummy Theme', $expected );204 208 } 205 209 206 210 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 231 235 232 236 $expected = i18n_theme_test(); 233 237 238 $this->assertSame( 'Das ist ein Dummy Theme', $expected ); 239 234 240 set_current_screen( 'front' ); 235 241 switch_theme( WP_DEFAULT_THEME ); 236 237 $this->assertSame( 'Das ist ein Dummy Theme', $expected );238 242 } 239 243 240 244 /** … … class Tests_L10n_loadTextdomainJustInTime extends WP_UnitTestCase { 245 249 246 250 add_filter( 'locale', array( $this, '_filter_locale_count' ) ); 247 251 248 __( 'Foo', $textdomain ); 249 __( 'Bar', $textdomain ); 250 __( 'Baz', $textdomain ); 251 __( 'Foo Bar', $textdomain ); 252 __( 'Foo Bar Baz', $textdomain ); 253 254 remove_filter( 'locale', array( $this, '_filter_locale_count' ) ); 252 $foo = (string) __( 'Foo', $textdomain ); 253 $bar = (string) __( 'Bar', $textdomain ); 254 $baz = (string) __( 'Baz', $textdomain ); 255 $foo_bar = (string) __( 'Foo Bar', $textdomain ); 256 $foo_bar_baz = (string) __( 'Foo Bar Baz', $textdomain ); 255 257 256 258 $this->assertFalse( is_textdomain_loaded( $textdomain ) ); 257 259 $this->assertSame( 1, $this->locale_count ); 260 261 remove_filter( 'locale', array( $this, '_filter_locale_count' ) ); 258 262 } 259 263 260 264 public function _filter_locale_count( $locale ) { -
tests/phpunit/tests/l10n/localeSwitcher.php
diff --git a/tests/phpunit/tests/l10n/localeSwitcher.php b/tests/phpunit/tests/l10n/localeSwitcher.php index f100c8a1db..84190c1961 100644
a b class Tests_Locale_Switcher extends WP_UnitTestCase { 48 48 public function test_switch_to_locale_returns_true() { 49 49 $expected = switch_to_locale( 'en_GB' ); 50 50 51 $this->assertTrue( $expected ); 52 51 53 // Cleanup. 52 54 restore_previous_locale(); 53 54 $this->assertTrue( $expected );55 55 } 56 56 57 57 public function test_switch_to_locale_changes_the_locale() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 59 59 60 60 $locale = get_locale(); 61 61 62 $this->assertSame( 'en_GB', $locale ); 63 62 64 // Cleanup. 63 65 restore_previous_locale(); 64 65 $this->assertSame( 'en_GB', $locale );66 66 } 67 67 68 68 public function test_switch_to_locale_loads_translation() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 70 70 71 71 $actual = __( 'Invalid parameter.' ); 72 72 73 $this->assertSame( 'Parámetro no válido. ', $actual ); 74 73 75 // Cleanup. 74 76 restore_previous_locale(); 75 76 $this->assertSame( 'Parámetro no válido. ', $actual );77 77 } 78 78 79 79 public function test_switch_to_locale_changes_wp_locale_global() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 88 88 89 89 $wp_locale_de_DE = clone $wp_locale; 90 90 91 $this->assertEqualSetsWithIndex( $expected, $wp_locale_de_DE->number_format ); 92 91 93 // Cleanup. 92 94 restore_previous_locale(); 93 94 $this->assertEqualSetsWithIndex( $expected, $wp_locale_de_DE->number_format );95 95 } 96 96 97 97 public function test_switch_to_locale_en_US() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 100 100 switch_to_locale( 'en_US' ); 101 101 $locale_en_US = get_locale(); 102 102 103 // Cleanup.104 restore_current_locale();105 106 103 $this->assertSame( 'en_GB', $locale_en_GB ); 107 104 $this->assertSame( 'en_US', $locale_en_US ); 105 106 // Cleanup. 107 restore_current_locale(); 108 108 } 109 109 110 110 public function test_switch_to_locale_multiple_times() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 112 112 switch_to_locale( 'es_ES' ); 113 113 $locale = get_locale(); 114 114 115 $this->assertSame( 'es_ES', $locale ); 116 115 117 // Cleanup. 116 118 restore_previous_locale(); 117 119 restore_previous_locale(); 118 119 $this->assertSame( 'es_ES', $locale );120 120 } 121 121 122 122 public function test_switch_to_locale_multiple_times_loads_translation() { … … class Tests_Locale_Switcher extends WP_UnitTestCase { 126 126 127 127 $actual = __( 'Invalid parameter.' ); 128 128 129 $this->assertSame( 'Parámetro no válido. ', $actual ); 130 129 131 // Cleanup. 130 132 restore_previous_locale(); 131 133 restore_previous_locale(); 132 134 restore_previous_locale(); 133 134 $this->assertSame( 'Parámetro no válido. ', $actual );135 135 } 136 136 137 137 public function test_restore_previous_locale_without_switching() { -
tests/phpunit/tests/locale.php
diff --git a/tests/phpunit/tests/locale.php b/tests/phpunit/tests/locale.php index 98a700509c..6ef9963223 100644
a b class Tests_Locale extends WP_UnitTestCase { 20 20 } 21 21 22 22 public function test_get_weekday() { 23 $this->assertEquals( __( 'Sunday' ), $this->locale->get_weekday( 0 ) );24 $this->assertEquals( __( 'Monday' ), $this->locale->get_weekday( 1 ) );25 $this->assertEquals( __( 'Tuesday' ), $this->locale->get_weekday( 2 ) );26 $this->assertEquals( __( 'Wednesday' ), $this->locale->get_weekday( 3 ) );27 $this->assertEquals( __( 'Thursday' ), $this->locale->get_weekday( 4 ) );28 $this->assertEquals( __( 'Friday' ), $this->locale->get_weekday( 5 ) );29 $this->assertEquals( __( 'Saturday' ), $this->locale->get_weekday( 6 ) );23 $this->assertEquals( (string) __( 'Sunday' ), $this->locale->get_weekday( 0 ) ); 24 $this->assertEquals( (string) __( 'Monday' ), $this->locale->get_weekday( 1 ) ); 25 $this->assertEquals( (string) __( 'Tuesday' ), $this->locale->get_weekday( 2 ) ); 26 $this->assertEquals( (string) __( 'Wednesday' ), $this->locale->get_weekday( 3 ) ); 27 $this->assertEquals( (string) __( 'Thursday' ), $this->locale->get_weekday( 4 ) ); 28 $this->assertEquals( (string) __( 'Friday' ), $this->locale->get_weekday( 5 ) ); 29 $this->assertEquals( (string) __( 'Saturday' ), $this->locale->get_weekday( 6 ) ); 30 30 } 31 31 32 32 /** … … class Tests_Locale extends WP_UnitTestCase { 37 37 } 38 38 39 39 public function test_get_weekday_initial() { 40 $this->assertEquals( __( 'S' ), $this->locale->get_weekday_initial( __( 'Sunday' ) ) );41 $this->assertEquals( __( 'M' ), $this->locale->get_weekday_initial( __( 'Monday' ) ) );42 $this->assertEquals( __( 'T' ), $this->locale->get_weekday_initial( __( 'Tuesday' ) ) );43 $this->assertEquals( __( 'W' ), $this->locale->get_weekday_initial( __( 'Wednesday' ) ) );44 $this->assertEquals( __( 'T' ), $this->locale->get_weekday_initial( __( 'Thursday' ) ) );45 $this->assertEquals( __( 'F' ), $this->locale->get_weekday_initial( __( 'Friday' ) ) );46 $this->assertEquals( __( 'S' ), $this->locale->get_weekday_initial( __( 'Saturday' ) ) );40 $this->assertEquals( (string) __( 'S' ), $this->locale->get_weekday_initial( __( 'Sunday' ) ) ); 41 $this->assertEquals( (string) __( 'M' ), $this->locale->get_weekday_initial( __( 'Monday' ) ) ); 42 $this->assertEquals( (string) __( 'T' ), $this->locale->get_weekday_initial( __( 'Tuesday' ) ) ); 43 $this->assertEquals( (string) __( 'W' ), $this->locale->get_weekday_initial( __( 'Wednesday' ) ) ); 44 $this->assertEquals( (string) __( 'T' ), $this->locale->get_weekday_initial( __( 'Thursday' ) ) ); 45 $this->assertEquals( (string) __( 'F' ), $this->locale->get_weekday_initial( __( 'Friday' ) ) ); 46 $this->assertEquals( (string) __( 'S' ), $this->locale->get_weekday_initial( __( 'Saturday' ) ) ); 47 47 } 48 48 49 49 public function test_get_weekday_abbrev() { 50 $this->assertEquals( __( 'Sun' ), $this->locale->get_weekday_abbrev( __( 'Sunday' ) ) );51 $this->assertEquals( __( 'Mon' ), $this->locale->get_weekday_abbrev( __( 'Monday' ) ) );52 $this->assertEquals( __( 'Tue' ), $this->locale->get_weekday_abbrev( __( 'Tuesday' ) ) );53 $this->assertEquals( __( 'Wed' ), $this->locale->get_weekday_abbrev( __( 'Wednesday' ) ) );54 $this->assertEquals( __( 'Thu' ), $this->locale->get_weekday_abbrev( __( 'Thursday' ) ) );55 $this->assertEquals( __( 'Fri' ), $this->locale->get_weekday_abbrev( __( 'Friday' ) ) );56 $this->assertEquals( __( 'Sat' ), $this->locale->get_weekday_abbrev( __( 'Saturday' ) ) );50 $this->assertEquals( (string) __( 'Sun' ), $this->locale->get_weekday_abbrev( __( 'Sunday' ) ) ); 51 $this->assertEquals( (string) __( 'Mon' ), $this->locale->get_weekday_abbrev( __( 'Monday' ) ) ); 52 $this->assertEquals( (string) __( 'Tue' ), $this->locale->get_weekday_abbrev( __( 'Tuesday' ) ) ); 53 $this->assertEquals( (string) __( 'Wed' ), $this->locale->get_weekday_abbrev( __( 'Wednesday' ) ) ); 54 $this->assertEquals( (string) __( 'Thu' ), $this->locale->get_weekday_abbrev( __( 'Thursday' ) ) ); 55 $this->assertEquals( (string) __( 'Fri' ), $this->locale->get_weekday_abbrev( __( 'Friday' ) ) ); 56 $this->assertEquals( (string) __( 'Sat' ), $this->locale->get_weekday_abbrev( __( 'Saturday' ) ) ); 57 57 } 58 58 59 59 public function test_get_month() { 60 $this->assertEquals( __( 'January' ), $this->locale->get_month( 1 ) );61 $this->assertEquals( __( 'February' ), $this->locale->get_month( 2 ) );62 $this->assertEquals( __( 'March' ), $this->locale->get_month( 3 ) );63 $this->assertEquals( __( 'April' ), $this->locale->get_month( 4 ) );64 $this->assertEquals( __( 'May' ), $this->locale->get_month( 5 ) );65 $this->assertEquals( __( 'June' ), $this->locale->get_month( 6 ) );66 $this->assertEquals( __( 'July' ), $this->locale->get_month( 7 ) );67 $this->assertEquals( __( 'August' ), $this->locale->get_month( 8 ) );68 $this->assertEquals( __( 'September' ), $this->locale->get_month( 9 ) );69 $this->assertEquals( __( 'October' ), $this->locale->get_month( 10 ) );70 $this->assertEquals( __( 'November' ), $this->locale->get_month( 11 ) );71 $this->assertEquals( __( 'December' ), $this->locale->get_month( 12 ) );60 $this->assertEquals( (string) __( 'January' ), $this->locale->get_month( 1 ) ); 61 $this->assertEquals( (string) __( 'February' ), $this->locale->get_month( 2 ) ); 62 $this->assertEquals( (string) __( 'March' ), $this->locale->get_month( 3 ) ); 63 $this->assertEquals( (string) __( 'April' ), $this->locale->get_month( 4 ) ); 64 $this->assertEquals( (string) __( 'May' ), $this->locale->get_month( 5 ) ); 65 $this->assertEquals( (string) __( 'June' ), $this->locale->get_month( 6 ) ); 66 $this->assertEquals( (string) __( 'July' ), $this->locale->get_month( 7 ) ); 67 $this->assertEquals( (string) __( 'August' ), $this->locale->get_month( 8 ) ); 68 $this->assertEquals( (string) __( 'September' ), $this->locale->get_month( 9 ) ); 69 $this->assertEquals( (string) __( 'October' ), $this->locale->get_month( 10 ) ); 70 $this->assertEquals( (string) __( 'November' ), $this->locale->get_month( 11 ) ); 71 $this->assertEquals( (string) __( 'December' ), $this->locale->get_month( 12 ) ); 72 72 } 73 73 74 74 public function test_get_month_leading_zero() { 75 $this->assertEquals( __( 'January' ), $this->locale->get_month( '01' ) );76 $this->assertEquals( __( 'February' ), $this->locale->get_month( '02' ) );77 $this->assertEquals( __( 'March' ), $this->locale->get_month( '03' ) );78 $this->assertEquals( __( 'April' ), $this->locale->get_month( '04' ) );79 $this->assertEquals( __( 'May' ), $this->locale->get_month( '05' ) );80 $this->assertEquals( __( 'June' ), $this->locale->get_month( '06' ) );81 $this->assertEquals( __( 'July' ), $this->locale->get_month( '07' ) );82 $this->assertEquals( __( 'August' ), $this->locale->get_month( '08' ) );83 $this->assertEquals( __( 'September' ), $this->locale->get_month( '09' ) );75 $this->assertEquals( (string) __( 'January' ), $this->locale->get_month( '01' ) ); 76 $this->assertEquals( (string) __( 'February' ), $this->locale->get_month( '02' ) ); 77 $this->assertEquals( (string) __( 'March' ), $this->locale->get_month( '03' ) ); 78 $this->assertEquals( (string) __( 'April' ), $this->locale->get_month( '04' ) ); 79 $this->assertEquals( (string) __( 'May' ), $this->locale->get_month( '05' ) ); 80 $this->assertEquals( (string) __( 'June' ), $this->locale->get_month( '06' ) ); 81 $this->assertEquals( (string) __( 'July' ), $this->locale->get_month( '07' ) ); 82 $this->assertEquals( (string) __( 'August' ), $this->locale->get_month( '08' ) ); 83 $this->assertEquals( (string) __( 'September' ), $this->locale->get_month( '09' ) ); 84 84 } 85 85 86 86 public function test_get_month_abbrev() { 87 $this->assertEquals( __( 'Jan' ), $this->locale->get_month_abbrev( __( 'January' ) ) );88 $this->assertEquals( __( 'Feb' ), $this->locale->get_month_abbrev( __( 'February' ) ) );89 $this->assertEquals( __( 'Mar' ), $this->locale->get_month_abbrev( __( 'March' ) ) );90 $this->assertEquals( __( 'Apr' ), $this->locale->get_month_abbrev( __( 'April' ) ) );91 $this->assertEquals( __( 'May' ), $this->locale->get_month_abbrev( __( 'May' ) ) );92 $this->assertEquals( __( 'Jun' ), $this->locale->get_month_abbrev( __( 'June' ) ) );93 $this->assertEquals( __( 'Jul' ), $this->locale->get_month_abbrev( __( 'July' ) ) );94 $this->assertEquals( __( 'Aug' ), $this->locale->get_month_abbrev( __( 'August' ) ) );95 $this->assertEquals( __( 'Sep' ), $this->locale->get_month_abbrev( __( 'September' ) ) );96 $this->assertEquals( __( 'Oct' ), $this->locale->get_month_abbrev( __( 'October' ) ) );97 $this->assertEquals( __( 'Nov' ), $this->locale->get_month_abbrev( __( 'November' ) ) );98 $this->assertEquals( __( 'Dec' ), $this->locale->get_month_abbrev( __( 'December' ) ) );87 $this->assertEquals( (string) __( 'Jan' ), $this->locale->get_month_abbrev( __( 'January' ) ) ); 88 $this->assertEquals( (string) __( 'Feb' ), $this->locale->get_month_abbrev( __( 'February' ) ) ); 89 $this->assertEquals( (string) __( 'Mar' ), $this->locale->get_month_abbrev( __( 'March' ) ) ); 90 $this->assertEquals( (string) __( 'Apr' ), $this->locale->get_month_abbrev( __( 'April' ) ) ); 91 $this->assertEquals( (string) __( 'May' ), $this->locale->get_month_abbrev( __( 'May' ) ) ); 92 $this->assertEquals( (string) __( 'Jun' ), $this->locale->get_month_abbrev( __( 'June' ) ) ); 93 $this->assertEquals( (string) __( 'Jul' ), $this->locale->get_month_abbrev( __( 'July' ) ) ); 94 $this->assertEquals( (string) __( 'Aug' ), $this->locale->get_month_abbrev( __( 'August' ) ) ); 95 $this->assertEquals( (string) __( 'Sep' ), $this->locale->get_month_abbrev( __( 'September' ) ) ); 96 $this->assertEquals( (string) __( 'Oct' ), $this->locale->get_month_abbrev( __( 'October' ) ) ); 97 $this->assertEquals( (string) __( 'Nov' ), $this->locale->get_month_abbrev( __( 'November' ) ) ); 98 $this->assertEquals( (string) __( 'Dec' ), $this->locale->get_month_abbrev( __( 'December' ) ) ); 99 99 } 100 100 101 101 public function test_get_meridiem() { 102 $this->assertEquals( __( 'am' ), $this->locale->get_meridiem( 'am' ) );103 $this->assertEquals( __( 'AM' ), $this->locale->get_meridiem( 'AM' ) );104 $this->assertEquals( __( 'pm' ), $this->locale->get_meridiem( 'pm' ) );105 $this->assertEquals( __( 'PM' ), $this->locale->get_meridiem( 'PM' ) );102 $this->assertEquals( (string) __( 'am' ), $this->locale->get_meridiem( 'am' ) ); 103 $this->assertEquals( (string) __( 'AM' ), $this->locale->get_meridiem( 'AM' ) ); 104 $this->assertEquals( (string) __( 'pm' ), $this->locale->get_meridiem( 'pm' ) ); 105 $this->assertEquals( (string) __( 'PM' ), $this->locale->get_meridiem( 'PM' ) ); 106 106 } 107 107 108 108 public function test_is_rtl() {