Index: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-locale-banner.php
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-locale-banner.php (revision 4914)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-locale-banner.php (working copy)
@@ -68,7 +68,7 @@
$current_locale = get_locale();
// Build a list of WordPress locales which we'll suggest to the user.
- $suggest_locales = array_values( array_intersect( $translated_locales, $locales_from_header ) );
+ $suggest_locales = array_values( array_intersect( $locales_from_header, $translated_locales ) );
$current_locale_is_suggested = in_array( $current_locale, $suggest_locales );
$current_locale_is_translated = in_array( $current_locale, $translated_locales );
@@ -262,8 +262,8 @@
}
foreach ( $available_locales as $locale ) {
- list( $lang, ) = preg_split( '/[_-]/', $locale );
- if ( $lang ) {
+ list( $locale_lang, ) = preg_split( '/[_-]/', $locale );
+ if ( $lang === $locale_lang ) {
return $locale;
}
}
Index: sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/phpunit/tests/api/locale-banner.php
===================================================================
--- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/phpunit/tests/api/locale-banner.php (nonexistent)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/phpunit/tests/api/locale-banner.php (working copy)
@@ -0,0 +1,57 @@
+ array(
+ 'Accept-Language' => $header
+ ),
+ ) );
+
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
+
+ $this->assertArrayHasKey( 'suggest_string', $data );
+ $this->assertArrayHasKey( 'translated', $data );
+ $this->assertInternalType( 'array', $data['translated'] );
+
+ preg_match_all( '#[a-z-]+.wordpress.org#', $data['suggest_string'], $sites );
+
+ $this->assertNotEmpty( $sites );
+ $this->assertEquals( $expected_sites, $sites[0] );
+ }
+
+ /**
+ * Data provider for test_locale_banner().
+ *
+ * @return array {
+ * @type array {
+ * @type string $header 'Accept-Language' header value.
+ * @type array $expected_sites Rosetta sites that should be present in the banner text.
+ * }
+ * }
+ */
+ function data_locale_banner() {
+ return array(
+ array(
+ 'en-US,en;q=0.8,ru;q=0.6,cs;q=0.4',
+ array( 'ru.wordpress.org', 'cs.wordpress.org' ),
+ ),
+ array(
+ 'en-US,en;q=0.8,da;q=0.6,nb;q=0.4,sv;q=0.2',
+ array( 'da.wordpress.org', 'nb.wordpress.org', 'sv.wordpress.org' ),
+ ),
+ );
+ }
+
+}