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 / RegisterWebsiteRoutineTest.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
RegisterWebsiteRoutineTest.php
77 lines
1 <?php
2
3 namespace SmashBalloon\Reviews\Tests\Unit;
4
5 use PHPUnit\Framework\TestCase;
6 use SmashBalloon\Reviews\Common\Services\Upgrade\Routines\RegisterWebsiteRoutine;
7
8 /**
9 * Regression coverage for the rate-limit transient that bounds /auth/register
10 * traffic per site to 1 call / 5 minutes regardless of upstream loop behaviour.
11 *
12 * @see SMASH-1274 — the earlier 2.5.3 version of this routine cleared the
13 * transient on successful registration, which defeated the limiter during
14 * the migration-detect loop (token wipe + successful re-register +
15 * transient clear repeated every request). 2.5.5 keeps the transient
16 * active regardless of outcome.
17 */
18 class RegisterWebsiteRoutineTest extends TestCase
19 {
20 protected function setUp(): void
21 {
22 parent::setUp();
23 global $wp_options_mock, $wp_transients_mock, $wp_home_url_mock;
24 $wp_options_mock = [];
25 $wp_transients_mock = [];
26 $wp_home_url_mock = 'https://example.com';
27 }
28
29 /** Exposes protected will_run() for direct testing. */
30 private function will_run(RegisterWebsiteRoutine $routine): bool
31 {
32 $reflection = new \ReflectionClass($routine);
33 $method = $reflection->getMethod('will_run');
34 $method->setAccessible(true);
35 return (bool) $method->invoke($routine);
36 }
37
38 public function test_will_run_returns_true_when_no_token_and_no_cooldown(): void
39 {
40 global $wp_options_mock;
41 $wp_options_mock['sbr_settings'] = [];
42
43 $this->assertTrue($this->will_run(new RegisterWebsiteRoutine()));
44 }
45
46 public function test_will_run_returns_false_when_token_is_present(): void
47 {
48 global $wp_options_mock;
49 $wp_options_mock['sbr_settings'] = ['access_token' => 'tok-abc'];
50
51 $this->assertFalse($this->will_run(new RegisterWebsiteRoutine()));
52 }
53
54 /**
55 * Core regression for the 2.5.5 fix — when the cooldown transient is set,
56 * will_run() must return false even though the access_token is empty. If
57 * it doesn't, the migration-detect loop (wipe → re-register → repeat)
58 * will hammer /auth/register regardless of the rate-limit intent.
59 */
60 public function test_will_run_returns_false_when_cooldown_transient_is_set(): void
61 {
62 global $wp_options_mock, $wp_transients_mock;
63 $wp_options_mock['sbr_settings'] = []; // no access_token
64 $wp_transients_mock['sbr_register_retry_cooldown'] = time();
65
66 $this->assertFalse($this->will_run(new RegisterWebsiteRoutine()));
67 }
68
69 public function test_will_run_returns_true_on_corrupted_settings(): void
70 {
71 global $wp_options_mock;
72 $wp_options_mock['sbr_settings'] = 'not-an-array'; // simulate corruption
73
74 $this->assertTrue($this->will_run(new RegisterWebsiteRoutine()));
75 }
76 }
77