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