Skip to content

Commit 8eb4dc9

Browse files
Tests: Add unit tests for wp_timezone_choice().
Follow-up to [57145], [59931]. Reviewed by westonruter, swissspidy, SergeyBiryukov. Props pbearne, SirLouen, wildworks, westonruter, swissspidy, audrasjb, juanmaguitar, rollybueno, welcher, SergeyBiryukov. Fixes #59941. git-svn-id: https://develop.svn.wordpress.org/trunk@62156 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d29c674 commit 8eb4dc9

7 files changed

Lines changed: 205 additions & 46 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['Vincennes'=>'Vincennes','Winamac'=>'Winamac','Inuvik'=>'Inuvik','Iqaluit'=>'Iqaluit','Jamaica'=>'Jamaica'],'language'=>'es_ES','x-generator'=>'Poedit 1.8.10'];
2+
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['Port Moresby'=>'Puerto Moresby','Arctic'=>'Ártico','Vincennes'=>'Vincennes','Winamac'=>'Winamac','Inuvik'=>'Inuvik','Iqaluit'=>'Iqaluit','Jamaica'=>'Jamaica'],'language'=>'es_ES','x-generator'=>'Poedit 1.8.10'];
110 Bytes
Binary file not shown.
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
# Translation of Continents & Cities in Spanish (Spain)
2-
# This file is distributed under the same license as the Continents & Cities package.
1+
# Translation of WordPress - 6.4.x - Development - Continents & Cities in Spanish (Spain)
2+
# This file is distributed under the same license as the WordPress - 6.4.x - Development - Continents & Cities package.
33
msgid ""
44
msgstr ""
5-
"PO-Revision-Date: 2016-10-26 00:01+0200\n"
5+
"PO-Revision-Date: 2022-10-12 09:13:34+0000\n"
66
"MIME-Version: 1.0\n"
77
"Content-Type: text/plain; charset=UTF-8\n"
88
"Content-Transfer-Encoding: 8bit\n"
99
"Plural-Forms: nplurals=2; plural=n != 1;\n"
10-
"X-Generator: Poedit 1.8.10\n"
11-
"Project-Id-Version: Continents & Cities\n"
12-
"Language: es_ES\n"
10+
"X-Generator: GlotPress/4.0.0-alpha.11\n"
11+
"Language: es\n"
12+
"Project-Id-Version: WordPress - 6.4.x - Development - Continents & Cities\n"
1313

14-
#: wp-admin/includes/continents-cities.php:140
15-
msgid "Vincennes"
16-
msgstr "Vincennes"
14+
#: wp-admin/includes/continents-cities.php:539
15+
msgid "Port Moresby"
16+
msgstr "Puerto Moresby"
1717

18-
#: wp-admin/includes/continents-cities.php:141
19-
msgid "Winamac"
20-
msgstr "Winamac"
18+
#: wp-admin/includes/continents-cities.php:248
19+
msgid "Arctic"
20+
msgstr "Ártico"
21+
22+
#: wp-admin/includes/continents-cities.php:149
23+
msgid "Iqaluit"
24+
msgstr "Iqaluit"
2125

22-
#: wp-admin/includes/continents-cities.php:142
26+
#: wp-admin/includes/continents-cities.php:148
2327
msgid "Inuvik"
2428
msgstr "Inuvik"
2529

26-
#: wp-admin/includes/continents-cities.php:143
27-
msgid "Iqaluit"
28-
msgstr "Iqaluit"
30+
#: wp-admin/includes/continents-cities.php:146
31+
msgid "Vincennes"
32+
msgstr "Vincennes"
2933

30-
#: wp-admin/includes/continents-cities.php:144
31-
msgid "Jamaica"
32-
msgstr "Jamaica"
34+
#: wp-admin/includes/continents-cities.php:147
35+
msgid "Winamac"
36+
msgstr "Winamac"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['text directionltr'=>'ltr','<strong>ERROR</strong>: Sorry, that username is not allowed.'=>'<strong>ERROR</strong>: Lo siento, ese nombre de usuario no está permitido.','Invalid parameter.'=>'Parámetro no válido. ','menu location(Current: %s)'=>'(Actual: %s)','menu(Currently set to: %s)'=>'(Actualmente fijado en: %s)','[%1$s] Confirm Action: %2$s'=>'[%1$s] Confirmar la acción: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Solicitud de borrado completada','[%s] Personal Data Export'=>'[%s] Exportación de datos personales'],'language'=>'es_ES','x-generator'=>'Poedit 2.3'];
2+
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['text directionltr'=>'ltr','<strong>ERROR</strong>: Sorry, that username is not allowed.'=>'<strong>ERROR</strong>: Lo siento, ese nombre de usuario no está permitido.','Invalid parameter.'=>'Parámetro no válido. ','menu location(Current: %s)'=>'(Actual: %s)','menu(Currently set to: %s)'=>'(Actualmente fijado en: %s)','[%1$s] Confirm Action: %2$s'=>'[%1$s] Confirmar la acción: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Solicitud de borrado completada','[%s] Personal Data Export'=>'[%s] Exportación de datos personales', 'Manual Offsets' => 'Compensaciones manuales', 'Select a city' => 'Elige una ciudad' ],'language'=>'es_ES','x-generator'=>'Poedit 2.3'];
33 Bytes
Binary file not shown.

tests/phpunit/data/languages/es_ES.po

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,64 @@
1-
# Translation of Development (5.2.x) in Spanish (Spain)
2-
# This file is distributed under the same license as the Development (5.2.x) package.
1+
# Translation of WordPress - 6.4.x - Development in Spanish (Spain)
2+
# This file is distributed under the same license as the WordPress - 6.4.x - Development package.
33
msgid ""
44
msgstr ""
5-
"PO-Revision-Date: 2020-07-23 21:12+0300\n"
5+
"Project-Id-Version: WordPress - 6.4.x - Development\n"
6+
"POT-Creation-Date: \n"
7+
"PO-Revision-Date: 2024-02-28 14:31-0500\n"
8+
"Last-Translator: \n"
9+
"Language-Team: \n"
10+
"Language: es\n"
611
"MIME-Version: 1.0\n"
712
"Content-Type: text/plain; charset=UTF-8\n"
813
"Content-Transfer-Encoding: 8bit\n"
914
"Plural-Forms: nplurals=2; plural=n != 1;\n"
10-
"X-Generator: Poedit 2.3\n"
11-
"Project-Id-Version: Development (5.2.x)\n"
12-
"Language: es_ES\n"
13-
"POT-Creation-Date: \n"
14-
"Last-Translator: \n"
15-
"Language-Team: \n"
15+
"X-Generator: Poedit 3.4.2\n"
16+
17+
#: wp-includes/functions.php:6635
18+
msgid "Manual Offsets"
19+
msgstr "Compensaciones manuales"
20+
21+
#: wp-includes/functions.php:6574
22+
msgid "Select a city"
23+
msgstr "Elige una ciudad"
1624

1725
#. translators: 'rtl' or 'ltr'. This sets the text direction for WordPress.
18-
#: wp-includes/locale.php:201
26+
#: wp-includes/class-wp-locale.php:248 wp-includes/script-loader.php:325
27+
#: wp-includes/js/dist/i18n.js:1398
28+
#, gp-priority: high
1929
msgctxt "text direction"
2030
msgid "ltr"
2131
msgstr "ltr"
2232

23-
#: wp-includes/user.php:2132
24-
msgid "<strong>ERROR</strong>: Sorry, that username is not allowed."
25-
msgstr "<strong>ERROR</strong>: Lo siento, ese nombre de usuario no está permitido."
33+
#: wp-includes/user.php:3357 wp-admin/includes/user.php:202
34+
msgid "<strong>Error:</strong> Sorry, that username is not allowed."
35+
msgstr "<strong>Error</strong>: lo siento, ese nombre de usuario no está permitido."
2636

27-
#: wp-includes/rest-api/class-wp-rest-request.php:850
37+
#: wp-includes/rest-api/class-wp-rest-request.php:916
2838
msgid "Invalid parameter."
2939
msgstr "Parámetro no válido. "
3040

31-
#. translators: %s: menu name
32-
#: wp-includes/customize/class-wp-customize-nav-menu-control.php:76
41+
#. translators: %s: Menu name.
42+
#: wp-includes/customize/class-wp-customize-nav-menu-locations-control.php:79
3343
msgctxt "menu location"
3444
msgid "(Current: %s)"
3545
msgstr "(Actual: %s)"
3646

37-
#. translators: %s: menu location slug
38-
#: wp-includes/class-wp-customize-nav-menus.php:340
47+
#. translators: %s: Menu location.
48+
#: wp-includes/class-wp-customize-nav-menus.php:510
3949
msgctxt "menu"
4050
msgid "(Currently set to: %s)"
4151
msgstr "(Actualmente fijado en: %s)"
4252

43-
#. translators: Privacy data request subject. 1: Site name, 2: Name of the action
44-
#: wp-includes/user.php:3445
53+
#. translators: Confirm privacy data request notification email subject. 1:
54+
#. Site title, 2: Name of the action.
55+
#: wp-includes/user.php:4705
4556
msgid "[%1$s] Confirm Action: %2$s"
4657
msgstr "[%1$s] Confirmar la acción: %2$s"
4758

48-
#. translators: %s: Site name.
49-
#: wp-includes/user.php:3175
59+
#. translators: Erasure request fulfilled notification email subject. %s: Site
60+
#. title.
61+
#: wp-includes/user.php:4299
5062
msgid "[%s] Erasure Request Fulfilled"
5163
msgstr "[%s] Solicitud de borrado completada"
5264

53-
#: wp-admin/includes/file.php:2415
54-
msgid "[%s] Personal Data Export"
55-
msgstr "[%s] Exportación de datos personales"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<?php
2+
3+
/**
4+
* Tests for the wp_timezone_choice() function.
5+
*
6+
* @group functions
7+
*
8+
* @covers ::wp_timezone_choice
9+
*/
10+
class Tests_Functions_WpTimezoneChoice extends WP_UnitTestCase {
11+
12+
/**
13+
* Restores the current locale after each test runs.
14+
*/
15+
public function tear_down(): void {
16+
restore_current_locale();
17+
parent::tear_down();
18+
}
19+
20+
/**
21+
* Tests default values.
22+
*
23+
* @ticket 59941
24+
* @dataProvider data_wp_timezone_choice
25+
*
26+
* @param string $expected Expected string HTML fragment.
27+
*/
28+
public function test_wp_timezone_choice( string $expected ): void {
29+
$timezone_list = wp_timezone_choice( '' );
30+
$this->assertStringContainsString( $expected, $timezone_list );
31+
}
32+
33+
/**
34+
* Data provider for test_wp_timezone_choice().
35+
*
36+
* @return array<string, array{ 0: string }>
37+
*/
38+
public function data_wp_timezone_choice(): array {
39+
return array(
40+
'placeholder option' => array( '<option selected="selected" value="">Select a city</option>' ),
41+
'city in Americas' => array( '<option value="America/Los_Angeles" dir="auto">Los Angeles</option>' ),
42+
'deprecated timezone' => array( '<option value="Pacific/Honolulu" dir="auto">Honolulu</option>' ),
43+
'manual offset example' => array( '<option value="UTC-8" dir="auto">UTC-8</option>' ),
44+
'UTC option' => array( '<option value="UTC" dir="auto">UTC</option>' ),
45+
'continent example' => array( '<option value="Africa/Johannesburg" dir="auto">Johannesburg</option>' ),
46+
'city example' => array( '<option value="Asia/Kuala_Lumpur" dir="auto">Kuala Lumpur</option>' ),
47+
'city with sub-city' => array( '<option value="America/Argentina/Buenos_Aires" dir="auto">Argentina - Buenos Aires</option>' ),
48+
'translated city name appears' => array( '<option value="Pacific/Port_Moresby" dir="auto">Port Moresby</option>' ),
49+
);
50+
}
51+
52+
/**
53+
* Tests zones are selected from the list.
54+
*
55+
* @ticket 59941
56+
* @dataProvider data_wp_timezone_choice_selected
57+
*
58+
* @param string $selected_zone The timezone to select.
59+
* @param string $expected Expected string HTML fragment.
60+
*/
61+
public function test_wp_timezone_choice_selected( string $selected_zone, string $expected ): void {
62+
$actual = wp_timezone_choice( $selected_zone );
63+
$this->assertStringContainsString( $expected, $actual );
64+
}
65+
66+
/**
67+
* Data provider for test_wp_timezone_choice_selected().
68+
*
69+
* @return array<string, array{ 0: string }>
70+
*/
71+
public function data_wp_timezone_choice_selected(): array {
72+
return array(
73+
'city from the list' => array(
74+
'America/Los_Angeles',
75+
'<option selected="selected" value="America/Los_Angeles" dir="auto">Los Angeles</option>',
76+
),
77+
'deprecated but valid timezone string' => array(
78+
'Pacific/Auckland',
79+
'<option selected="selected" value="Pacific/Auckland" dir="auto">Auckland</option>',
80+
),
81+
'UTC' => array(
82+
'UTC',
83+
'<option selected="selected" value="UTC" dir="auto">UTC</option>',
84+
),
85+
'manual UTC offset' => array(
86+
'UTC+10',
87+
'<option selected="selected" value="UTC+10" dir="auto">UTC+10</option>',
88+
),
89+
);
90+
}
91+
92+
/**
93+
* Tests passing in the locale.
94+
*
95+
* @ticket 59941
96+
* @dataProvider data_wp_timezone_choice_es
97+
*
98+
* @param string $expected Expected string HTML fragment.
99+
*/
100+
public function test_wp_timezone_choice_es( string $expected ): void {
101+
$timezone_list = wp_timezone_choice( '', 'es_ES' );
102+
$this->assertStringContainsString( $expected, $timezone_list );
103+
}
104+
105+
/**
106+
* Data provider for test_wp_timezone_choice_es().
107+
*
108+
* @return array<string, array{ 0: string }>
109+
*/
110+
public function data_wp_timezone_choice_es(): array {
111+
return array(
112+
'placeholder remains in English (no translation override passed)' => array( '<option selected="selected" value="">Select a city</option>' ),
113+
'spanish city translation' => array( '<option value="Pacific/Port_Moresby" dir="auto">Puerto Moresby</option>' ),
114+
'spanish optgroup Arctic' => array( '<optgroup label="Ártico" dir="auto">' ),
115+
'spanish optgroup Manual Offsets untranslated' => array( '<optgroup label="Manual Offsets" dir="auto">' ),
116+
);
117+
}
118+
119+
/**
120+
* Tests setting the locale globally.
121+
*
122+
* @ticket 59941
123+
* @dataProvider data_wp_timezone_choice_es_set
124+
*
125+
* @param string $expected Expected string HTML fragment.
126+
*/
127+
public function test_wp_timezone_choice_es_set( string $expected ): void {
128+
switch_to_locale( 'es_ES' );
129+
$timezone_list = wp_timezone_choice( '' );
130+
$this->assertStringContainsString( $expected, $timezone_list );
131+
}
132+
133+
/**
134+
* Data provider for test_wp_timezone_choice_es_set().
135+
*
136+
* @return array<string, array{ 0: string }>
137+
*/
138+
public static function data_wp_timezone_choice_es_set(): array {
139+
return array(
140+
'placeholder in Spanish' => array( '<option selected="selected" value="">Elige una ciudad</option>' ),
141+
'spanish city translation' => array( '<option value="Pacific/Port_Moresby" dir="auto">Puerto Moresby</option>' ),
142+
'spanish optgroup Arctic' => array( '<optgroup label="Ártico" dir="auto">' ),
143+
'spanish optgroup Manual Offsets' => array( '<optgroup label="Compensaciones manuales" dir="auto">' ),
144+
);
145+
}
146+
}

0 commit comments

Comments
 (0)