Doubles
1 month ago
Providers
1 month ago
BulkRearmOnGrowthTest.php
1 month ago
BulkReviewsUpdateStuckStateTest.php
1 month ago
ClearCacheRelayResetTest.php
1 month ago
DeleteSourceRelayFailureTest.php
1 month ago
ErrorHandlerFalsyOptionTest.php
1 month ago
FeedCacheUpdateServiceTest.php
1 month ago
FeedMalformedPayloadTest.php
1 month ago
ForceKeylessRefetchTest.php
1 month ago
LicenseDeactivateStaleStateTest.php
1 month ago
MediaFinderMemoTest.php
1 month ago
MultiSourceAggregationTest.php
1 month ago
ReconcileMigratedLicenseRoutineTest.php
1 month ago
ReconcileRemovalTest.php
1 month ago
RegisterWebsiteRoutineTest.php
1 month ago
RemoteRequestMemoTest.php
1 month ago
ReviewAlertHeaderTotalsTest.php
1 month ago
ReviewAlertPageTargetingTest.php
1 month ago
ReviewAlertStarFillTest.php
1 month ago
ShortcodeNeutralizationTest.php
1 month ago
SiteMigrationRecoveryTest.php
1 month ago
Smash1583HeaderParityTest.php
1 month ago
Smash1631MultiLanguageBulkTest.php
1 month ago
Smash1631UpdateSingleLangScopeTest.php
1 month ago
Smash1706TripAdvisorPlaceIdTest.php
1 month ago
Smash782BookingHeaderRatingTest.php
1 month ago
Smash782CountryFlagEmojiTest.php
1 month ago
Smash782ExternalRefreshCronTest.php
1 month ago
Smash782ExtrasTemplateTest.php
1 month ago
Smash782ReviewAlertProviderDataTest.php
1 month ago
SourceIdLookupTest.php
1 month ago
WpmlGetCurrentLanguageTest.php
1 month ago
WpmlLanguageMappingTest.php
1 month ago
ReviewAlertStarFillTest.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SmashBalloon\Reviews\Tests\Unit; |
| 4 | |
| 5 | use PHPUnit\Framework\TestCase; |
| 6 | use SmashBalloon\Reviews\Common\ReviewAlerts\SBR_Review_Alert_Frontend; |
| 7 | |
| 8 | /** |
| 9 | * Pins SBR_Review_Alert_Frontend::star_fill_states() — the one formula that |
| 10 | * turns an average rating into per-star full/half/empty glyphs (SMASH-1616). |
| 11 | * |
| 12 | * This is the AUTHORITATIVE side of a cross-language contract: the popup |
| 13 | * template (templates/review-alerts/popup.php) consumes this, and the |
| 14 | * customizer's React starFillStates() in ReviewAlertPreview.js mirrors this |
| 15 | * exact formula. The original bug was the preview pre-rounding the average |
| 16 | * (Math.round(4.7) -> 5 solid stars) while the frontend drew 4 + a half — so |
| 17 | * "4.7 -> 4 full + 1 half" is the case that must hold on both sides. |
| 18 | */ |
| 19 | final class ReviewAlertStarFillTest extends TestCase |
| 20 | { |
| 21 | /** |
| 22 | * @dataProvider provideRatings |
| 23 | * |
| 24 | * @param string[] $expected |
| 25 | */ |
| 26 | public function test_star_fill_states(float $average, array $expected): void |
| 27 | { |
| 28 | $this->assertSame($expected, SBR_Review_Alert_Frontend::star_fill_states($average)); |
| 29 | } |
| 30 | |
| 31 | /** @return array<string, array{0: float, 1: string[]}> */ |
| 32 | public static function provideRatings(): array |
| 33 | { |
| 34 | $f = 'full'; |
| 35 | $h = 'half'; |
| 36 | $e = 'empty'; |
| 37 | |
| 38 | return [ |
| 39 | // The headline regression case: Cosmetic source 4.7 (Google). |
| 40 | '4.7 -> 4 full + 1 half' => [4.7, [$f, $f, $f, $f, $h]], |
| 41 | // Collection Cosmetic+Lombard weighted 4.6. |
| 42 | '4.6 -> 4 full + 1 half' => [4.6, [$f, $f, $f, $f, $h]], |
| 43 | // Exact .5 boundary rounds toward half, not full. |
| 44 | '4.5 -> 4 full + 1 half' => [4.5, [$f, $f, $f, $f, $h]], |
| 45 | // Just under .5 stays empty (no premature half). |
| 46 | '4.4 -> 4 full + 1 empty' => [4.4, [$f, $f, $f, $f, $e]], |
| 47 | // Whole number: no half. |
| 48 | '4.0 -> 4 full + 1 empty' => [4.0, [$f, $f, $f, $f, $e]], |
| 49 | // Lombard source 3.4 (Yelp): 3.4 < 3.5 so the 4th star is empty. |
| 50 | '3.4 -> 3 full + 2 empty' => [3.4, [$f, $f, $f, $e, $e]], |
| 51 | // Perfect score: all full, no overflow. |
| 52 | '5.0 -> 5 full' => [5.0, [$f, $f, $f, $f, $f]], |
| 53 | // Zero / missing metadata: all empty. |
| 54 | '0.0 -> 5 empty' => [0.0, [$e, $e, $e, $e, $e]], |
| 55 | ]; |
| 56 | } |
| 57 | } |
| 58 |