-
Notifications
You must be signed in to change notification settings - Fork 8
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
Handle missing scheme in animated image rule #545
Merged
pattonwebz
merged 15 commits into
develop
from
william/544/animage_image_check_causes_error_when_image_lacks_scheme
Mar 26, 2024
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5f92eed
Add asset dir for test with animated and static webp and gif
pattonwebz 84be3bd
Add constant to test that points to new asset dir
pattonwebz 61e9fc9
Add some helpers to try add scheme to file urls missing them and vali…
pattonwebz eaa47ca
Add a helper to make opening files as binary live in a single place o…
pattonwebz e8a58b9
Add tests for the new helper functions
pattonwebz b6f7a9e
Swap to new helper to open file as binary and avoid duplicate code
pattonwebz 365cb5b
Update some comments in the img_animated_gif file
pattonwebz e8c5ccd
Add some tests that test the full edac_rule_img_animated_gif rule
pattonwebz 57bf0f3
Merge branch 'develop' into william/544/animage_image_check_causes_er…
pattonwebz b6e1573
Add some extra test assertions to cover a new capability that I will add
pattonwebz 7e8da4b
Use site scheme as default and support non-relative non-protocol-rela…
pattonwebz 138a847
Add a 'rules' group the the ImgAnimatedGifTest.php class
pattonwebz 8c85464
Restore a checking clause before modifying the url and make it more r…
pattonwebz 98ea77d
Restore a checking clause before modifying the url and make it more r…
pattonwebz 8d09f47
Merge remote-tracking branch 'origin/william/544/animage_image_check_…
pattonwebz 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains 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
41 changes: 41 additions & 0 deletions
41
tests/phpunit/helper-functions/GetFileOpenedAsBinaryTest.php
This file contains 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,41 @@ | ||
<?php | ||
/** | ||
* Tests the opening of image files as binary. | ||
* | ||
* @package Accessibility_Checker | ||
*/ | ||
|
||
/** | ||
* Tests the function that opens a file as binary - used when analyzing images. | ||
* | ||
* @group helper-functions | ||
*/ | ||
class GetFileOpenedAsBinaryTest extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test if file gets retrieved and opened as binary. | ||
* | ||
* @group external-http | ||
*/ | ||
public function test_file_opened_as_binary() { | ||
$file = 'https://httpbin.org/image/webp'; | ||
|
||
$fh = edac_get_file_opened_as_binary( $file ); | ||
|
||
$this->assertNotFalse( $fh ); | ||
fclose( $fh ); | ||
} | ||
|
||
/** | ||
* Test if file is not opened as binary. | ||
* | ||
* @group external-http | ||
*/ | ||
public function test_file_not_opened_as_binary() { | ||
$file = 'https://httpbin.org/status/404'; | ||
|
||
$fh = edac_get_file_opened_as_binary( $file ); | ||
|
||
$this->assertFalse( $fh ); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/phpunit/helper-functions/UrlAddSchemeIfNotExistingTest.php
This file contains 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,62 @@ | ||
<?php | ||
/** | ||
* Tests the helper function that adds a scheme to urls that don't have one. | ||
* | ||
* @package accessibility-checker | ||
*/ | ||
|
||
/** | ||
* Test class for validating the helper function that adds a scheme to urls works | ||
* as it was intended when written. | ||
*/ | ||
class UrlAddSchemeIfNotExistingTest extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test that the function adds a scheme to a url that doesn't have one and returns relative urls unchanged. | ||
*/ | ||
public function test_url_add_scheme_if_not_existing() { | ||
$url = '//example.com'; | ||
$expected = 'https://example.com'; | ||
$this->assertEquals( $expected, edac_url_add_scheme_if_not_existing( $url, 'https' ) ); | ||
|
||
$url_http = '//example.com'; | ||
$expected = 'http://example.com'; | ||
$this->assertEquals( $expected, edac_url_add_scheme_if_not_existing( $url_http, 'http' ) ); | ||
|
||
$url_one_slash = '/example.com'; | ||
$this->assertEquals( $url_one_slash, edac_url_add_scheme_if_not_existing( $url_one_slash ) ); | ||
|
||
$url_no_slash = 'example.com'; | ||
$this->assertStringStartsWith( 'http', edac_url_add_scheme_if_not_existing( $url_no_slash ) ); | ||
} | ||
|
||
/** | ||
* Test that the function doesn't add a scheme to a url that already has one. | ||
*/ | ||
public function test_url_add_scheme_if_not_existing_with_scheme() { | ||
$url = 'https://example.com'; | ||
$this->assertEquals( $url, edac_url_add_scheme_if_not_existing( $url ) ); | ||
|
||
$url_http = 'http://example.com/'; | ||
$this->assertEquals( $url_http, edac_url_add_scheme_if_not_existing( $url_http, 'http' ) ); | ||
} | ||
|
||
/** | ||
* Test that the function doesn't add a scheme to a url that already has one, even when not http*. | ||
*/ | ||
public function test_url_add_scheme_if_not_existing_unmoidfied_with_ftp() { | ||
$ftp_url = 'ftp://example.com'; | ||
$this->assertEquals( $ftp_url, edac_url_add_scheme_if_not_existing( $ftp_url ) ); | ||
} | ||
|
||
/** | ||
* Test that the function doesn't add a scheme to a local or relative url. | ||
*/ | ||
public function test_url_add_scheme_if_not_existing_unmoidfied_when_local_or_relative() { | ||
$local_path = '/wp-content/uploads/2024/03/image.gif'; | ||
$this->assertEquals( $local_path, edac_url_add_scheme_if_not_existing( $local_path ) ); | ||
|
||
$relative_url = '/about.gif'; | ||
$this->assertEquals( $relative_url, edac_url_add_scheme_if_not_existing( $relative_url ) ); | ||
} | ||
} |
This file contains 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,34 @@ | ||
<?php | ||
/** | ||
* Tests the helper function that checks if a URL exists. | ||
* | ||
* @package accessibility-checker | ||
*/ | ||
|
||
/** | ||
* Test class for validating the helper function that checks if a URL exists. | ||
*/ | ||
class UrlExistsTest extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test if URL exists. | ||
* | ||
* @group external-http | ||
*/ | ||
public function test_url_exists() { | ||
$url = 'https://httpbin.org/status/200'; | ||
$this->assertTrue( edac_url_exists( $url ) ); | ||
} | ||
|
||
/** | ||
* Test that we get false on a non-2xx status code. | ||
* | ||
* @group external-http | ||
*/ | ||
public function test_url_does_not_exist() { | ||
$url = 'https://httpbin.org/status/404'; | ||
$this->assertFalse( edac_url_exists( $url ) ); | ||
$url = 'https://httpbin.org/status/418'; | ||
$this->assertFalse( edac_url_exists( $url ) ); | ||
} | ||
} |
Oops, something went wrong.
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.
I thought about this over the weekend and I want to just do away with the nested if logic here and instead assume it will always have only what the site protocal is since the page it loads on would dictate it. Thoughts on dropping the internal if here that falls back to
http
?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.
Yes, we can remove this logic check.