-
Notifications
You must be signed in to change notification settings - Fork 214
Temporarily disable Photon screenshot srcset in Plugin Directory #859
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
Closed
dan-zakirov
wants to merge
2
commits into
WordPress:trunk
from
dan-zakirov:dan/plugin-screenshots-disable-photon-srcset
Closed
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
66 changes: 66 additions & 0 deletions
66
.../public_html/wp-content/plugins/plugin-directory/tests/Screenshots_Photon_Srcset_Test.php
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,66 @@ | ||
| <?php | ||
| /** | ||
| * Tests for screenshot image sources. | ||
| * | ||
| * @package WordPressdotorg\Plugin_Directory\Tests | ||
| */ | ||
|
|
||
| declare( strict_types = 1 ); | ||
|
|
||
| namespace WordPressdotorg\Plugin_Directory\Shortcodes; | ||
|
|
||
| use PHPUnit\Framework\Attributes\Group; | ||
| use PHPUnit\Framework\TestCase; | ||
| use ReflectionMethod; | ||
|
|
||
| require_once __DIR__ . '/fixtures/production-environment.php'; | ||
|
|
||
| /** | ||
| * Tests that screenshot markup avoids Photon resize candidates. | ||
| * | ||
| * @group shortcodes | ||
| */ | ||
| #[Group( 'shortcodes' )] | ||
| class Screenshots_Photon_Srcset_Test extends TestCase { | ||
|
|
||
| /** | ||
| * Screenshot markup keeps the revision-aware source without a Photon srcset. | ||
| */ | ||
| public function test_image_block_uses_direct_source_without_photon_srcset(): void { | ||
| $source = 'https://ps.w.org/srcset-regression/assets/screenshot-1.png?rev=123'; | ||
| $method = new ReflectionMethod( Screenshots::class, 'build_image_block' ); | ||
| $post_id = wp_insert_post( | ||
| array( | ||
| 'post_name' => 'srcset-regression', | ||
| 'post_title' => 'Srcset Regression', | ||
| 'post_type' => 'plugin', | ||
| 'post_status' => 'publish', | ||
| 'post_modified' => current_time( 'mysql' ), | ||
| 'post_modified_gmt' => current_time( 'mysql', true ), | ||
| ) | ||
| ); | ||
|
|
||
| setup_postdata( get_post( $post_id ) ); | ||
|
|
||
| try { | ||
| $markup = $method->invoke( | ||
| null, | ||
| array( | ||
| 'src' => $source, | ||
| 'filename' => 'screenshot-1.png', | ||
| 'revision' => 123, | ||
| ), | ||
| 9000001, | ||
| true, | ||
| array( 1200, 800 ) | ||
| ); | ||
| } finally { | ||
| wp_reset_postdata(); | ||
| wp_delete_post( $post_id, true ); | ||
| } | ||
|
|
||
| $this->assertStringContainsString( 'src="' . $source . '"', $markup ); | ||
| $this->assertStringNotContainsString( 'srcset=', $markup ); | ||
| $this->assertStringNotContainsString( 'i0.wp.com', $markup ); | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
...public_html/wp-content/plugins/plugin-directory/tests/fixtures/production-environment.php
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,17 @@ | ||
| <?php | ||
| /** | ||
| * Production environment fixture for shortcode tests. | ||
| * | ||
| * @package WordPressdotorg\Plugin_Directory\Tests | ||
| */ | ||
|
|
||
| namespace WordPressdotorg\Plugin_Directory\Shortcodes; | ||
|
|
||
| /** | ||
| * Forces the production path in the shortcode namespace. | ||
| * | ||
| * @return string The environment type. | ||
| */ | ||
| function wp_get_environment_type() { | ||
| return 'production'; | ||
| } |
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.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: WordPress/wordpress.org
Length of output: 4411
🏁 Script executed:
Repository: WordPress/wordpress.org
Length of output: 6560
🌐 Web query:
PHPUnit 9.6 source PHPUnit\Framework\Attributes\Group PHPUnit 10 attributes introduced💡 Result:
PHPUnit attributes (found in the PHPUnit\Framework\Attributes namespace) were introduced in PHPUnit 10 [1][2][3]. They were implemented to provide a modern, PHP 8-native way to define metadata for test classes and methods, serving as an alternative to the older "annotation" style comments (e.g.,
@group,@covers) [1][4]. PHPUnit 10 and 11 still support both attributes and annotations, though they prioritize attributes when both are present [1][5]. PHPUnit 9.6 does not support these attributes [5]. If you are using PHPUnit 9.6, you must continue using annotation-based metadata in your docblocks [5]. To use attributes, you must upgrade your project to at least PHPUnit 10 [1][5].Citations:
Remove the unsupported PHPUnit attribute.
The repository locks PHPUnit at
9.6.34, which does not supportPHPUnit\Framework\Attributes\Group. The unit-test job uses PHP 8.4, so the PHP 7 parse failure does not apply. Retain@group shortcodesand remove the attribute import and declaration.🤖 Prompt for AI Agents