Skip to content

Conversation

@stephywells
Copy link
Contributor

@stephywells stephywells commented Mar 13, 2024

Fixes https://github.com/Strategy11/awpcp/issues/3165

Summary by CodeRabbit

  • New Features
    • Improved testing capabilities by replacing Brain\Monkey with WP_Mock for function mocking in various test files.
  • Bug Fixes
    • Enhanced testing setup by using WP_Mock::userFunction for mocking functions in multiple test files.
  • Tests
    • Updated test methods to utilize WP_Mock::userFunction for improved function mocking and testing scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2024

Walkthrough

The 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 wp_strip_all_tags were added, ensuring a more robust and secure plugin management experience.

Changes

Files Change Summary
admin/.../class-uninstall-admin-page.php
admin/.../admin-panel-uninstall.tpl.php
Added nonce verification, authorization check, and updated uninstall/deactivation functionality.
tests/bootstrap.php Initialized WP_Mock and set up Phake client.
tests/includes/shims.php Added wp_strip_all_tags function shim.
tests/.../test-uninstall-admin-page.php Introduced tests for uninstall admin page functionality.

🐰✨
In the garden of code, where the plugins do play,
A small change was made, to keep bugs at bay.
With a hop and a skip, security's tight,
No unwanted guests, in the night.
So here's to the devs, with their wisdom so bright,
Keeping our digital warren safe, all day and night.
🌟🐾

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@stephywells stephywells added run analysis Run the phpcs run tests Run the unit tests labels Mar 13, 2024
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 7a9631c and 9b8367e.
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_url for the uninstall link is correct and enhances security. Ensure that the nonce action used here matches the one expected in the verification step in class-uninstall-admin-page.php.
  • 37-39: The updated text for the deactivation link is clear and instructive, likely improving user experience.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 9b8367e and 9596539.
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.

Comment on lines 11 to 20
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() );
}
Copy link

@coderabbitai coderabbitai bot Mar 13, 2024

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?

Copy link
Contributor Author

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?

Copy link

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.

Copy link
Contributor Author

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?

Copy link

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!

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 9596539 and 6a435b4.
Files ignored due to path filters (2)
  • composer.json is excluded by: !**/*.json
  • composer.lock is 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.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 6a435b4 and 59aefca.
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

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 59aefca and 474ca68.
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_tags function as a shim is a good practice for ensuring compatibility with different WordPress versions. However, it's important to note that while strip_tags effectively 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.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 474ca68 and 6c56805.
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

stephywells added a commit that referenced this pull request Mar 20, 2024
Without the unit tests in #56
@stephywells stephywells marked this pull request as draft March 20, 2024 14:45
@stephywells stephywells changed the title Check uninstall Switch to WP_Mock Mar 20, 2024
@stephywells stephywells mentioned this pull request Mar 20, 2024
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 6c56805 and 399359e.
Files ignored due to path filters (2)
  • composer.json is excluded by: !**/*.json
  • composer.lock is 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_over is 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\Functions with WP_Mock::userFunction for mocking get_option is 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 $query property to AWPCP_ListingsTableSearchModeTestCase class 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\Functions import aligns with the shift towards using WP_Mock for WordPress testing. Ensure that all necessary functions are now being mocked using WP_Mock to avoid any potential issues with test execution.

tests/suite/frontend/test-frontend-container-configuration.php (1)
  • 24-26: Switching to WP_Mock::userFunction for mocking the awpcp function is a step towards better test reliability and consistency with WordPress standards. Verify that all instances previously using Brain\Monkey\Functions are now correctly using WP_Mock.
tests/suite/includes/media/test-media-container-configuration.php (1)
  • 19-30: Transitioning to WP_Mock::userFunction for 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 using WP_Mock and that there are no leftover references to Brain\Monkey.
tests/suite/listings/test-listing-renewed-email-notifications.php (2)
  • 11-13: Introducing new private properties ($listing_renderer, $template_renderer, $settings) in AWPCP_ListingRenewedEmailNotificationTest enhances the test's clarity and maintainability. Ensure these properties are well-documented and initialized correctly.
  • 52-54: Using WP_Mock::userFunction to mock awpcp_admin_email_to aligns with the shift towards WP_Mock for more consistent WordPress testing practices. Verify that all necessary functions are now being mocked using WP_Mock to maintain consistency across tests.
tests/suite/includes/frontend/test-show-listing-page.php (1)
  • 45-47: Switching to WP_Mock::userFunction for mocking get_awpcp_option is a positive step towards ensuring consistency and reliability in WordPress testing. Confirm that all instances previously using Brain\Monkey\Functions are now correctly using WP_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 bool annotation to the offsetExists method improves documentation and clarity. Good practice.
tests/suite/listings/test-listings-container-configuration.php (1)
  • 17-22: Replacing Brain\Monkey\Functions with WP_Mock::userFunction standardizes 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\Functions with WP_Mock::userFunction and using a closure for sanitize_key enhances the flexibility and consistency of mocking in tests.
tests/suite/includes/helpers/test-facebook-integration.php (1)
  • 34-36: Standardizing on WP_Mock for mocking wp_next_scheduled aligns with the project's preference for a consistent mocking framework.
tests/suite/includes/media/test-image-renderer.php (1)
  • 37-47: Using WP_Mock::userFunction for 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\Functions with WP_Mock::userFunction for 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\when with WP_Mock::userFunction standardizes 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 $authorization and its initialization in the setUp method is clear and follows good practices for setting up test environments. Ensure that this property is utilized effectively in the tests for the AWPCP_ListingFormFields class.
tests/suite/includes/listings/test-listings-content-renderer.php (1)
  • 36-57: The replacement of Brain\Monkey with WP_Mock for mocking functions and the usage of \WP_Mock::onFilter are 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 $wordpress and their initialization in the setUp method is clear and follows good practices for setting up test environments. Ensure that these properties are utilized effectively in the tests for the AWPCP_RemoveListingAttachmentsService class.
tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php (2)
  • 11-11: The addition of the private property $query and its initialization in the setUp method is clear and follows good practices for setting up test environments. Ensure that this property is utilized effectively in the tests for the AWPCP_IndeedMembershipProPluginIntegration class.
  • 60-68: The replacement of Brain\Monkey\Functions with WP_Mock::userFunction for mocking wp_dequeue_style and wp_dequeue_script is 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\Functions with WP_Mock::userFunction for mocking get_awpcp_option with 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::userFunction for mocking get_awpcp_option with a different set of arguments and return values is correctly done. This ensures that the test accurately simulates the behavior of the get_awpcp_option function.
  • 56-58: Correctly using WP_Mock::userFunction to mock awpcp_are_images_allowed without specifying times or args since 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\Functions with WP_Mock::userFunction for mocking awpcp_classifieds_bar and is_admin is 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::userFunction to mock awpcp_request_param and get_awpcp_option for the test_get_results_per_page function. 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 $views and $request to the AWPCP_ListTableViewsHandlerTest class 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\Functions with WP_Mock::userFunction for mocking various functions like get_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_logic and $listing_renderer to the AWPCP_UnflagListingTableActionTest class 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::userFunction to mock add_query_arg in the test_get_url method. This ensures that the test accurately simulates the behavior of the add_query_arg function, 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 $request to the AWPCP_ListingInformationMetaboxTest class 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::userFunction to mock awpcp_current_user_is_moderator in the test_render_when_the_listing_has_no_payment_term_associated method. This ensures that the test accurately simulates the behavior of the awpcp_current_user_is_moderator function, which is crucial for testing access control logic.
  • 95-97: Correctly using WP_Mock::userFunction to mock awpcp_current_user_is_moderator in the test_save_when_the_listing_has_no_previous_payment_term method. This ensures that the test accurately simulates the behavior of the awpcp_current_user_is_moderator function, 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\Functions with WP_Mock::userFunction for mocking get_option with specific arguments and return values is correctly implemented. This change ensures that the test accurately simulates the behavior of the get_option function, which is crucial for testing permalink structure logic.
  • 53-56: Correctly using WP_Mock::userFunction to mock get_option in the test_get_post_type_permastruct_includes_location_placeholder method. This ensures that the test accurately simulates the behavior of the get_option function, 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::userFunction to mock awpcp_current_user_is_moderator in the test_create_attachment_as_moderator method. This ensures that the test accurately simulates the behavior of the awpcp_current_user_is_moderator function, which is crucial for testing the creation of attachments with different user roles.
  • 79-81: Correctly using WP_Mock::userFunction to mock awpcp_current_user_is_moderator in the test_create_attachment_as_subscriber_when_imagesapprove_is_enabled method. This ensures that the test accurately simulates the behavior of the awpcp_current_user_is_moderator function, which is crucial for testing the creation of attachments with different user roles and settings.
  • 108-110: Correctly using WP_Mock::userFunction to mock awpcp_current_user_is_moderator in the test_create_attachment_marks_listings_as_having_images_awaiting_approval method. This ensures that the test accurately simulates the behavior of the awpcp_current_user_is_moderator function, 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\Functions with WP_Mock::userFunction for mocking has_shortcode in the test_is_search_listings_page method 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\Functions with WP_Mock::userFunction for mocking add_query_arg in the test_get_url method 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.php enhances 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_factory and $listing_renderer to the AWPCP_SendAccessKeyListingTableActionTest class enhances the clarity and maintainability of the test code by explicitly declaring dependencies.
  • 70-75: Replacing Brain\Monkey\Functions with WP_Mock::userFunction for mocking add_query_arg aligns 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 $facebook, $listing_renderer, $settings, and $wordpress to the AWPCP_SendToFacebookHelperTest class 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\Functions with WP_Mock::userFunction for mocking add_query_arg in the test_get_url method 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\Functions calls with WP_Mock::userFunction for mocking functions in test-container-configuration.php is 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\Functions and replacing its usage with WP_Mock::userFunction for add_query_arg in the test_get_url method 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_UninstallerTest class.
  • 47-67: Switching to WP_Mock for function mocking instead of Brain\Monkey\Functions aligns 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\Functions with WP_Mock::userFunction for mocking WordPress functions such as is_admin and get_awpcp_option is 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::userFunction for 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::userFunction for mocking awpcp_request_param and get_query_var functions 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 $request to the AWPCP_ListTableSearchHandlerTest class 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::userFunction for mocking the awpcp_get_var function 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::userFunction for mocking awpcp_get_var to 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::userFunction for mocking awpcp_get_var to 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\Functions with WP_Mock::userFunction for mocking remove_query_arg and awpcp_current_user_is_moderator functions 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_arg and wp_nonce_url functions within test methods, using WP_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::userFunction for adjusting the handling of add_query_arg within 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::userFunction for mocking is_user_logged_in 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.
  • 114-116: The use of WP_Mock::userFunction for mocking current_time function 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::userFunction for mocking current_time to 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 $data to the AWPCP_FormFieldsDataValidatorTest class 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\Monkey functions with WP_Mock for mocking awpcp_is_email_address_allowed is 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::userFunction for mocking awpcp_is_email_address_allowed in 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\Functions with WP_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::userFunction for mocking akismet_init to 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\Functions with WP_Mock::userFunction for mocking add_query_arg in 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 $wordpress to the AWPCP_SendToFacebookPageListingTableActionTest class 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\expect with WP_Mock::userFunction for mocking add_query_arg 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.
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 $wordpress is a good practice for encapsulation. Ensure that these properties are used appropriately within the class methods.
  • 81-85: Replacing Functions\expect with WP_Mock::userFunction aligns with the transition to using WP_Mock for 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 $authorization and $listing_renderer enhances the class structure by clearly defining its dependencies. Good practice for object-oriented design.
  • 25-29: The use of WP_Mock::userFunction for mocking awpcp_maybe_add_http_to_url is consistent with the shift towards WP_Mock for function mocking. This change improves the test's compatibility with WordPress testing standards.
  • 47-66: Replacing direct calls to functions with WP_Mock::userFunction for various utility functions like awpcp_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 TestCase from WP_Mock\Tools is a significant improvement. It aligns the test suite with WP_Mock, providing a more WordPress-centric approach to mocking and testing.
  • 47-58: The use of WP_Mock::userFunction for mocking WordPress functions like is_user_logged_in, wp_get_current_user, etc., in the logout method 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 mockCommonWpFunctions method to use WP_Mock for function mocking, including the adjustment of the expectAddQueryArg method, 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\Functions with WP_Mock::userFunction for is_wp_error is a good practice. It aligns with the transition to using WP_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_ListingFieldsMetaboxTest class is a good practice for encapsulation and clearly defines the dependencies required by the class.
  • 91-104: Using WP_Mock::userFunction for mocking WordPress functions like wp_create_nonce and get_post_meta is 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::userFunction for get_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\Functions calls with WP_Mock::userFunction calls for get_user_by, wp_generate_password, wp_create_user, and is_wp_error within the import_row method 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\Functions call with a WP_Mock::userFunction call for mocking add_query_arg in the test_get_url method 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\Functions with WP_Mock::userFunction for mocking get_query_var is correctly implemented. This change aligns with the PR objectives to enhance testing compatibility.
  • 188-191: The usage of WP_Mock::userFunction for mocking get_query_var in 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::userFunction to mock get_query_var for 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::userFunction for mocking awpcp_request in the test_container_defines_listings_table_views_handler method 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\Functions with WP_Mock::userFunction for mocking awpcp_get_edit_listing_direct_url is correctly applied. This change enhances the test's compatibility with the WordPress testing environment.
  • 78-80: Using WP_Mock::userFunction to mock awpcp_get_edit_listing_generic_url correctly aligns with the PR's objectives to improve testing practices by utilizing a more standardized mocking approach.
  • 92-95: The use of WP_Mock::userFunction for mocking awpcp_get_edit_listing_page_url_with_listing_id is 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::userFunction in 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::userFunction for 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::userFunction to mock the awpcp function is correctly implemented, aligning with the PR's objectives to improve the testing framework's compatibility and reliability.
  • 219-222: Using WP_Mock::userFunction to mock is_email within the context of testing the do_send_access_key_step method 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 $query to the AWPCP_ListingsCollectionTest class is a positive change, enhancing the class's structure and making it more aligned with the testing requirements.
  • 32-39: Replacing Brain\Monkey\Functions with WP_Mock::userFunction for mocking apply_filters and is_admin functions 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::userFunction for apply_filters in 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 $post to the AWPCP_AdminTest class 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 setUp method 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_handlers method thoroughly tests the configuration of necessary handlers during the admin_init action. 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_type method effectively tests that no handlers are configured for an incorrect post type during the admin_init action. 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_views method 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_actions method 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_modes method 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_type method 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_status method 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_loops method 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_vars to the AWPCP_QueryIntegrationTest class 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 setUp method 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_query method 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_posts method correctly tests the pre_get_posts action, 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_queries method effectively tests that the pre_get_posts action 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_status method 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_only method 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_order method 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_only method 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_parameter method 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_parameter method 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_parameters method 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_parameters method 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_parameter method correctly tests that the normalization process adds the is_valid query 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::userFunction for mocking awpcp_send_listing_was_flagged_notification is correctly implemented. This change from Brain\Monkey\Functions to WP_Mock::userFunction aligns with the PR objectives to enhance testing capabilities.
  • 503-515: The refactoring to use WP_Mock::userFunction for functions like awpcp_get_blog_name, home_url, awpcp, and awpcp_get_email_verification_url is correctly done. This approach ensures that the tests are more WordPress-native and potentially more reliable.
  • 516-519: Correct use of WP_Mock::userFunction for awpcp_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::userFunction to mock current_time in 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::userFunction for get_post_meta, current_time, awpcp_getip, awpcp_current_user_is_moderator, and wp_parse_args is 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::userFunction for 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Run the phpcs run tests Run the unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants