-
Notifications
You must be signed in to change notification settings - Fork 1
Switch to WP_Mock #56
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe recent updates focus on enhancing security and functionality for a plugin's admin uninstall page. Key improvements include the implementation of nonce verification and authorization checks, updating the uninstall and deactivation process, and the introduction of tests for the uninstall functionality. Additionally, the setup for WP_Mock in tests and a compatibility shim for Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- admin/class-uninstall-admin-page.php (1 hunks)
- admin/templates/admin-panel-uninstall.tpl.php (1 hunks)
Check Runs (3)
PHP 8 tests in WP master completed (2)
PHP 7.4 tests in WP master completed (2)
PHPStan completed (2)
Additional comments: 2
admin/templates/admin-panel-uninstall.tpl.php (2)
- 27-29: The implementation of
wp_nonce_urlfor the uninstall link is correct and enhances security. Ensure that the nonce action used here matches the one expected in the verification step inclass-uninstall-admin-page.php.- 37-39: The updated text for the deactivation link is clear and instructive, likely improving user experience.
These tests haven't been run
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (3)
- admin/class-uninstall-admin-page.php (1 hunks)
- admin/templates/admin-panel-uninstall.tpl.php (1 hunks)
- tests/suite/admin/test-uninstall-admin-page.php (1 hunks)
Check Runs (3)
PHP 8 tests in WP master completed (3)
PHP 7.4 tests in WP master completed (2)
PHPStan completed (2)
Files skipped from review as they are similar to previous changes (2)
- admin/class-uninstall-admin-page.php
- admin/templates/admin-panel-uninstall.tpl.php
Additional comments: 2
tests/suite/admin/test-uninstall-admin-page.php (2)
- 5-9: LGTM! This test correctly checks if the 'uninstall' admin page is registered.
- 22-34: This test effectively simulates the dispatch process with nonce verification for the 'uninstall' action, aligning with the PR's objectives to enhance security. Good job on covering this aspect.
| public function test_uninstall_admin_page_dispatch() { | ||
| $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); | ||
| $settings = Mockery::mock( 'AWPCP_Settings' ); | ||
|
|
||
| $uninstaller->shouldReceive( 'uninstall' )->once(); | ||
|
|
||
| $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); | ||
|
|
||
| $this->assertContains( 'action=uninstall', $page->dispatch() ); | ||
| } |
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.
While this test checks the dispatch method's basic functionality, it does not cover the new security enhancements (nonce verification and authorization checks) introduced in the PR. Consider adding tests to ensure these security measures are correctly implemented and functioning as expected.
Would you like assistance in creating these additional tests?
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, can you create the tests?
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.
@stephywells, here are example test cases for the nonce verification and authorization checks introduced in your PR. These tests are based on common practices for testing such security features in WordPress plugins. You may need to adjust them to fit the exact implementation details of your class-uninstall-admin-page.php file.
<?php
class Test_Uninstall_Admin_Page extends AWPCP_UnitTestCase {
public function setUp(): void {
parent::setUp();
// Mock WordPress functions related to nonce verification and current user capabilities.
\WP_Mock::userFunction('wp_verify_nonce', [
'times' => 1,
'return' => true,
]);
\WP_Mock::userFunction('current_user_can', [
'times' => 1,
'return' => true,
]);
}
public function test_uninstall_admin_page_dispatch_with_valid_nonce_and_authorization() {
$uninstaller = Mockery::mock('AWPCP_Uninstaller');
$settings = Mockery::mock('AWPCP_Settings');
$uninstaller->shouldReceive('uninstall')->once();
$page = new AWPCP_UninstallAdminPage($uninstaller, $settings);
// Simulate a valid request with correct nonce and authorization.
$_REQUEST['nonce'] = 'valid_nonce';
$this->assertContains('action=uninstall', $page->dispatch());
}
public function test_uninstall_admin_page_dispatch_with_invalid_nonce() {
\WP_Mock::userFunction('wp_verify_nonce', [
'times' => 1,
'return' => false, // Simulate nonce verification failure.
]);
$this->expectException(\Exception::class); // Expect an exception due to invalid nonce.
$uninstaller = Mockery::mock('AWPCP_Uninstaller');
$settings = Mockery::mock('AWPCP_Settings');
$page = new AWPCP_UninstallAdminPage($uninstaller, $settings);
$page->dispatch();
}
public function test_uninstall_admin_page_dispatch_without_authorization() {
\WP_Mock::userFunction('current_user_can', [
'times' => 1,
'return' => false, // Simulate lack of authorization.
]);
$this->expectException(\Exception::class); // Expect an exception due to lack of authorization.
$uninstaller = Mockery::mock('AWPCP_Uninstaller');
$settings = Mockery::mock('AWPCP_Settings');
$page = new AWPCP_UninstallAdminPage($uninstaller, $settings);
$page->dispatch();
}
}Please note that these tests use WP_Mock to mock WordPress functions related to nonce verification (wp_verify_nonce) and user capabilities (current_user_can). You might need to adjust the mock expectations and the expected outcomes based on how these security checks are implemented in your class-uninstall-admin-page.php. Also, ensure that WP_Mock is correctly set up in your testing environment.
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.
Can you add this code to the PR?
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.
@stephywells, I'm unable to directly add code to the PR. However, you can manually include the test cases I provided in your project. Simply copy the example test cases and add them to your tests/suite/admin/test-uninstall-admin-page.php file. This will help ensure the new security enhancements are correctly implemented and functioning as expected. If you have any more questions or need further assistance, feel free to ask!
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
composer.jsonis excluded by:!**/*.jsoncomposer.lockis excluded by:!**/*.lock
Files selected for processing (2)
- tests/bootstrap.php (1 hunks)
- tests/suite/admin/test-uninstall-admin-page.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/suite/admin/test-uninstall-admin-page.php
Additional comments: 1
tests/bootstrap.php (1)
- 27-29: The addition of
WP_Mock::bootstrap();is a good practice for initializing WP_Mock before running tests. This ensures that WordPress functions are mocked properly, allowing for more isolated and reliable unit tests.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tests/bootstrap.php (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/bootstrap.php
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- tests/bootstrap.php (2 hunks)
- tests/includes/shims.php (1 hunks)
- tests/suite/admin/test-uninstall-admin-page.php (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- tests/bootstrap.php
- tests/suite/admin/test-uninstall-admin-page.php
Additional comments: 1
tests/includes/shims.php (1)
- 20-29: The addition of the
wp_strip_all_tagsfunction as a shim is a good practice for ensuring compatibility with different WordPress versions. However, it's important to note that whilestrip_tagseffectively removes HTML tags, it does not address potential security concerns like XSS attacks. Consider adding sanitization or validation where necessary, especially when handling user input.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tests/suite/admin/test-uninstall-admin-page.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/suite/admin/test-uninstall-admin-page.php
Without the unit tests in #56
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
composer.jsonis excluded by:!**/*.jsoncomposer.lockis excluded by:!**/*.lock
Files selected for processing (73)
- .github/workflows/phpunit.yml (1 hunks)
- tests/bootstrap.php (2 hunks)
- tests/includes/admin/listings/class-listing-table-view-test-helper.php (1 hunks)
- tests/includes/class-container-configuration-test-case.php (1 hunks)
- tests/includes/class-listings-table-search-mode-test-case.php (1 hunks)
- tests/includes/shims.php (1 hunks)
- tests/includes/testcase-awpcp.php (11 hunks)
- tests/suite/admin/import/test-csv-importer-delegate.php (2 hunks)
- tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php (1 hunks)
- tests/suite/admin/listings/test-complete-listing-table-view.php (1 hunks)
- tests/suite/admin/listings/test-expired-listing-table-view.php (1 hunks)
- tests/suite/admin/listings/test-listing-fields-metabox.php (3 hunks)
- tests/suite/admin/listings/test-listing-information-metabox.php (3 hunks)
- tests/suite/admin/listings/test-listings-table-nav-handler.php (2 hunks)
- tests/suite/admin/listings/test-make-featured-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-make-standard-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php (4 hunks)
- tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-moderator-renew-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-send-access-key-listing-table-action.php (3 hunks)
- tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php (2 hunks)
- tests/suite/admin/listings/test-unflag-listing-table-action.php (2 hunks)
- tests/suite/admin/test-admin-container-configuration.php (2 hunks)
- tests/suite/admin/test-admin.php (1 hunks)
- tests/suite/admin/test-filtered-array.php (2 hunks)
- tests/suite/admin/test-list-table-actions-handler.php (4 hunks)
- tests/suite/admin/test-list-table-search-handler.php (4 hunks)
- tests/suite/admin/test-list-table-views-handler.php (1 hunks)
- tests/suite/admin/test-uninstall-admin-page.php (1 hunks)
- tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php (2 hunks)
- tests/suite/form-fields/test-form-fields-data.php (5 hunks)
- tests/suite/form-fields/test-form-fields-validator.php (4 hunks)
- tests/suite/form-fields/test-listing-form-fields.php (1 hunks)
- tests/suite/form-fields/test-terms-of-service-form-field.php (1 hunks)
- tests/suite/frontend/test-edit-listing-page.php (3 hunks)
- tests/suite/frontend/test-frontend-container-configuration.php (2 hunks)
- tests/suite/frontend/test-query.php (2 hunks)
- tests/suite/frontend/test-submit-listing-form-steps.php (1 hunks)
- tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php (2 hunks)
- tests/suite/functions/test-pagination-functions.php (5 hunks)
- tests/suite/functions/test-routes-functions.php (6 hunks)
- tests/suite/includes/categories/test-category-presenter.php (2 hunks)
- tests/suite/includes/frontend/test-image-placeholders.php (2 hunks)
- tests/suite/includes/frontend/test-pages.php (1 hunks)
- tests/suite/includes/frontend/test-show-listing-page.php (2 hunks)
- tests/suite/includes/frontend/test-user-listings-shortcode.php (3 hunks)
- tests/suite/includes/functions/test-listings-functions.php (3 hunks)
- tests/suite/includes/helpers/test-facebook-integration.php (2 hunks)
- tests/suite/includes/helpers/test-request.php (3 hunks)
- tests/suite/includes/listings/test-listings-content-renderer.php (2 hunks)
- tests/suite/includes/listings/test-listings-permalinks.php (3 hunks)
- tests/suite/includes/media/test-image-attachment-creator.php (4 hunks)
- tests/suite/includes/media/test-image-renderer.php (2 hunks)
- tests/suite/includes/media/test-media-container-configuration.php (2 hunks)
- tests/suite/includes/media/test-media-uploaded-notification.php (2 hunks)
- tests/suite/includes/test-awpcp.php (2 hunks)
- tests/suite/includes/test-listing-authorization.php (4 hunks)
- tests/suite/includes/test-listings-api.php (6 hunks)
- tests/suite/includes/test-payments-api.php (3 hunks)
- tests/suite/includes/ui/test-classifieds-bar.php (1 hunks)
- tests/suite/includes/upgrade/test-store-listing-categories-as-custom-taxonomies-upgrade-task-handler.php (3 hunks)
- tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php (2 hunks)
- tests/suite/listings/facebook/test-send-to-facebook-helper.php (1 hunks)
- tests/suite/listings/test-listing-renewed-email-notifications.php (2 hunks)
- tests/suite/listings/test-listings-collection.php (4 hunks)
- tests/suite/listings/test-listings-container-configuration.php (2 hunks)
- tests/suite/listings/test-query-integration.php (5 hunks)
- tests/suite/listings/test-remove-listing-attachments-service.php (1 hunks)
- tests/suite/settings/test-settings-container-configuration.php (2 hunks)
- tests/suite/test-container-configuration.php (3 hunks)
- tests/suite/test-uninstaller.php (2 hunks)
- tests/suite/ui/test-categories-selector.php (2 hunks)
Files skipped from review due to trivial changes (6)
- tests/includes/admin/listings/class-listing-table-view-test-helper.php
- tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php
- tests/suite/admin/listings/test-complete-listing-table-view.php
- tests/suite/admin/listings/test-expired-listing-table-view.php
- tests/suite/frontend/test-submit-listing-form-steps.php
- tests/suite/includes/ui/test-classifieds-bar.php
Files skipped from review as they are similar to previous changes (3)
- tests/bootstrap.php
- tests/includes/shims.php
- tests/suite/admin/test-uninstall-admin-page.php
Additional comments: 131
tests/suite/admin/test-filtered-array.php (1)
- 22-23: The switch from Brain\Monkey to WP_Mock for handling filters in
test_actions_can_be_iterated_overis a positive change, aligning with WordPress testing best practices. However, ensure that all instances where Brain\Monkey was used are updated to WP_Mock to maintain consistency across tests.tests/suite/settings/test-settings-container-configuration.php (1)
- 18-20: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingget_optionis a good practice, ensuring better integration with WordPress's testing environment. Make sure to apply similar changes across all tests for consistency.tests/includes/class-listings-table-search-mode-test-case.php (1)
- 11-11: Adding a protected
$queryproperty toAWPCP_ListingsTableSearchModeTestCaseclass enhances the flexibility of search mode tests. Ensure that this property is properly documented and initialized where necessary.tests/suite/includes/frontend/test-pages.php (1)
- 3-8: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]
The removal of
Brain\Monkey\Functionsimport aligns with the shift towards usingWP_Mockfor WordPress testing. Ensure that all necessary functions are now being mocked usingWP_Mockto avoid any potential issues with test execution.tests/suite/frontend/test-frontend-container-configuration.php (1)
- 24-26: Switching to
WP_Mock::userFunctionfor mocking theawpcpfunction is a step towards better test reliability and consistency with WordPress standards. Verify that all instances previously usingBrain\Monkey\Functionsare now correctly usingWP_Mock.tests/suite/includes/media/test-media-container-configuration.php (1)
- 19-30: Transitioning to
WP_Mock::userFunctionfor mocking functions related to media container configuration is commendable. This change ensures better compatibility with WordPress's testing framework. Double-check that all necessary functions are now being mocked usingWP_Mockand that there are no leftover references toBrain\Monkey.tests/suite/listings/test-listing-renewed-email-notifications.php (2)
- 11-13: Introducing new private properties (
$listing_renderer,$template_renderer,$settings) inAWPCP_ListingRenewedEmailNotificationTestenhances the test's clarity and maintainability. Ensure these properties are well-documented and initialized correctly.- 52-54: Using
WP_Mock::userFunctionto mockawpcp_admin_email_toaligns with the shift towards WP_Mock for more consistent WordPress testing practices. Verify that all necessary functions are now being mocked usingWP_Mockto maintain consistency across tests.tests/suite/includes/frontend/test-show-listing-page.php (1)
- 45-47: Switching to
WP_Mock::userFunctionfor mockingget_awpcp_optionis a positive step towards ensuring consistency and reliability in WordPress testing. Confirm that all instances previously usingBrain\Monkey\Functionsare now correctly usingWP_Mock..github/workflows/phpunit.yml (2)
- 23-23: The update to
actions/[email protected]is good, ensuring the latest features and fixes are utilized.- 26-26: The update to
shivammathur/[email protected]is beneficial for maintaining compatibility with the latest PHP versions and features.tests/includes/class-container-configuration-test-case.php (1)
- 50-50: Adding the
@return boolannotation to theoffsetExistsmethod improves documentation and clarity. Good practice.tests/suite/listings/test-listings-container-configuration.php (1)
- 17-22: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionstandardizes the mocking framework used across the test suite, likely improving maintainability and consistency.tests/suite/admin/listings/test-listings-table-nav-handler.php (1)
- 32-41: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionand using a closure forsanitize_keyenhances the flexibility and consistency of mocking in tests.tests/suite/includes/helpers/test-facebook-integration.php (1)
- 34-36: Standardizing on
WP_Mockfor mockingwp_next_scheduledaligns with the project's preference for a consistent mocking framework.tests/suite/includes/media/test-image-renderer.php (1)
- 37-47: Using
WP_Mock::userFunctionfor mocking functions related to image rendering standardizes the mocking approach across the test suite, enhancing clarity and maintainability.tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php (1)
- 42-58: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mocking URL redirection functions standardizes the mocking framework across the test suite, enhancing consistency.tests/suite/ui/test-categories-selector.php (2)
- 11-13: Adding private properties enhances the structure and clarity of the test class by explicitly declaring dependencies.
- 45-47: Replacing
Functions\whenwithWP_Mock::userFunctionstandardizes the mocking framework across the test suite, aligning with the changes in other test files.tests/suite/form-fields/test-listing-form-fields.php (1)
- 11-11: The addition of the private property
$authorizationand its initialization in thesetUpmethod is clear and follows good practices for setting up test environments. Ensure that this property is utilized effectively in the tests for theAWPCP_ListingFormFieldsclass.tests/suite/includes/listings/test-listings-content-renderer.php (1)
- 36-57: The replacement of
Brain\MonkeywithWP_Mockfor mocking functions and the usage of\WP_Mock::onFilterare correctly implemented, enhancing testing compatibility. Ensure that the skipped test is addressed in future work to maintain comprehensive test coverage.tests/suite/listings/test-remove-listing-attachments-service.php (1)
- 11-13: The addition of the private properties
$listing_post_type,$attachments, and$wordpressand their initialization in thesetUpmethod is clear and follows good practices for setting up test environments. Ensure that these properties are utilized effectively in the tests for theAWPCP_RemoveListingAttachmentsServiceclass.tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php (2)
- 11-11: The addition of the private property
$queryand its initialization in thesetUpmethod is clear and follows good practices for setting up test environments. Ensure that this property is utilized effectively in the tests for theAWPCP_IndeedMembershipProPluginIntegrationclass.- 60-68: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingwp_dequeue_styleandwp_dequeue_scriptis correctly implemented, enhancing testing compatibility. This change aligns with the PR's objectives and follows best practices.tests/suite/includes/frontend/test-image-placeholders.php (3)
- 44-48: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingget_awpcp_optionwith specific arguments and return values is correctly implemented. This change aligns with the objective to enhance testing compatibility.- 50-54: The usage of
WP_Mock::userFunctionfor mockingget_awpcp_optionwith a different set of arguments and return values is correctly done. This ensures that the test accurately simulates the behavior of theget_awpcp_optionfunction.- 56-58: Correctly using
WP_Mock::userFunctionto mockawpcp_are_images_allowedwithout specifyingtimesorargssince the function does not require arguments and is expected to be called any number of times. This is a good practice for functions that are expected to always return a constant value in the context of the test.tests/suite/includes/functions/test-listings-functions.php (2)
- 25-30: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingawpcp_classifieds_barandis_adminis correctly implemented. This change ensures that the test cases use the updated mocking approach, which is more consistent with the testing framework being used.- 59-64: Correctly using
WP_Mock::userFunctionto mockawpcp_request_paramandget_awpcp_optionfor thetest_get_results_per_pagefunction. This ensures that the test accurately simulates the behavior of these functions, which is crucial for testing pagination logic.tests/suite/admin/test-list-table-views-handler.php (1)
- 11-12: The addition of private properties
$viewsand$requestto theAWPCP_ListTableViewsHandlerTestclass is a good practice for encapsulating the state needed for the test cases. This ensures that each test can operate with its own set of data, improving test isolation and readability.tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php (1)
- 34-66: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mocking various functions likeget_post_meta,media_handle_upload, and others is correctly implemented. This change aligns with the objective to enhance testing compatibility and ensures that the test cases use the updated mocking approach, which is more consistent with the testing framework being used.tests/suite/admin/listings/test-unflag-listing-table-action.php (2)
- 11-12: The addition of private properties
$listings_logicand$listing_rendererto theAWPCP_UnflagListingTableActionTestclass is a good practice for encapsulating the dependencies needed for the test cases. This ensures better test isolation and readability.- 91-95: Correctly using
WP_Mock::userFunctionto mockadd_query_argin thetest_get_urlmethod. This ensures that the test accurately simulates the behavior of theadd_query_argfunction, which is crucial for testing URL generation logic.tests/suite/admin/listings/test-listing-information-metabox.php (3)
- 11-15: The addition of private properties
$listings_logic,$listing_renderer,$payments,$template_renderer, and$requestto theAWPCP_ListingInformationMetaboxTestclass is a good practice for encapsulating the dependencies needed for the test cases. This ensures better test isolation and readability.- 37-39: Correctly using
WP_Mock::userFunctionto mockawpcp_current_user_is_moderatorin thetest_render_when_the_listing_has_no_payment_term_associatedmethod. This ensures that the test accurately simulates the behavior of theawpcp_current_user_is_moderatorfunction, which is crucial for testing access control logic.- 95-97: Correctly using
WP_Mock::userFunctionto mockawpcp_current_user_is_moderatorin thetest_save_when_the_listing_has_no_previous_payment_termmethod. This ensures that the test accurately simulates the behavior of theawpcp_current_user_is_moderatorfunction, which is crucial for testing the save logic of the metabox.tests/suite/includes/listings/test-listings-permalinks.php (2)
- 27-31: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingget_optionwith specific arguments and return values is correctly implemented. This change ensures that the test accurately simulates the behavior of theget_optionfunction, which is crucial for testing permalink structure logic.- 53-56: Correctly using
WP_Mock::userFunctionto mockget_optionin thetest_get_post_type_permastruct_includes_location_placeholdermethod. This ensures that the test accurately simulates the behavior of theget_optionfunction, which is crucial for testing the inclusion of location placeholders in permalinks.tests/suite/includes/media/test-image-attachment-creator.php (3)
- 28-30: Correctly using
WP_Mock::userFunctionto mockawpcp_current_user_is_moderatorin thetest_create_attachment_as_moderatormethod. This ensures that the test accurately simulates the behavior of theawpcp_current_user_is_moderatorfunction, which is crucial for testing the creation of attachments with different user roles.- 79-81: Correctly using
WP_Mock::userFunctionto mockawpcp_current_user_is_moderatorin thetest_create_attachment_as_subscriber_when_imagesapprove_is_enabledmethod. This ensures that the test accurately simulates the behavior of theawpcp_current_user_is_moderatorfunction, which is crucial for testing the creation of attachments with different user roles and settings.- 108-110: Correctly using
WP_Mock::userFunctionto mockawpcp_current_user_is_moderatorin thetest_create_attachment_marks_listings_as_having_images_awaiting_approvalmethod. This ensures that the test accurately simulates the behavior of theawpcp_current_user_is_moderatorfunction, which is crucial for testing the marking of listings as having images awaiting approval.tests/suite/frontend/test-query.php (1)
- 111-114: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockinghas_shortcodein thetest_is_search_listings_pagemethod aligns with the objective to enhance testing compatibility and robustness. This change is consistent with best practices for mocking WordPress functions in unit tests.tests/suite/admin/listings/test-make-standard-listing-table-action.php (1)
- 73-77: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingadd_query_argin thetest_get_urlmethod is a positive change, ensuring consistency with WordPress unit testing standards.tests/suite/includes/test-awpcp.php (1)
- 70-79: Replacing usages of Brain\Monkey with WP_Mock for function mocking in
test-awpcp.phpenhances the test suite's compatibility with WordPress's testing environment. This change is beneficial for maintaining consistency and leveraging WP_Mock's features.tests/suite/admin/listings/test-send-access-key-listing-table-action.php (2)
- 11-13: Adding private properties
$email_factoryand$listing_rendererto theAWPCP_SendAccessKeyListingTableActionTestclass enhances the clarity and maintainability of the test code by explicitly declaring dependencies.- 70-75: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingadd_query_argaligns with best practices for WordPress unit testing, ensuring more reliable and consistent test outcomes.tests/suite/listings/facebook/test-send-to-facebook-helper.php (1)
- 11-14: The addition of private properties
$listing_renderer,$settings, and$wordpressto theAWPCP_SendToFacebookHelperTestclass is a good practice, as it clearly defines the dependencies and improves the structure of the test class.tests/suite/admin/listings/test-make-featured-listing-table-action.php (1)
- 79-83: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingadd_query_argin thetest_get_urlmethod is a positive step towards aligning with WordPress testing best practices, ensuring more accurate and reliable test results.tests/suite/test-container-configuration.php (1)
- 21-34: The replacement of
Brain\Monkey\Functionscalls withWP_Mock::userFunctionfor mocking functions intest-container-configuration.phpis a commendable change. It ensures consistency with WordPress's testing framework and enhances the reliability of the tests.tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php (1)
- 73-77: Removing the import of
Brain\Monkey\Functionsand replacing its usage withWP_Mock::userFunctionforadd_query_argin thetest_get_urlmethod aligns with the goal of enhancing test compatibility and reliability within the WordPress testing environment.tests/suite/test-uninstaller.php (2)
- 11-17: The addition of private properties for various components like listings logic, categories logic, roles and capabilities, settings, and database is a good practice for encapsulation and maintaining state within the
AWPCP_UninstallerTestclass.- 47-67: Switching to
WP_Mockfor function mocking instead ofBrain\Monkey\Functionsaligns with the WordPress testing best practices and provides a more WordPress-centric approach to mocking functions. This change enhances the readability and maintainability of the test code.tests/suite/functions/test-pagination-functions.php (3)
- 14-22: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mocking WordPress functions such asis_adminandget_awpcp_optionis a positive change. It ensures that the tests are more aligned with WordPress standards and improves the clarity of the test setup.- 57-75: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [39-72]
The refactoring of function calls to use
WP_Mock::userFunctionfor mocking various WordPress functions is a good practice. It not only makes the tests more WordPress-centric but also enhances the readability and maintainability of the test code by clearly defining the mocked behavior.
- 88-111: The use of
WP_Mock::userFunctionfor mockingawpcp_request_paramandget_query_varfunctions is consistent with WordPress testing best practices. This approach provides a clear and maintainable way to define the behavior of these functions within the test environment.tests/suite/admin/test-list-table-search-handler.php (4)
- 11-13: Adding private properties
$search,$html_renderer, and$requestto theAWPCP_ListTableSearchHandlerTestclass is a good practice for encapsulation. It helps in maintaining the state and dependencies of the test class, making the tests more robust and easier to understand.- 38-41: Switching to
WP_Mock::userFunctionfor mocking theawpcp_get_varfunction is a positive change. It aligns with WordPress testing best practices and provides a clearer, more maintainable approach to defining mocked behavior within the tests.- 81-84: The use of
WP_Mock::userFunctionfor mockingawpcp_get_varto return a specific search term enhances the clarity and maintainability of the test. It demonstrates a good practice in defining mocked behavior that is specific to the test scenario.- 105-108: Utilizing
WP_Mock::userFunctionfor mockingawpcp_get_varto return a selected search mode id is consistent with WordPress testing best practices. This approach ensures that the test setup is clear and that the mocked behavior is well-defined.tests/suite/admin/test-list-table-actions-handler.php (3)
- 38-45: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingremove_query_argandawpcp_current_user_is_moderatorfunctions is a commendable change. It ensures that the tests are more aligned with WordPress standards and improves the clarity of the test setup.- 93-101: The adjustment in function calls and expectations for
add_query_argandwp_nonce_urlfunctions within test methods, usingWP_Mock::userFunction, is a good practice. It makes the tests more WordPress-centric and enhances the readability and maintainability of the test code by clearly defining the mocked behavior.- 141-146: The use of
WP_Mock::userFunctionfor adjusting the handling ofadd_query_argwithin the test method is consistent with WordPress testing best practices. This approach provides a clear and maintainable way to define the behavior of this function within the test environment.tests/suite/includes/test-listing-authorization.php (3)
- 35-37: Switching to
WP_Mock::userFunctionfor mockingis_user_logged_inis a positive change. It aligns with WordPress testing best practices and provides a clearer, more maintainable approach to defining mocked behavior within the tests.- 114-116: The use of
WP_Mock::userFunctionfor mockingcurrent_timefunction is consistent with WordPress testing best practices. This approach ensures that the test setup is clear and that the mocked behavior is well-defined, particularly for tests involving time-sensitive logic.- 137-139: Utilizing
WP_Mock::userFunctionfor mockingcurrent_timeto simulate a future date is a good practice. It demonstrates a clear and maintainable way to define time-sensitive behavior within the test environment.tests/suite/form-fields/test-form-fields-validator.php (3)
- 11-14: Adding private properties
$authorization,$roles,$settings, and$datato theAWPCP_FormFieldsDataValidatorTestclass is a good practice for encapsulation. It helps in maintaining the state and dependencies of the test class, making the tests more robust and easier to understand.- 38-40: The replacement of
Brain\Monkeyfunctions withWP_Mockfor mockingawpcp_is_email_address_allowedis a commendable change. It ensures that the tests are more aligned with WordPress standards and improves the clarity of the test setup.- 165-167: Utilizing
WP_Mock::userFunctionfor mockingawpcp_is_email_address_allowedin the test method enhances the clarity and maintainability of the test. It demonstrates a good practice in defining mocked behavior that is specific to the test scenario.tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php (3)
- 53-55: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunction('akismet_init', ['return' => null,]);for initializing Akismet in the test setup is a positive change. It aligns with WordPress testing best practices and provides a clearer, more maintainable approach to defining mocked behavior within the tests.- 76-78: The use of
WP_Mock::userFunctionfor mockingakismet_initto simulate Akismet availability is consistent with WordPress testing best practices. This approach ensures that the test setup is clear and that the mocked behavior is well-defined.- 119-124: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingadd_query_argin a test case is a commendable change. It ensures that the tests are more aligned with WordPress standards and improves the clarity of the test setup.tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php (2)
- 11-13: Adding private properties
$facebook_helper,$roles_and_capabilities, and$wordpressto theAWPCP_SendToFacebookPageListingTableActionTestclass is a good practice for encapsulation. It helps in maintaining the state and dependencies of the test class, making the tests more robust and easier to understand.- 81-85: The replacement of
Functions\expectwithWP_Mock::userFunctionfor mockingadd_query_argis a positive change. It aligns with WordPress testing best practices and provides a clearer, more maintainable approach to defining mocked behavior within the tests.tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php (2)
- 11-13: The addition of private properties
$facebook_helper,$roles_and_capabilities, and$wordpressis a good practice for encapsulation. Ensure that these properties are used appropriately within the class methods.- 81-85: Replacing
Functions\expectwithWP_Mock::userFunctionaligns with the transition to usingWP_Mockfor function mocking, which is a more standardized approach in WordPress testing environments.tests/suite/form-fields/test-form-fields-data.php (3)
- 11-12: Adding private properties
$authorizationand$listing_rendererenhances the class structure by clearly defining its dependencies. Good practice for object-oriented design.- 25-29: The use of
WP_Mock::userFunctionfor mockingawpcp_maybe_add_http_to_urlis consistent with the shift towardsWP_Mockfor function mocking. This change improves the test's compatibility with WordPress testing standards.- 47-66: Replacing direct calls to functions with
WP_Mock::userFunctionfor various utility functions likeawpcp_get_var,awpcp_parse_money, etc., is a good practice. It ensures that the tests are more isolated and not dependent on the actual implementation of these functions.tests/includes/testcase-awpcp.php (3)
- 6-6: Changing the base class for plugin tests to extend
TestCasefromWP_Mock\Toolsis a significant improvement. It aligns the test suite withWP_Mock, providing a more WordPress-centric approach to mocking and testing.- 47-58: The use of
WP_Mock::userFunctionfor mocking WordPress functions likeis_user_logged_in,wp_get_current_user, etc., in thelogoutmethod is a good practice. It ensures that the tests are not dependent on the actual WordPress environment, which is crucial for unit testing.- 191-211: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [168-222]
Refactoring the
mockCommonWpFunctionsmethod to useWP_Mockfor function mocking, including the adjustment of theexpectAddQueryArgmethod, is a positive change. It standardizes the approach to mocking WordPress functions across the test suite.tests/suite/includes/upgrade/test-store-listing-categories-as-custom-taxonomies-upgrade-task-handler.php (1)
- 36-38: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionforis_wp_erroris a good practice. It aligns with the transition to usingWP_Mock, which is more consistent with WordPress testing standards.tests/suite/admin/listings/test-listing-fields-metabox.php (2)
- 11-22: The addition of multiple private properties to the
AWPCP_ListingFieldsMetaboxTestclass is a good practice for encapsulation and clearly defines the dependencies required by the class.- 91-104: Using
WP_Mock::userFunctionfor mocking WordPress functions likewp_create_nonceandget_post_metais a good practice. It ensures that the tests are more isolated and not dependent on the actual implementation of these functions.tests/suite/includes/media/test-media-uploaded-notification.php (1)
- 161-180: Replacing direct calls to functions with
WP_Mock::userFunctionforget_option,awpcp_admin_email_to, etc., is a good practice. It ensures that the tests are more isolated and not dependent on the actual implementation of these functions, which is crucial for unit testing.tests/suite/admin/import/test-csv-importer-delegate.php (1)
- 123-141: The replacement of
Brain\Monkey\Functionscalls withWP_Mock::userFunctioncalls forget_user_by,wp_generate_password,wp_create_user, andis_wp_errorwithin theimport_rowmethod is appropriate for unit testing. Ensure that the tests cover all relevant cases and that the use of mocks accurately reflects the intended behavior of the actual WordPress functions.tests/suite/admin/listings/test-moderator-renew-listing-table-action.php (1)
- 87-91: The replacement of a
Brain\Monkey\Functionscall with aWP_Mock::userFunctioncall for mockingadd_query_argin thetest_get_urlmethod is appropriate for unit testing. Ensure that the test covers all relevant cases and that the use of the mock accurately reflects the intended behavior of the actual WordPress function.tests/suite/includes/helpers/test-request.php (3)
- 124-127: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingget_query_varis correctly implemented. This change aligns with the PR objectives to enhance testing compatibility.- 188-191: The usage of
WP_Mock::userFunctionfor mockingget_query_varin the context of getting the category ID from query variables is correctly applied and improves the test's compatibility and readability.- 199-201: Correctly using
WP_Mock::userFunctionto mockget_query_varfor testing the retrieval of the current listing ID when no query variable is set. This change enhances the test's clarity and maintainability.tests/suite/admin/test-admin-container-configuration.php (1)
- 54-56: The change to use
WP_Mock::userFunctionfor mockingawpcp_requestin thetest_container_defines_listings_table_views_handlermethod is correctly implemented. This adjustment is in line with the PR's goal to improve the testing framework's compatibility and reliability.tests/suite/functions/test-routes-functions.php (5)
- 61-64: The replacement of
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingawpcp_get_edit_listing_direct_urlis correctly applied. This change enhances the test's compatibility with the WordPress testing environment.- 78-80: Using
WP_Mock::userFunctionto mockawpcp_get_edit_listing_generic_urlcorrectly aligns with the PR's objectives to improve testing practices by utilizing a more standardized mocking approach.- 92-95: The use of
WP_Mock::userFunctionfor mockingawpcp_get_edit_listing_page_url_with_listing_idis properly implemented, ensuring that the test accurately simulates the behavior of the WordPress environment.- 107-125: The comprehensive mocking of WordPress functions using
WP_Mock::userFunctionin the context of testing friendly URLs for editing listings demonstrates a thorough approach to ensuring test reliability and compatibility.- 138-146: Correctly utilizing
WP_Mock::userFunctionfor mocking functions related to the generation of edit listing page URLs when friendly URLs are disabled. This change contributes to the consistency and maintainability of the test suite.tests/suite/frontend/test-edit-listing-page.php (2)
- 205-207: The introduction of
WP_Mock::userFunctionto mock theawpcpfunction is correctly implemented, aligning with the PR's objectives to improve the testing framework's compatibility and reliability.- 219-222: Using
WP_Mock::userFunctionto mockis_emailwithin the context of testing thedo_send_access_key_stepmethod is correctly applied. This change enhances the test's clarity and maintainability.tests/suite/listings/test-listings-collection.php (3)
- 14-18: The addition of private properties
$wordpress,$roles, and$queryto theAWPCP_ListingsCollectionTestclass is a positive change, enhancing the class's structure and making it more aligned with the testing requirements.- 32-39: Replacing
Brain\Monkey\FunctionswithWP_Mock::userFunctionfor mockingapply_filtersandis_adminfunctions is correctly implemented. This adjustment is in line with the PR's goal to improve the testing framework's compatibility and reliability.- 299-303: The repeated use of
WP_Mock::userFunctionforapply_filtersin a different context within the same file is consistent with the PR's objectives and enhances the test suite's compatibility with WordPress testing practices.tests/suite/admin/test-admin.php (10)
- 13-21: The addition of private properties
$post_type,$container,$views,$actions,$tablenav,$search,$columns,$restrictions, and$postto theAWPCP_AdminTestclass enhances the test's ability to simulate different scenarios and interactions within the admin panel. This change aligns with the objective of improving test coverage and functionality testing.- 10-25: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-36]
The
setUpmethod is correctly initializing the private properties with mock objects and specific values, ensuring that each test runs in a controlled environment. This setup is essential for isolating tests and accurately assessing the functionality being tested.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [37-76]
The
test_admin_init_configures_necessary_handlersmethod thoroughly tests the configuration of necessary handlers during theadmin_initaction. It correctly verifies that the expected actions and filters are added with the appropriate priorities, ensuring the admin panel's functionality is as intended.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [77-87]
The
test_admin_init_configures_no_handler_for_the_wrong_post_typemethod effectively tests that no handlers are configured for an incorrect post type during theadmin_initaction. This ensures that actions and filters are only applied where relevant, preventing unintended side effects.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [88-101]
The
test_register_listings_table_viewsmethod correctly tests the registration of listings table views, ensuring that the expected views are registered. This is crucial for maintaining the admin panel's usability and organization.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [102-120]
The
test_register_listings_table_actionsmethod effectively tests the registration of listings table actions, ensuring that the expected actions are registered. This contributes to the admin panel's functionality, allowing for various actions to be performed on listings directly from the table.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [121-132]
The
test_register_listings_table_search_modesmethod correctly tests the registration of listings table search modes, ensuring that the expected search modes are registered. This is important for enhancing the search functionality within the admin panel, allowing for more precise filtering of listings.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [133-138]
The
test_save_classifieds_meta_boxes_does_nothing_for_the_wrong_post_typemethod effectively tests that saving classifieds meta boxes does nothing for the wrong post type. This ensures that meta box saving logic is only applied to relevant post types, preventing unintended data manipulation.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [139-144]
The
test_save_classifieds_meta_boxes_does_nothing_for_the_wrong_post_statusmethod effectively tests that saving classifieds meta boxes does nothing for the wrong post status. This ensures that meta box saving logic is only applied when appropriate, maintaining data integrity.
- 10-25: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [145-161]
The
test_save_classified_meta_boxes_prevents_infinite_loopsmethod correctly tests that saving classified meta boxes prevents infinite loops. This is crucial for avoiding potential stack overflow errors or excessive resource consumption, ensuring the stability and performance of the admin panel.tests/suite/listings/test-query-integration.php (14)
- 12-15: The addition of private properties
$settings,$db,$post_type, and$query_varsto theAWPCP_QueryIntegrationTestclass enhances the test's ability to simulate different scenarios and interactions with the query integration for classifieds. This change aligns with the objective of improving test coverage and functionality testing.- 3-19: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [16-26]
The
setUpmethod is correctly initializing the private properties with mock objects and specific values, ensuring that each test runs in a controlled environment. This setup is essential for isolating tests and accurately assessing the functionality being tested.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [27-33]
The
test_parse_querymethod effectively tests the parsing of query parameters, ensuring that the expected post type is set correctly. This is crucial for the correct functioning of classifieds query integration, ensuring that queries are processed as intended.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [34-38]
The
test_pre_get_postsmethod correctly tests thepre_get_postsaction, ensuring that it modifies the query as expected for classifieds queries. This contributes to the seamless integration of classifieds into the WordPress query system.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [39-48]
The
test_pre_get_posts_does_nothing_for_non_classifieds_queriesmethod effectively tests that thepre_get_postsaction does nothing for non-classifieds queries. This ensures that only relevant queries are modified, preventing unintended side effects on other parts of the site.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [49-58]
The
test_normalize_sets_post_statusmethod correctly tests the normalization of query parameters, ensuring that the default post status is set correctly. This is important for ensuring that queries are processed with the correct parameters, contributing to accurate query results.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [59-68]
The
test_normalize_sets_post_status_if_not_defined_onlymethod effectively tests that the normalization process sets the post status only if it is not already defined by the user. This allows for custom query modifications while ensuring that default values are applied when necessary.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [69-78]
The
test_normalize_sets_ordermethod correctly tests the normalization of the order parameter, ensuring that the default order is set correctly. This is crucial for maintaining consistent ordering in query results, enhancing the user experience.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [79-88]
The
test_normalize_sets_order_if_not_defined_onlymethod effectively tests that the normalization process sets the order only if it is not already defined by the user. This allows for custom query modifications while ensuring that default values are applied when necessary.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [89-104]
The
test_normalize_region_query_parametermethod correctly tests the normalization of the region query parameter, ensuring that it correctly processes region-related parameters. This is important for accurately filtering classifieds based on geographical regions, enhancing the search functionality.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [105-118]
The
test_normalize_type_specific_region_query_parametermethod effectively tests the normalization of type-specific region query parameters, ensuring that it correctly processes each type of region parameter. This contributes to the flexibility and accuracy of region-based filtering in classifieds searches.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [119-130]
The
test_normalize_remove_other_region_query_parametersmethod correctly tests that the normalization process removes other region query parameters when a specific region parameter is provided. This avoids conflicts and ensures accurate query processing, contributing to the reliability of region-based filtering.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [131-140]
The
test_normalize_remove_empty_regions_query_parametersmethod effectively tests that the normalization process removes empty regions query parameters. This is important for cleaning up the query and avoiding processing unnecessary parameters, enhancing the efficiency and accuracy of the query processing.
- 3-19: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [141-156]
The
test_normalize_adds_is_valid_query_parametermethod correctly tests that the normalization process adds theis_validquery parameter when certain conditions are met. This is crucial for filtering classifieds based on their validity, ensuring that only relevant listings are included in the query results.tests/suite/includes/test-listings-api.php (6)
- 429-432: The usage of
WP_Mock::userFunctionfor mockingawpcp_send_listing_was_flagged_notificationis correctly implemented. This change fromBrain\Monkey\FunctionstoWP_Mock::userFunctionaligns with the PR objectives to enhance testing capabilities.- 503-515: The refactoring to use
WP_Mock::userFunctionfor functions likeawpcp_get_blog_name,home_url,awpcp, andawpcp_get_email_verification_urlis correctly done. This approach ensures that the tests are more WordPress-native and potentially more reliable.- 516-519: Correct use of
WP_Mock::userFunctionforawpcp_format_recipient_address. This change is part of the broader effort to improve the test suite by using a more standardized mocking framework.- 560-568: The use of
WP_Mock::userFunctionto mockcurrent_timein two different contexts (with 'mysql' and 'timestamp' as arguments) is a good practice. It ensures that the tests can simulate different scenarios accurately.- 621-638: The refactoring to use
WP_Mock::userFunctionforget_post_meta,current_time,awpcp_getip,awpcp_current_user_is_moderator, andwp_parse_argsis correctly implemented. This enhances the test suite's ability to mock and assert the behavior of these functions effectively.- 722-745: The use of
WP_Mock::userFunctionfor mocking functions related to sending email notifications (awpcp_send_listing_posted_notification_to_user,awpcp_send_listing_posted_notification_to_moderators,get_awpcp_option,awpcp_send_listing_awaiting_approval_notification_to_moderators) is correctly done. This ensures that the tests can verify the behavior of the Listings API in scenarios involving email notifications without actually sending emails.
Fixes https://github.com/Strategy11/awpcp/issues/3165
Summary by CodeRabbit
Brain\MonkeywithWP_Mockfor function mocking in various test files.WP_Mock::userFunctionfor mocking functions in multiple test files.WP_Mock::userFunctionfor improved function mocking and testing scenarios.