Repository navigation
Enhance data handling for Black Friday #3198
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
Merged
Merged
Changes from all commits
Commits
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
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,69 @@ | ||
| <?php | ||
| /** | ||
| * Tests for Main::add_black_friday_data(). | ||
| * | ||
| * @package gutenberg-blocks | ||
| */ | ||
|
|
||
| use ThemeIsle\GutenbergBlocks\Main; | ||
|
|
||
| /** | ||
| * Black Friday SDK data test case. | ||
| */ | ||
| class TestBlackFridayData extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Set up each test. | ||
| */ | ||
| public function set_up(): void { | ||
| parent::set_up(); | ||
|
|
||
| // The test bootstrap loads Composer before WordPress, so the SDK's load.php skips its helpers. | ||
| if ( ! function_exists( 'tsdk_translate_link' ) ) { | ||
| function tsdk_translate_link( string $link ): string { | ||
| return $link; | ||
| } | ||
| } | ||
|
|
||
| if ( ! function_exists( 'tsdk_utmify' ) ) { | ||
| function tsdk_utmify( string $link ): string { | ||
| return $link; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * An earlier filter returning an empty array opts out of the promotion, so it must stay empty. | ||
| */ | ||
| public function test_empty_configs_are_returned_unchanged(): void { | ||
| $this->assertSame( array(), ( new Main() )->add_black_friday_data( array() ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Configs whose default entry was removed upstream are passed through untouched. | ||
| */ | ||
| public function test_configs_without_default_are_returned_unchanged(): void { | ||
| $configs = array( | ||
| 'other-plugin' => array( 'message' => 'Other plugin sale' ), | ||
| ); | ||
|
|
||
| $this->assertSame( $configs, ( new Main() )->add_black_friday_data( $configs ) ); | ||
| } | ||
|
|
||
| /** | ||
| * The SDK default entry is extended into an Otter entry. | ||
| */ | ||
| public function test_default_config_adds_otter_entry(): void { | ||
| $default = array( | ||
| 'title' => 'Default title', | ||
| 'message' => 'Default message', | ||
| ); | ||
|
|
||
| $configs = ( new Main() )->add_black_friday_data( array( 'default' => $default ) ); | ||
|
|
||
| $this->assertSame( $default, $configs['default'] ); | ||
| $this->assertArrayHasKey( OTTER_PRODUCT_SLUG, $configs ); | ||
| $this->assertStringContainsString( 'otter-bf', $configs[ OTTER_PRODUCT_SLUG ]['sale_url'] ); | ||
| $this->assertNotSame( $default['message'], $configs[ OTTER_PRODUCT_SLUG ]['message'] ); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noteThe newempty()check also skips a present but emptydefault, such asarray( 'default' => array() ). Before this change, Otter still added its sale entry for that value. Does any supported filter send an emptydefaultand expect the Otter entry? If no, the change is safe. If yes, check! isset()instead, so an empty array still gets the entry.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No supported producer sends an empty
default. The SDK always seeds it fromget_notice_data(), a non-empty array oftitle,sale_url,messageandtime_left(Announcements.php:212-217). Everythemeisle_sdk_blackfriday_datacallback on the test install readsdefaultand none empties it, so an empty default only arrives when a filter blanks the sale data. Passing it through unchanged is the intended opt-out.