Doubles
3 weeks ago
Providers
3 weeks ago
BulkRearmOnGrowthTest.php
3 weeks ago
BulkReviewsUpdateStuckStateTest.php
3 weeks ago
ClearCacheRelayResetTest.php
3 weeks ago
DeleteSourceRelayFailureTest.php
3 weeks ago
ErrorHandlerFalsyOptionTest.php
3 weeks ago
FeedCacheUpdateServiceTest.php
3 weeks ago
FeedMalformedPayloadTest.php
3 weeks ago
ForceKeylessRefetchTest.php
3 weeks ago
LicenseDeactivateStaleStateTest.php
3 weeks ago
MediaFinderMemoTest.php
3 weeks ago
MultiSourceAggregationTest.php
3 weeks ago
ReconcileMigratedLicenseRoutineTest.php
3 weeks ago
ReconcileRemovalTest.php
3 weeks ago
RegisterWebsiteRoutineTest.php
3 weeks ago
RemoteRequestMemoTest.php
3 weeks ago
ReviewAlertHeaderTotalsTest.php
3 weeks ago
ReviewAlertPageTargetingTest.php
3 weeks ago
ReviewAlertStarFillTest.php
3 weeks ago
ShortcodeNeutralizationTest.php
3 weeks ago
SiteMigrationRecoveryTest.php
3 weeks ago
Smash1583HeaderParityTest.php
3 weeks ago
Smash1631MultiLanguageBulkTest.php
3 weeks ago
Smash1631UpdateSingleLangScopeTest.php
3 weeks ago
Smash1706TripAdvisorPlaceIdTest.php
3 weeks ago
Smash1756SchemaServiceTest.php
3 weeks ago
Smash1785AvatarLocalUrlGuardTest.php
3 weeks ago
Smash1785AvatarReHealTest.php
3 weeks ago
Smash1795ReviewTextXssTest.php
3 weeks ago
Smash782BookingHeaderRatingTest.php
3 weeks ago
Smash782CountryFlagEmojiTest.php
3 weeks ago
Smash782ExternalRefreshCronTest.php
3 weeks ago
Smash782ExtrasTemplateTest.php
3 weeks ago
Smash782ReviewAlertProviderDataTest.php
3 weeks ago
SourceIdLookupTest.php
3 weeks ago
WpmlGetCurrentLanguageTest.php
3 weeks ago
WpmlLanguageMappingTest.php
3 weeks ago
Smash782CountryFlagEmojiTest.php
77 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 | * SMASH-782 follow-up (2026-07-08) — shared flag-emoji derivation. |
| 10 | * |
| 11 | * The AliExpress buyer-country flag was computed inline in two places with |
| 12 | * byte-identical logic: the feed author element (post-elements/author.php) and |
| 13 | * the Review Alerts popup (review-alerts/popup.php). Util::country_flag_emoji() |
| 14 | * now owns that computation so the feed and the alert render the same glyph |
| 15 | * from the same rules. These tests pin the extracted helper against the exact |
| 16 | * behaviour the two call sites relied on (2-letter/alpha validation, uppercase |
| 17 | * normalisation, the 0x1F1E6 regional-indicator codepoint math, and the safe |
| 18 | * empty-string fallback for anything not derivable). |
| 19 | */ |
| 20 | final class Smash782CountryFlagEmojiTest extends TestCase |
| 21 | { |
| 22 | /** |
| 23 | * The regional-indicator pair the old inline code would have produced for |
| 24 | * a valid 2-letter code — recomputed independently here so the test does |
| 25 | * not just echo the implementation. |
| 26 | * |
| 27 | * @param string $cc |
| 28 | * @return string |
| 29 | */ |
| 30 | private function expected($cc) |
| 31 | { |
| 32 | $up = strtoupper($cc); |
| 33 | $offset = 0x1F1E6 - ord('A'); |
| 34 | return mb_chr(ord($up[0]) + $offset, 'UTF-8') . mb_chr(ord($up[1]) + $offset, 'UTF-8'); |
| 35 | } |
| 36 | |
| 37 | public function test_valid_uppercase_code_maps_to_flag(): void |
| 38 | { |
| 39 | $this->assertSame($this->expected('US'), Util::country_flag_emoji('US')); |
| 40 | $this->assertSame($this->expected('DE'), Util::country_flag_emoji('DE')); |
| 41 | } |
| 42 | |
| 43 | public function test_lowercase_is_normalised_before_mapping(): void |
| 44 | { |
| 45 | $this->assertSame(Util::country_flag_emoji('US'), Util::country_flag_emoji('us')); |
| 46 | } |
| 47 | |
| 48 | public function test_surrounding_whitespace_is_trimmed(): void |
| 49 | { |
| 50 | $this->assertSame(Util::country_flag_emoji('GB'), Util::country_flag_emoji(' gb ')); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @dataProvider nonDerivableProvider |
| 55 | * @param mixed $input |
| 56 | */ |
| 57 | public function test_non_derivable_input_returns_empty_string($input): void |
| 58 | { |
| 59 | $this->assertSame('', Util::country_flag_emoji($input)); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return array<string, array{0: mixed}> |
| 64 | */ |
| 65 | public static function nonDerivableProvider(): array |
| 66 | { |
| 67 | return [ |
| 68 | 'empty' => [''], |
| 69 | 'one letter' => ['U'], |
| 70 | 'three letters' => ['USA'], |
| 71 | 'has digit' => ['U1'], |
| 72 | 'symbol' => ['@!'], |
| 73 | 'null' => [null], |
| 74 | ]; |
| 75 | } |
| 76 | } |
| 77 |