PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.11.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.11.0
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 / ReviewAlertStarFillTest.php
reviews-feed / tests / Unit Last commit date
Doubles 1 week ago Providers 1 week ago BulkRearmOnGrowthTest.php 1 week ago BulkReviewsUpdateStuckStateTest.php 1 week ago ClearCacheRelayResetTest.php 1 week ago DeleteSourceRelayFailureTest.php 1 week ago ErrorHandlerFalsyOptionTest.php 1 week ago FeedCacheUpdateServiceTest.php 1 week ago FeedMalformedPayloadTest.php 1 week ago ForceKeylessRefetchTest.php 1 week ago LicenseDeactivateStaleStateTest.php 1 week ago MediaFinderMemoTest.php 1 week ago MultiSourceAggregationTest.php 1 week ago ReconcileMigratedLicenseRoutineTest.php 1 week ago ReconcileRemovalTest.php 1 week ago RegisterWebsiteRoutineTest.php 1 week ago RelaySlowEndpointsTest.php 1 week ago RemoteRequestMemoTest.php 1 week ago ReviewAlertHeaderTotalsTest.php 1 week ago ReviewAlertPageTargetingTest.php 1 week ago ReviewAlertStarFillTest.php 1 week ago ShortcodeNeutralizationTest.php 1 week ago SiteMigrationRecoveryTest.php 1 week ago Smash1130UsageTrackingHardeningTest.php 1 week ago Smash1130UsageTrackingHooksTest.php 1 week ago Smash1583HeaderParityTest.php 1 week ago Smash1631MultiLanguageBulkTest.php 1 week ago Smash1631UpdateSingleLangScopeTest.php 1 week ago Smash1706TripAdvisorPlaceIdTest.php 1 week ago Smash1756SchemaServiceTest.php 1 week ago Smash1785AvatarLocalUrlGuardTest.php 1 week ago Smash1785AvatarReHealTest.php 1 week ago Smash1795ReviewTextXssTest.php 1 week ago Smash1835TripAdvisorKeyShapeTest.php 1 week ago Smash1973WordpressOrgPlaceIdNullTest.php 1 week ago Smash1987NestedSourceErrorShapeTest.php 1 week ago Smash782BookingHeaderRatingTest.php 1 week ago Smash782CountryFlagEmojiTest.php 1 week ago Smash782ExternalRefreshCronTest.php 1 week ago Smash782ExtrasTemplateTest.php 1 week ago Smash782ReviewAlertProviderDataTest.php 1 week ago SourceIdLookupTest.php 1 week ago WpmlGetCurrentLanguageTest.php 1 week ago WpmlLanguageMappingTest.php 1 week 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