-
Notifications
You must be signed in to change notification settings - Fork 128
Implement mechanism to not load module if core version is available #390
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
Conversation
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.
Looks good to me based on our discussions previously, just a few spelling fixes I noticed.
Co-authored-by: Crisoforo Gaspar Hernández <hello@crisoforo.com>
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.
@mukeshpanchal27 This is mostly looking good so far, however the API approach you're taking here is different from the issue, so I'm curious why you decided to divert from that - IMO it's more complicated than needed.
That's my main feedback, other than that I mostly have minor comments.
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.
@mukeshpanchal27 Thanks for the updates, the perflab_can_load_module()
behavior looks good now.
I left some replies on the relevant comment threads above around how to handle the additional logic about whether a module can be loaded. TLDR I think we should add a new perflab_get_active_and_valid_modules()
function which calls perflab_get_active_modules()
and then further filters out any modules that cannot be loaded. All the additional checks can happen in that function, and most code that currently calls perflab_get_active_modules()
should then call perflab_get_active_and_valid_modules()
instead.
@felixarntz Thanks for the review. I have implemented the review changes. Can you please review it again and let me know if it needs any changes? |
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.
Thanks @mukeshpanchal27 added a comment related to a couple of the tests. It would be good to get @felixarntz input on this.
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.
Thanks @mukeshpanchal27 test look good now 👍
admin/load.php
Outdated
?> | ||
<?php if ( ! $can_load_module ) { ?> | ||
<input type="checkbox" id="<?php echo esc_attr( "{$base_id}_enabled" ); ?>" aria-describedby="<?php echo esc_attr( "{$base_id}_description" ); ?>" disabled> | ||
<input type="hidden" name="<?php echo esc_attr( "{$base_name}[enabled]" ); ?>" value="<?php echo $enabled ? '1' : ''; ?>"> |
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.
Would be worth fallback to 0
instead of an empty string as the value?
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.
agreed. For now, I have updated PR accordingly.
@felixarntz Do we need to set an empty value here?
tests/testdata/demo-modules/javascript/demo-module-1/can-load.php
Outdated
Show resolved
Hide resolved
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.
Great work 👍
The PR needs a final review from @felixarntz. |
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.
Nice work! LGTM pending final review from Felix.
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.
@mukeshpanchal27 Looks good now, mostly a few last nitpicks and minor things to improve around the tests.
load.php
Outdated
* @param array $modules List of active module slugs. | ||
* @return array List of active valid module slugs. | ||
*/ | ||
function perflab_get_valid_modules( array $modules = array() ) { |
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.
Two things about this function:
- I would say the
get
in the name is a bit confusing, since it filters an existing input variable rather than getting a distinct value from somewhere. So I think a better name would beperflab_filter_valid_modules()
. Or, we change this implementation to just be for a single module, e.g.perflab_is_valid_module( $module )
, and then you could call it viaarray_filter( perflab_get_active_modules(), 'perflab_is_valid_module' )
. - Why is there a default? I would say this should rather be a required parameter, especially since calling it without any value is pointless since it would always just return the empty array then.
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.
Thanks for the feedback.
I like the perflab_is_valid_module( $module )
approach instead of the function name change. Now we should have passed a valid module slug. I have updated unit tests according to these changes.
Thanks for the feedback @felixarntz, I have addressed the feedback and updated the PR and unit tests accordingly. |
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.
@mukeshpanchal27 This is looking good now, thank you for the updates!
I left a few last suggestions to further improve the tests, but this is pretty much good to go.
tests/load-tests.php
Outdated
public function test_empty_module_for_perflab_is_valid_module() { | ||
// Assert that it return null for empty module. | ||
$this->assertEmpty( perflab_is_valid_module( '' ) ); | ||
} | ||
|
||
/** | ||
* @dataProvider provider_dummy_valid_modules | ||
*/ | ||
public function test_perflab_is_valid_module( $dummy_module ) { | ||
$output = perflab_is_valid_module( $dummy_module ); | ||
$this->assertNotEmpty( $output ); | ||
$this->assertIsString( $output ); | ||
} |
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.
See above, these assertions should be using assertFalse
or assertTrue
based on the alternate return type.
Also, it would be more efficient to combine these two tests into one. Both could use the same @dataProvider
, you could include the empty string in there, and then every data set could also include the expected true
or false
. You could use assertSame
for that, similarly to how you have it below for the perflab_can_load_module
tests.
Also it would be great if you could use the same method name for the data provider method, except replacing test_
with data_
(see other comment below).
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.
Thanks for the feedback. I removed the empty module test and merged it into test_perflab_is_valid_module
so it tests all scenarios. For this test, I use @dataProvider data_perflab_is_valid_module
because we can't test an empty module in test_perflab_can_load_module
test.
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.
@mukeshpanchal27 Two super-minor nit-picks, but this is looking very solid now. Great work!
I'll just add those quickly, it's basically good to merge.
Summary
This PR works when function
wp_image_use_alternate_mime_types()
(see WordPress core PR WordPress/wordpress-develop#2393) implemented in WordPress core.How to test PR in WordPress 6.0
If you want to test PR then please pull from the git change this line code.
if ( function_exists( 'wp_image_use_alternate_mime_types' ) ) {
Replace it with
wp_recursive_ksort()
which introduce in WordPress 6.0.if ( function_exists( 'wp_recursive_ksort' ) ) {
If you want to test
can-load.php
for the other module then please copy the file from thewebp-uploads
module and paste it into the other modules.For testing purposes, I have created a
can-load.php
file fordominant-color
andpersistent-object-cache-health-check
modules.can-load.php
file fordominant-color
can-load.php
file forpersistent-object-cache-health-check
Fixes #293
Checklist
[Focus]
orInfrastructure
label.[Type]
label.no milestone
label.