PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.10.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.10.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 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
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