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