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 / ReviewAlertHeaderTotalsTest.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
ReviewAlertHeaderTotalsTest.php
73 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::resolve_header_totals() — the shared helper that
10 * gives a Review Alert the SAME headline total + average as the feed header
11 * (SMASH-1616). Used by both the frontend render path and the customizer preview
12 * (SBR_Review_Alert_Service::get_preview_reviews), so this one test guards both.
13 *
14 * It's a pure static seam (the only WP touch is the $feed's get_header_data(),
15 * which we stub), so it runs in the plain-PHPUnit suite.
16 */
17 final class ReviewAlertHeaderTotalsTest extends TestCase
18 {
19 /** A minimal Feed stand-in exposing get_header_data(). */
20 private static function feedWith(array $businesses): object
21 {
22 return new class ($businesses) {
23 private $businesses;
24 public function __construct(array $b)
25 {
26 $this->businesses = $b;
27 }
28 public function get_header_data(): array
29 {
30 return $this->businesses;
31 }
32 };
33 }
34
35 public function test_uses_source_metadata_total_and_average(): void
36 {
37 // Keyless Google: ~9 cached, but metadata carries 211 / 4.7.
38 $feed = self::feedWith([['info' => ['rating' => 4.7, 'total_rating' => 211]]]);
39 [$total, $average] = SBR_Review_Alert_Frontend::resolve_header_totals($feed, [], 9, 45);
40 $this->assertSame(211, $total);
41 $this->assertSame(4.7, $average);
42 }
43
44 public function test_collection_sums_total_and_weights_average(): void
45 {
46 // Google (4.7/211) + Yelp The Lombard (3.4/25) → 236 total, weighted 4.6 (not 4.05).
47 $feed = self::feedWith([
48 ['info' => ['rating' => 4.7, 'total_rating' => 211]],
49 ['info' => ['rating' => 3.4, 'total_rating' => 25]],
50 ]);
51 [$total, $average] = SBR_Review_Alert_Frontend::resolve_header_totals($feed, [], 9, 45);
52 $this->assertSame(236, $total);
53 $this->assertSame(4.6, $average);
54 }
55
56 public function test_falls_back_to_cached_when_no_metadata(): void
57 {
58 // Manual feed / provider with no count → use the cached complete-review set.
59 $feed = self::feedWith([]);
60 [$total, $average] = SBR_Review_Alert_Frontend::resolve_header_totals($feed, [], 8, 36);
61 $this->assertSame(8, $total);
62 $this->assertSame(4.5, $average); // 36 / 8
63 }
64
65 public function test_zero_cached_no_metadata_defaults_to_five(): void
66 {
67 $feed = self::feedWith([]);
68 [$total, $average] = SBR_Review_Alert_Frontend::resolve_header_totals($feed, [], 0, 0);
69 $this->assertSame(0, $total);
70 $this->assertSame(5.0, $average);
71 }
72 }
73