-
Notifications
You must be signed in to change notification settings - Fork 58
fix(reader-data): make is_donor read-only only when platform has server-side tracking #4641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jason10lee
wants to merge
4
commits into
trunk
Choose a base branch
from
fix/allow-non-woo-is-donor-write
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+192
−10
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1dde930
fix: `is_donor` read-only only on WooCommerce-backed donations
jason10lee e522308
test: verify read-only keys behavior
jason10lee 8b596d3
docs: acknowledge `is_donor` is not uniformly read-only and offer a t…
jason10lee eba769a
test: properly tear down our test filter after each run
jason10lee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| <?php | ||
| /** | ||
| * Tests for platform-conditional read-only key enforcement in Reader_Data. | ||
| * | ||
| * @package Newspack\Tests | ||
| * @group reader-data-read-only | ||
| */ | ||
|
|
||
| use Newspack\Donations; | ||
| use Newspack\Reader_Data; | ||
|
|
||
| /** | ||
| * Tests for Reader_Data read-only key behavior based on donation platform. | ||
| * | ||
| * @group reader-data-read-only | ||
| */ | ||
| class Newspack_Test_Reader_Data_Read_Only_Keys extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tear down after each test — reset platform to default. | ||
| */ | ||
| public function tear_down() { | ||
| Donations::set_platform_slug( 'wc' ); | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Test that has_server_side_donor_tracking() returns true for WooCommerce. | ||
| */ | ||
| public function test_has_server_side_donor_tracking_wc() { | ||
| Donations::set_platform_slug( 'wc' ); | ||
| self::assertTrue( | ||
| Donations::has_server_side_donor_tracking(), | ||
| 'WooCommerce platform should have server-side donor tracking.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that has_server_side_donor_tracking() returns false for NRH. | ||
| */ | ||
| public function test_has_server_side_donor_tracking_nrh() { | ||
| Donations::set_platform_slug( 'nrh' ); | ||
| self::assertFalse( | ||
| Donations::has_server_side_donor_tracking(), | ||
| 'NRH platform should not have server-side donor tracking.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that has_server_side_donor_tracking() returns false for other. | ||
| */ | ||
| public function test_has_server_side_donor_tracking_other() { | ||
| Donations::set_platform_slug( 'other' ); | ||
| self::assertFalse( | ||
| Donations::has_server_side_donor_tracking(), | ||
| 'Other platform should not have server-side donor tracking.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that is_donor is read-only on WooCommerce platform. | ||
| */ | ||
| public function test_is_donor_read_only_on_wc() { | ||
| Donations::set_platform_slug( 'wc' ); | ||
| self::assertContains( | ||
| 'is_donor', | ||
| Reader_Data::get_read_only_keys(), | ||
| 'is_donor should be read-only on WooCommerce platform.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that is_donor is writable on NRH platform. | ||
| */ | ||
| public function test_is_donor_writable_on_nrh() { | ||
| Donations::set_platform_slug( 'nrh' ); | ||
| self::assertNotContains( | ||
| 'is_donor', | ||
| Reader_Data::get_read_only_keys(), | ||
| 'is_donor should be writable on NRH platform.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that is_donor is writable on other platform. | ||
| */ | ||
| public function test_is_donor_writable_on_other() { | ||
| Donations::set_platform_slug( 'other' ); | ||
| self::assertNotContains( | ||
| 'is_donor', | ||
| Reader_Data::get_read_only_keys(), | ||
| 'is_donor should be writable on other platform.' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that is_former_donor is always read-only regardless of platform. | ||
| * | ||
| * @dataProvider platform_provider | ||
| * @param string $platform Platform slug. | ||
| */ | ||
| public function test_is_former_donor_always_read_only( $platform ) { | ||
| Donations::set_platform_slug( $platform ); | ||
| self::assertContains( | ||
| 'is_former_donor', | ||
| Reader_Data::get_read_only_keys(), | ||
| "is_former_donor should be read-only on {$platform} platform." | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that the newspack_reader_data_read_only_keys filter still works. | ||
| */ | ||
| public function test_filter_can_add_custom_key() { | ||
| $add_key = function ( $keys ) { | ||
| $keys[] = 'custom_key'; | ||
| return $keys; | ||
| }; | ||
| add_filter( 'newspack_reader_data_read_only_keys', $add_key ); | ||
|
|
||
| self::assertContains( | ||
| 'custom_key', | ||
| Reader_Data::get_read_only_keys(), | ||
| 'Filter should be able to add custom read-only keys.' | ||
| ); | ||
|
|
||
| remove_filter( 'newspack_reader_data_read_only_keys', $add_key ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for all platform slugs. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public function platform_provider() { | ||
| return [ | ||
| 'wc' => [ 'wc' ], | ||
| 'nrh' => [ 'nrh' ], | ||
| 'other' => [ 'other' ], | ||
| ]; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.