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 / ReviewAlertPageTargetingTest.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
ReviewAlertPageTargetingTest.php
99 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 the Review Alert page-targeting fix (SMASH-1616).
10 *
11 * Before: the page-targeting dropdown only listed the `page` post type
12 * (get_pages), and the frontend matcher matched custom post types only by SLUG
13 * (whole type). So a page-builder landing page (a CPT) couldn't be targeted
14 * individually — selectable-but-never-fires.
15 *
16 * After: the builder lists `page` + public custom post types; and the matcher's
17 * `custom_post_type` case keeps the slug whole-type match AND adds a per-post-ID
18 * fallback against the selected `pages` list, so an individually-selected landing
19 * page fires.
20 *
21 * The `custom_post_type` matcher branch uses only `extract_visibility_ids` (pure),
22 * so it runs in the plain-PHPUnit suite via reflection. The builder change is a
23 * source-guard (it calls WP `get_post_types`/`get_posts`).
24 */
25 final class ReviewAlertPageTargetingTest extends TestCase
26 {
27 private static function locationMatches(array $location, array $list): bool
28 {
29 $ref = new \ReflectionClass(SBR_Review_Alert_Frontend::class);
30 $obj = $ref->newInstanceWithoutConstructor();
31 $m = $ref->getMethod('is_location_in_list');
32 $m->setAccessible(true);
33
34 return (bool) $m->invoke($obj, $location, $list);
35 }
36
37 public function test_cpt_single_matches_by_post_id_in_pages_list(): void
38 {
39 // A landing page (CPT) selected individually is stored under `pages` by ID.
40 $location = ['type' => 'custom_post_type', 'id' => 'e-landing-page', 'post_id' => 1234];
41 $list = ['pages' => [['id' => 1234, 'title' => 'Landing', 'url' => '/x']]];
42 $this->assertTrue(self::locationMatches($location, $list), 'CPT single must fire when its post ID is in the pages list');
43 }
44
45 public function test_cpt_whole_type_slug_match_preserved(): void
46 {
47 $location = ['type' => 'custom_post_type', 'id' => 'e-landing-page', 'post_id' => 1234];
48 $list = ['custom_post_types' => [['name' => 'e-landing-page']]];
49 $this->assertTrue(self::locationMatches($location, $list), 'Whole-type (slug) targeting must still work');
50 }
51
52 public function test_cpt_no_match_when_neither_id_nor_slug_listed(): void
53 {
54 $location = ['type' => 'custom_post_type', 'id' => 'e-landing-page', 'post_id' => 1234];
55 $list = ['pages' => [['id' => 9999]], 'custom_post_types' => [['name' => 'other']]];
56 $this->assertFalse(self::locationMatches($location, $list));
57 }
58
59 public function test_cpt_archive_without_post_id_still_slug_matches(): void
60 {
61 // A post-type ARCHIVE has no post_id; it must still match by slug.
62 $location = ['type' => 'custom_post_type', 'id' => 'e-landing-page'];
63 $list = ['custom_post_types' => [['name' => 'e-landing-page']]];
64 $this->assertTrue(self::locationMatches($location, $list));
65 }
66
67 public function test_cpt_archive_without_post_id_does_not_match_pages(): void
68 {
69 // No post_id → the per-ID fallback must be skipped (no accidental match).
70 $location = ['type' => 'custom_post_type', 'id' => 'e-landing-page'];
71 $list = ['pages' => [['id' => 0]]];
72 $this->assertFalse(self::locationMatches($location, $list));
73 }
74
75 public function test_bc_legacy_plain_page_id_still_matches(): void
76 {
77 // Old saved format: pages as plain ints. The page-case ID check fires
78 // before any WooCommerce conditional, so this needs no WP context.
79 $location = ['type' => 'page', 'id' => 55];
80 $list = ['pages' => [55]];
81 $this->assertTrue(self::locationMatches($location, $list));
82 }
83
84 public function test_builder_lists_public_post_types_not_only_pages(): void
85 {
86 $src = (string) file_get_contents(__DIR__ . '/../../class/Common/ReviewAlerts/SBR_ReviewAlert_Builder.php');
87 $this->assertStringContainsString(
88 "get_post_types(['public' => true, '_builtin' => false]",
89 $src,
90 'Builder must enumerate public custom post types, not just pages'
91 );
92 $this->assertStringNotContainsString(
93 "get_pages(['post_status' => 'publish'])",
94 $src,
95 'Builder must no longer use get_pages() (page-type only)'
96 );
97 }
98 }
99