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 / DeleteSourceRelayFailureTest.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
DeleteSourceRelayFailureTest.php
83 lines
1 <?php
2
3 namespace SmashBalloon\Reviews\Tests\Unit;
4
5 use PHPUnit\Framework\TestCase;
6 use SmashBalloon\Reviews\Common\Builder\SBR_Feed_Saver_Manager;
7
8 /**
9 * Pins SBR_Feed_Saver_Manager::relay_source_removed() — the relay/remove verdict
10 * used by delete_souce() (PR #482 Copilot review, C5).
11 *
12 * SBRelay::call() returns the full body on success (`success: true`) and the
13 * UNWRAPPED error envelope on failure (`{ id, code, success: false }`, NO `error`
14 * key). The original check gated on `$relay_response['error']`, which never
15 * matched a real failure, so a failed `source/remove` read as success and the
16 * source was deleted locally anyway — orphaning the relay-side source, which then
17 * keeps counting against the per-license source cap.
18 *
19 * These exercise the verdict directly across every envelope shape, so a relay
20 * rename (e.g. `sourceNotFound`) or a change to how `call()` unwraps errors can't
21 * silently re-orphan sources or start blocking legitimate deletes.
22 */
23 final class DeleteSourceRelayFailureTest extends TestCase
24 {
25 private static function removed($relay_response): bool
26 {
27 $m = new \ReflectionMethod(SBR_Feed_Saver_Manager::class, 'relay_source_removed');
28 $m->setAccessible(true);
29
30 return (bool) $m->invoke(null, $relay_response);
31 }
32
33 public function test_success_response_allows_local_delete(): void
34 {
35 // What `respondWithSuccess([], 'Source removed.')` looks like after call().
36 $this->assertTrue(self::removed(['success' => true, 'message' => 'Source removed.']));
37 }
38
39 public function test_generic_failure_blocks_local_delete(): void
40 {
41 // Unwrapped error envelope — the case the old `['error']` check missed.
42 $this->assertFalse(self::removed(['id' => 'unknownError', 'code' => 400, 'success' => false]));
43 }
44
45 public function test_auth_failure_blocks_local_delete(): void
46 {
47 $this->assertFalse(self::removed(['id' => 'invalidToken', 'code' => 401, 'success' => false]));
48 }
49
50 public function test_source_not_found_counts_as_removed(): void
51 {
52 $this->assertTrue(self::removed(['id' => 'sourceNotFound', 'code' => 404, 'success' => false]));
53 }
54
55 public function test_http_404_without_id_counts_as_removed(): void
56 {
57 $this->assertTrue(self::removed(['code' => 404, 'success' => false]));
58 }
59
60 public function test_unreachable_relay_fails_open(): void
61 {
62 // WP_Error → empty decoded body → proceed (prior, documented behaviour).
63 $this->assertTrue(self::removed([]));
64 }
65
66 public function test_malformed_id_or_code_does_not_fatal(): void
67 {
68 // Pathological shapes must not throw — just fall through to "not removed".
69 $this->assertFalse(self::removed(['id' => ['x'], 'code' => ['y'], 'success' => false]));
70 }
71
72 public function test_source_info_json_decode_is_array_guarded(): void
73 {
74 // C4: delete_souce() must coerce a malformed json_decode() result to an
75 // array before reading relay_source_id (PHP 8 offset-on-null guard).
76 $path = __DIR__ . '/../../class/Common/Builder/SBR_Feed_Saver_Manager.php';
77 $this->assertStringContainsString(
78 'if (!is_array($source_info))',
79 (string) file_get_contents($path)
80 );
81 }
82 }
83