Refactor theme fonts class for readability#661
Conversation
matiasbenedetto
left a comment
There was a problem hiding this comment.
Probably we should use this refactor to improve the tests of this class. They currently relay on setting users, creating new themes dynamically and after removing it without restoring the previous state.
Example:
create-block-theme/tests/test-theme-fonts.php
Lines 26 to 60 in eabd382
I think this kind of test is the cause of the destructive tests we found some time ago and we tried to workaround it here: #618
Could we follow the approach we are using in the base case for the Readme class ?. It can improve 3 aspects of these tests:
- Fine tune control and always predictable active theme for test.
- No destructive test env.
- Avoid realying on CBT complex functions.
| } | ||
|
|
||
| public function test_array_font_src() { | ||
| wp_set_current_user( self::$admin_id ); |
There was a problem hiding this comment.
This is probably not needed.
There was a problem hiding this comment.
Without it, the tests break:
Time: 00:00.357, Memory: 42.50 MB
There was 1 error:
1) Test_Create_Block_Theme_Fonts::test_copy_activated_fonts_to_theme
Undefined array key "typography"
/var/www/html/wp-content/plugins/create-block-theme/tests/test-theme-fonts.php:43
ERRORS!
Tests: 67, Assertions: 163, Errors: 1.
Script phpunit handling the test event returned with error code 2
✖ Command failed with exit code 2
Command failed with exit code 2There was a problem hiding this comment.
Probably we should use this refactor to improve the tests of this class. They currently relay on setting users, creating new themes dynamically and after removing it without restoring the previous state.
I agree that we should work on that, but since the tests currently cover the already-refactored code, I'd prefer refactoring them in another PR.
ded5ff5 to
2b409f8
Compare
Co-authored-by: Jason Crist <[email protected]>
pbking
left a comment
There was a problem hiding this comment.
Seems fine to me. Quality improvements.
What?
This Pull Request refactors the them fonts class to improve code readability and maintainability. The main focus is on cleaning up the code.
I felt inclined to do this because when debugging for #660, I found some parts of the code hard to follow.
Why?
This PR addresses the need to make the code more readable and maintainable by:
How?
Key Changes:
Class documentation added: Added descriptions and the purpose of the
CBT_Theme_Fontsclass.Function improvements:
make_theme_font_src_absolute()to usearray_mapfor cleaner array handling.foreachtoarray_map: This reduces the complexity and makes the handling of arrays cleaner.Code clean-up:
?? null) for checking array keys.Function calls:
CBT_Theme_Fonts::withself::for static method calls within the class, enhancing readability and context awareness.Added test cases for parts of the code that could break on further refactors.