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 / ReviewAlertStarFillTest.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
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