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