PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.9.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.9.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 / Smash782ReviewAlertProviderDataTest.php
reviews-feed / tests / Unit Last commit date
Doubles 1 month ago Providers 1 month ago BulkRearmOnGrowthTest.php 1 month ago BulkReviewsUpdateStuckStateTest.php 1 month ago ClearCacheRelayResetTest.php 1 month ago DeleteSourceRelayFailureTest.php 1 month ago ErrorHandlerFalsyOptionTest.php 1 month ago FeedCacheUpdateServiceTest.php 1 month ago FeedMalformedPayloadTest.php 1 month ago ForceKeylessRefetchTest.php 1 month ago LicenseDeactivateStaleStateTest.php 1 month ago MediaFinderMemoTest.php 1 month ago MultiSourceAggregationTest.php 1 month ago ReconcileMigratedLicenseRoutineTest.php 1 month ago ReconcileRemovalTest.php 1 month ago RegisterWebsiteRoutineTest.php 1 month ago RemoteRequestMemoTest.php 1 month ago ReviewAlertHeaderTotalsTest.php 1 month ago ReviewAlertPageTargetingTest.php 1 month ago ReviewAlertStarFillTest.php 1 month ago ShortcodeNeutralizationTest.php 1 month ago SiteMigrationRecoveryTest.php 1 month ago Smash1583HeaderParityTest.php 1 month ago Smash1631MultiLanguageBulkTest.php 1 month ago Smash1631UpdateSingleLangScopeTest.php 1 month ago Smash1706TripAdvisorPlaceIdTest.php 1 month ago Smash782BookingHeaderRatingTest.php 1 month ago Smash782CountryFlagEmojiTest.php 1 month ago Smash782ExternalRefreshCronTest.php 1 month ago Smash782ExtrasTemplateTest.php 1 month ago Smash782ReviewAlertProviderDataTest.php 1 month ago SourceIdLookupTest.php 1 month ago WpmlGetCurrentLanguageTest.php 1 month ago WpmlLanguageMappingTest.php 1 month ago
Smash782ReviewAlertProviderDataTest.php
114 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 * SMASH-782 — Review Alert provider-data pass-through (data layer).
10 *
11 * The alert popup renders the same provider-specific elements the feed does
12 * (Booking pros/cons + 0-10 score + helpful + photos, AliExpress variants /
13 * translated / buyer-flag / followup, Airbnb reply). Those all live in the
14 * review's `metadata` / `reply` / `title` / `reviewer_photos`, but the frontend
15 * formatter previously emitted only a whitelist (id/text/rating/time/reviewer/
16 * provider), so the popup never received them. This guards that the formatter
17 * now forwards the provider shape (additive — the original keys are unchanged).
18 *
19 * Reflection is used because format_reviews_for_frontend() is private and reads
20 * only its argument (no WP/DB state).
21 */
22 final class Smash782ReviewAlertProviderDataTest extends TestCase
23 {
24 /** @param array<int,array<string,mixed>> $reviews */
25 private function format(array $reviews): array
26 {
27 $fe = (new \ReflectionClass(SBR_Review_Alert_Frontend::class))->newInstanceWithoutConstructor();
28 $m = new \ReflectionMethod($fe, 'format_reviews_for_frontend');
29 $m->setAccessible(true);
30 return $m->invoke($fe, $reviews);
31 }
32
33 public function test_booking_review_forwards_metadata_title_and_photos(): void
34 {
35 $out = $this->format([[
36 'review_id' => 'b1',
37 'text' => 'Great stay',
38 'title' => 'It was excellent',
39 'rating' => 5,
40 'reviewer' => ['name' => 'Alison', 'avatar' => ''],
41 'provider' => ['name' => 'booking'],
42 'metadata' => [
43 'pros' => 'Spacious room',
44 'cons' => 'Pricey breakfast',
45 'review_score' => 8.6,
46 'review_score_word' => 'Fabulous',
47 'helpful_vote_count' => 14,
48 ],
49 'reviewer_photos' => [['90_90' => 'https://x/a.jpg']],
50 'source' => ['id' => '1377073'],
51 ]]);
52 $r = $out[0];
53 $this->assertSame('It was excellent', $r['title']);
54 $this->assertSame('Spacious room', $r['metadata']['pros']);
55 $this->assertSame('Pricey breakfast', $r['metadata']['cons']);
56 $this->assertSame(8.6, $r['metadata']['review_score']);
57 $this->assertSame(14, $r['metadata']['helpful_vote_count']);
58 $this->assertNotEmpty($r['reviewer_photos']);
59 $this->assertSame('1377073', $r['source']['id']);
60 }
61
62 public function test_aliexpress_review_forwards_variants_translated_flag(): void
63 {
64 $out = $this->format([[
65 'text' => 'Nice shirt',
66 'rating' => 4,
67 'reviewer' => ['name' => 'Shopper'],
68 'provider' => ['name' => 'aliexpress'],
69 'metadata' => [
70 'item_spec' => 'Color:Black Size:XL',
71 'translated' => true,
72 'buyer_country' => 'US',
73 ],
74 ]]);
75 $md = $out[0]['metadata'];
76 $this->assertSame('Color:Black Size:XL', $md['item_spec']);
77 $this->assertTrue($md['translated']);
78 $this->assertSame('US', $md['buyer_country']);
79 }
80
81 public function test_airbnb_review_forwards_reply(): void
82 {
83 $out = $this->format([[
84 'text' => 'Lovely place',
85 'rating' => 5,
86 'reviewer' => ['name' => 'Jamie'],
87 'provider' => ['name' => 'airbnb'],
88 'response' => 'Thanks for staying!',
89 'reply' => ['name' => 'Host', 'avatar' => ''],
90 ]]);
91 $this->assertSame('Thanks for staying!', $out[0]['response']);
92 $this->assertSame('Host', $out[0]['reply']['name']);
93 }
94
95 public function test_missing_provider_data_degrades_to_safe_empties_bc(): void
96 {
97 // A Google/legacy review with none of the new keys must not error and
98 // must keep the original contract intact.
99 $out = $this->format([[
100 'text' => 'Good',
101 'rating' => 5,
102 'reviewer' => ['name' => 'Sam'],
103 'provider' => ['name' => 'google'],
104 ]]);
105 $r = $out[0];
106 $this->assertSame('Good', $r['text']);
107 $this->assertSame([], $r['metadata']);
108 $this->assertSame([], $r['reply']);
109 $this->assertSame('', $r['response']);
110 $this->assertSame([], $r['reviewer_photos']);
111 $this->assertSame('', $r['title']);
112 }
113 }
114