PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.6.7
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.6.7
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / tests / Unit / WpmlLanguageMappingTest.php
reviews-feed / tests / Unit Last commit date
Doubles 2 months ago Providers 2 months ago BulkReviewsUpdateStuckStateTest.php 2 months ago ClearCacheRelayResetTest.php 2 months ago DeleteSourceRelayFailureTest.php 2 months ago ErrorHandlerFalsyOptionTest.php 2 months ago FeedCacheUpdateServiceTest.php 2 months ago FeedMalformedPayloadTest.php 2 months ago ForceKeylessRefetchTest.php 2 months ago LicenseDeactivateStaleStateTest.php 2 months ago MediaFinderMemoTest.php 2 months ago MultiSourceAggregationTest.php 2 months ago ReconcileMigratedLicenseRoutineTest.php 2 months ago ReconcileRemovalTest.php 2 months ago RegisterWebsiteRoutineTest.php 2 months ago RemoteRequestMemoTest.php 2 months ago ReviewAlertHeaderTotalsTest.php 2 months ago ReviewAlertPageTargetingTest.php 2 months ago ReviewAlertStarFillTest.php 2 months ago ShortcodeNeutralizationTest.php 2 months ago SiteMigrationRecoveryTest.php 2 months ago Smash1583HeaderParityTest.php 2 months ago SourceIdLookupTest.php 2 months ago WpmlGetCurrentLanguageTest.php 2 months ago WpmlLanguageMappingTest.php 2 months ago
WpmlLanguageMappingTest.php
96 lines
1 <?php
2
3 namespace SmashBalloon\Reviews\Tests\Unit;
4
5 use PHPUnit\Framework\TestCase;
6 use SmashBalloon\Reviews\Common\Util;
7
8 /**
9 * Pins Util::map_wpml_to_google_language() — maps a WPML/locale code to a code the
10 * Google Places API actually accepts, so reviews come back translated (SMASH-1617,
11 * WPSA #62626). The reported case: a WPML `es-mx` site sent an unsupported code and
12 * Google returned reviews untranslated; this maps it to `es-419`.
13 *
14 * Pure static (only reads the in-code supported-language list), so it runs in the
15 * plain-PHPUnit suite.
16 */
17 final class WpmlLanguageMappingTest extends TestCase
18 {
19 /**
20 * @dataProvider provideCodes
21 *
22 * @param string|null $input
23 * @param string|null $expected
24 */
25 public function test_map_wpml_to_google_language($input, $expected): void
26 {
27 $this->assertSame($expected, Util::map_wpml_to_google_language($input));
28 }
29
30 /** @return array<string, array{0: string|null, 1: string|null}> */
31 public static function provideCodes(): array
32 {
33 return [
34 // --- The reported regression: every Latin-American Spanish variant -> es-419 ---
35 'es-mx -> es-419' => ['es-mx', 'es-419'],
36 'es_MX underscore' => ['es_MX', 'es-419'],
37 'ES-MX uppercase' => ['ES-MX', 'es-419'],
38 'es-ar -> es-419' => ['es-ar', 'es-419'],
39 'es-cl -> es-419' => ['es-cl', 'es-419'],
40 'es-co -> es-419' => ['es-co', 'es-419'],
41 'es-pe -> es-419' => ['es-pe', 'es-419'],
42 'es-ve -> es-419' => ['es-ve', 'es-419'],
43 'es-uy -> es-419' => ['es-uy', 'es-419'],
44 'es-419 exact' => ['es-419', 'es-419'],
45
46 // --- Spain Spanish stays es ---
47 'es -> es' => ['es', 'es'],
48 'es-es -> es' => ['es-es', 'es'],
49 'es-ES -> es' => ['es-ES', 'es'],
50 'es_ES underscore -> es' => ['es_ES', 'es'],
51
52 // --- Already-supported codes pass through unchanged (BC) ---
53 'en exact' => ['en', 'en'],
54 'en-GB exact' => ['en-GB', 'en-GB'],
55 'en-AU exact' => ['en-AU', 'en-AU'],
56 'fr exact' => ['fr', 'fr'],
57 'fr-CA exact' => ['fr-CA', 'fr-CA'],
58 'pt exact' => ['pt', 'pt'],
59 'pt-BR exact' => ['pt-BR', 'pt-BR'],
60 'pt-PT exact' => ['pt-PT', 'pt-PT'],
61 'zh exact' => ['zh', 'zh'],
62 'zh-CN exact' => ['zh-CN', 'zh-CN'],
63 'zh-TW exact' => ['zh-TW', 'zh-TW'],
64 'hy (Armenian) exact' => ['hy', 'hy'],
65
66 // --- Case-insensitive match for region variants Google lists ---
67 'en-gb -> en-GB' => ['en-gb', 'en-GB'],
68 'en-au -> en-AU' => ['en-au', 'en-AU'],
69 'pt-br -> pt-BR' => ['pt-br', 'pt-BR'],
70 'pt_br underscore -> pt-BR' => ['pt_br', 'pt-BR'],
71 'fr-ca -> fr-CA' => ['fr-ca', 'fr-CA'],
72 'zh-tw -> zh-TW' => ['zh-tw', 'zh-TW'],
73 'zh-hk -> zh-HK' => ['zh-hk', 'zh-HK'],
74
75 // --- Region strip to a supported base language ---
76 'en-us -> en' => ['en-us', 'en'],
77 'fr-fr -> fr' => ['fr-fr', 'fr'],
78 'de-de -> de' => ['de-de', 'de'],
79 'de_DE underscore -> de' => ['de_DE', 'de'],
80 'it-it -> it' => ['it-it', 'it'],
81 'nl-nl -> nl' => ['nl-nl', 'nl'],
82 'ja-jp -> ja' => ['ja-jp', 'ja'],
83 'ru-ru -> ru' => ['ru-ru', 'ru'],
84 'EN uppercase base -> en' => ['EN', 'en'],
85
86 // --- Unmappable -> null so the caller falls back (never sends a bogus code) ---
87 'literal wpml -> null' => ['wpml', null],
88 'unknown 2-letter -> null' => ['xx', null],
89 'unknown region -> null' => ['xx-yy', null],
90 'gibberish -> null' => ['zz-zz', null],
91 'empty string -> null' => ['', null],
92 'null -> null' => [null, null],
93 ];
94 }
95 }
96