From 9b8367e918958d0696483248126267dbda107f09 Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 12 Mar 2024 19:20:13 -0600 Subject: [PATCH 01/11] Check uninstall Fixes https://github.com/Strategy11/awpcp/issues/3165 --- admin/class-uninstall-admin-page.php | 6 ++++++ admin/templates/admin-panel-uninstall.tpl.php | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/admin/class-uninstall-admin-page.php b/admin/class-uninstall-admin-page.php index ec3bcfc06..ef9aa3790 100644 --- a/admin/class-uninstall-admin-page.php +++ b/admin/class-uninstall-admin-page.php @@ -46,6 +46,12 @@ public function dispatch() { $dirname = $this->settings->get_runtime_option( 'awpcp-uploads-dir' ); if ( 0 === strcmp( $action, 'uninstall' ) ) { + // Check the wp_nonce_url. + $nonce = awpcp_get_var( array( 'param' => '_wpnonce' ), 'get' ); + if ( ! wp_verify_nonce( $nonce ) || ! awpcp_current_user_is_admin() ) { + wp_die( esc_html__( 'You are not authorized to perform this action.', 'another-wordpress-classifieds-plugin' ) ); + } + $this->uninstaller->uninstall(); } diff --git a/admin/templates/admin-panel-uninstall.tpl.php b/admin/templates/admin-panel-uninstall.tpl.php index bb20c66ab..f7cc204d4 100644 --- a/admin/templates/admin-panel-uninstall.tpl.php +++ b/admin/templates/admin-panel-uninstall.tpl.php @@ -24,8 +24,9 @@

- 'uninstall' ), $url ); ?> - + + +

@@ -33,7 +34,9 @@

- + + +

From e8be68140fd5fdb096e92edd07a65018747218b7 Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 12 Mar 2024 19:35:53 -0600 Subject: [PATCH 02/11] Add AI tests These tests haven't been run --- .../suite/admin/test-uninstall-admin-page.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/suite/admin/test-uninstall-admin-page.php diff --git a/tests/suite/admin/test-uninstall-admin-page.php b/tests/suite/admin/test-uninstall-admin-page.php new file mode 100644 index 000000000..829f61e97 --- /dev/null +++ b/tests/suite/admin/test-uninstall-admin-page.php @@ -0,0 +1,35 @@ +assertArrayHasKey( 'uninstall', $admin_pages ); + } + + 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() ); + } + + public function test_uninstall_admin_page_dispatch_uninstall() { + $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); + $settings = Mockery::mock( 'AWPCP_Settings' ); + + $uninstaller->shouldReceive( 'uninstall' )->once(); + + $_GET['_wpnonce'] = wp_create_nonce( 'uninstall' ); + $_GET['action'] = 'uninstall'; + + $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); + + $this->assertEmpty( $page->dispatch() ); + } +} From 9596539aba0b82b471f9c098acc84d31ec6fbc67 Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 12 Mar 2024 19:38:57 -0600 Subject: [PATCH 03/11] Make uninstall nonce more specific --- admin/class-uninstall-admin-page.php | 2 +- admin/templates/admin-panel-uninstall.tpl.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/class-uninstall-admin-page.php b/admin/class-uninstall-admin-page.php index ef9aa3790..125c19a0c 100644 --- a/admin/class-uninstall-admin-page.php +++ b/admin/class-uninstall-admin-page.php @@ -48,7 +48,7 @@ public function dispatch() { if ( 0 === strcmp( $action, 'uninstall' ) ) { // Check the wp_nonce_url. $nonce = awpcp_get_var( array( 'param' => '_wpnonce' ), 'get' ); - if ( ! wp_verify_nonce( $nonce ) || ! awpcp_current_user_is_admin() ) { + if ( ! wp_verify_nonce( $nonce, 'awpcp-uninstall' ) || ! awpcp_current_user_is_admin() ) { wp_die( esc_html__( 'You are not authorized to perform this action.', 'another-wordpress-classifieds-plugin' ) ); } diff --git a/admin/templates/admin-panel-uninstall.tpl.php b/admin/templates/admin-panel-uninstall.tpl.php index f7cc204d4..4d275e794 100644 --- a/admin/templates/admin-panel-uninstall.tpl.php +++ b/admin/templates/admin-panel-uninstall.tpl.php @@ -24,7 +24,7 @@

- +

From 6a435b4678872cbd5b74e9ea4c002da159b5d961 Mon Sep 17 00:00:00 2001 From: stephywells Date: Wed, 13 Mar 2024 22:23:34 -0600 Subject: [PATCH 04/11] Update unit tests --- composer.json | 3 +- composer.lock | 58 ++++++++++++- tests/bootstrap.php | 3 + .../suite/admin/test-uninstall-admin-page.php | 81 ++++++++++++++++--- 4 files changed, 131 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 7cd7ebd2f..8ca0dd197 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "wp-coding-standards/wpcs": "*", "php-stubs/wordpress-stubs": "^6.0", "phpstan/phpstan": "^1.8", - "dms/phpunit-arraysubset-asserts": "^0.4.0" + "dms/phpunit-arraysubset-asserts": "^0.4.0", + "10up/wp_mock": "^1.0" }, "config": { "allow-plugins": { diff --git a/composer.lock b/composer.lock index c178b5085..28bfd8cd7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,63 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b95d729f75d111eeea33dbb2affe5e6f", + "content-hash": "53dbc5d85fcaae13e68209e12848a4f8", "packages": [], "packages-dev": [ + { + "name": "10up/wp_mock", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/10up/wp_mock.git", + "reference": "48b7f22934a4351e45e336f09263ee27fc9ddcbe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/10up/wp_mock/zipball/48b7f22934a4351e45e336f09263ee27fc9ddcbe", + "reference": "48b7f22934a4351e45e336f09263ee27fc9ddcbe", + "shasum": "" + }, + "require": { + "antecedent/patchwork": "^2.1", + "mockery/mockery": "^1.6", + "php": ">=7.4 < 9", + "phpunit/phpunit": "^9.6" + }, + "require-dev": { + "behat/behat": "^v3.11.0", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "friendsofphp/php-cs-fixer": "^3.4", + "php-coveralls/php-coveralls": "^v2.7", + "php-stubs/wordpress-globals": "^0.2", + "php-stubs/wordpress-stubs": "^6.3", + "phpcompatibility/php-compatibility": "^9.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-phpunit": "^1.3", + "sebastian/comparator": "^4.0.8", + "sempro/phpunit-pretty-print": "^1.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "WP_Mock\\": "./php/WP_Mock" + }, + "classmap": [ + "php/WP_Mock.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "A mocking library to take the pain out of unit testing for WordPress", + "support": { + "issues": "https://github.com/10up/wp_mock/issues", + "source": "https://github.com/10up/wp_mock/tree/1.0.1" + }, + "time": "2024-01-22T02:22:57+00:00" + }, { "name": "antecedent/patchwork", "version": "2.1.25", @@ -2530,5 +2584,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 129f5f14e..d5d7fda7c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -24,6 +24,9 @@ } require AWPCP_DIR . '/vendor/autoload.php'; +// Bootstrap WP_Mock to initialize built-in features +WP_Mock::bootstrap(); + Phake::setClient( Phake::CLIENT_PHPUNIT6 ); require_once AWPCP_DIR . '/functions.php'; diff --git a/tests/suite/admin/test-uninstall-admin-page.php b/tests/suite/admin/test-uninstall-admin-page.php index 829f61e97..774e1619b 100644 --- a/tests/suite/admin/test-uninstall-admin-page.php +++ b/tests/suite/admin/test-uninstall-admin-page.php @@ -2,13 +2,37 @@ class Test_Uninstall_Admin_Page extends AWPCP_UnitTestCase { - public function test_admin_page_is_registered() { - $admin_pages = awpcp_admin_pages(); - - $this->assertArrayHasKey( 'uninstall', $admin_pages ); + 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( + 'wp_create_nonce', [ + 'times' => 1, + 'return' => '2weer2445', + ] + ); + \WP_Mock::userFunction( + 'current_user_can', [ + 'times' => 1, + 'return' => true, + ] + ); + \WP_Mock::userFunction( + 'is_ssl', + [ + 'times' => 1, + 'return' => true, + ] + ); } - public function test_uninstall_admin_page_dispatch() { + public function test_uninstall_admin_page_dispatch_with_valid_nonce_and_authorization() { $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); $settings = Mockery::mock( 'AWPCP_Settings' ); @@ -16,20 +40,55 @@ public function test_uninstall_admin_page_dispatch() { $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); - $this->assertContains( 'action=uninstall', $page->dispatch() ); + // Simulate a valid request with correct nonce and authorization. + $_REQUEST['nonce'] = 'valid_nonce'; + $this->assertContains( 'Almost done...', $page->dispatch() ); } - public function test_uninstall_admin_page_dispatch_uninstall() { + 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); - $uninstaller->shouldReceive( 'uninstall' )->once(); + $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. + ] + ); - $_GET['_wpnonce'] = wp_create_nonce( 'uninstall' ); - $_GET['action'] = 'uninstall'; + $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 ); - $this->assertEmpty( $page->dispatch() ); + $page->dispatch(); + } + + 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() ); } } From 59aefca76a44b98edc3f544d739a0ec20262cd46 Mon Sep 17 00:00:00 2001 From: stephywells Date: Wed, 13 Mar 2024 22:29:11 -0600 Subject: [PATCH 05/11] Include some wp functions in phpunit --- tests/bootstrap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d5d7fda7c..d74e5901f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -54,6 +54,10 @@ function _replace_modules_manager() { define( 'OBJECT', 'OBJECT' ); } +if ( ! function_exists( 'wp_strip_all_tags' ) ) { + require_once ABSPATH . 'wp-includes/formatting.php'; +} + require_once dirname( __FILE__ ) . '/includes/shims.php'; require_once dirname( __FILE__ ) . '/includes/functions.php'; require_once dirname( __FILE__ ) . '/includes/testcase-awpcp.php'; From 31a110980ad6f48edf2af5d98305efee852c78e1 Mon Sep 17 00:00:00 2001 From: stephywells Date: Wed, 13 Mar 2024 22:43:59 -0600 Subject: [PATCH 06/11] Add shim. Temp solution until this is fixed to run WP --- tests/bootstrap.php | 4 ---- tests/includes/shims.php | 12 ++++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d74e5901f..d5d7fda7c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -54,10 +54,6 @@ function _replace_modules_manager() { define( 'OBJECT', 'OBJECT' ); } -if ( ! function_exists( 'wp_strip_all_tags' ) ) { - require_once ABSPATH . 'wp-includes/formatting.php'; -} - require_once dirname( __FILE__ ) . '/includes/shims.php'; require_once dirname( __FILE__ ) . '/includes/functions.php'; require_once dirname( __FILE__ ) . '/includes/testcase-awpcp.php'; diff --git a/tests/includes/shims.php b/tests/includes/shims.php index 97d3bd58e..0d85c12db 100644 --- a/tests/includes/shims.php +++ b/tests/includes/shims.php @@ -16,3 +16,15 @@ function is_post_type_viewable( $post_type_object ) { return $post_type_object->publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public ); } } + +if ( ! function_exists( 'wp_strip_all_tags' ) ) { + /** + * Strips all of the HTML in the content. + * + * @param string $data Content to strip all HTML from. + * @return string Content without any HTML. + */ + function wp_strip_all_tags( $data ) { + return strip_tags( $data ); + } +} From 474ca68f022d399de33a133163735dfbf5b0f5eb Mon Sep 17 00:00:00 2001 From: stephywells Date: Wed, 13 Mar 2024 23:06:02 -0600 Subject: [PATCH 07/11] Set server values for unit tests --- tests/bootstrap.php | 1 - tests/suite/admin/test-uninstall-admin-page.php | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d5d7fda7c..1a193578b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -60,4 +60,3 @@ function _replace_modules_manager() { require_once dirname( __FILE__ ) . '/includes/testcase-step-decorator.php'; require_once dirname( __FILE__ ) . '/includes/class-listings-table-search-mode-test-case.php'; require_once dirname( __FILE__ ) . '/includes/class-container-configuration-test-case.php'; - diff --git a/tests/suite/admin/test-uninstall-admin-page.php b/tests/suite/admin/test-uninstall-admin-page.php index 774e1619b..5b45801c4 100644 --- a/tests/suite/admin/test-uninstall-admin-page.php +++ b/tests/suite/admin/test-uninstall-admin-page.php @@ -30,6 +30,9 @@ public function setUp(): void { 'return' => true, ] ); + + $_SERVER['HTTP_HOST'] = 'example.com'; + $_SERVER['REQUEST_URI'] = '/wp-admin/admin.php'; } public function test_uninstall_admin_page_dispatch_with_valid_nonce_and_authorization() { From 6c56805adeeeaddf8d843a4e90f67413cb27e6b1 Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 19 Mar 2024 09:52:16 -0600 Subject: [PATCH 08/11] Hopefully fix unit tests --- tests/suite/admin/test-uninstall-admin-page.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/suite/admin/test-uninstall-admin-page.php b/tests/suite/admin/test-uninstall-admin-page.php index 5b45801c4..04952c2ef 100644 --- a/tests/suite/admin/test-uninstall-admin-page.php +++ b/tests/suite/admin/test-uninstall-admin-page.php @@ -37,7 +37,7 @@ public function setUp(): void { public function test_uninstall_admin_page_dispatch_with_valid_nonce_and_authorization() { $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); - $settings = Mockery::mock( 'AWPCP_Settings' ); + $settings = $this->get_settings_class(); $uninstaller->shouldReceive( 'uninstall' )->once(); @@ -60,12 +60,20 @@ public function test_uninstall_admin_page_dispatch_with_invalid_nonce() { $this->expectException(\Exception::class); // Expect an exception due to invalid nonce. $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); - $settings = Mockery::mock( 'AWPCP_Settings' ); + $settings = $this->get_settings_class(); $page = new AWPCP_UninstallAdminPage($uninstaller, $settings); $page->dispatch(); } + private function get_settings_class() { + $settings = Mockery::mock( 'AWPCP_Settings' ); + + // 'Uploads' is not the right value, but it will do the job for this test. + $settings->shouldReceive( 'get_runtime_option' )->with( 'awpcp-uploads-dir' )->andReturn( 'uploads' ); + return $settings; + } + public function test_uninstall_admin_page_dispatch_without_authorization() { \WP_Mock::userFunction( 'current_user_can', From 6dbd65829e566a540af3c5b9812a0dc7f21984cf Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 19 Mar 2024 10:35:58 -0600 Subject: [PATCH 09/11] now add in the right branch --- tests/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1a193578b..5ff6d3983 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,6 +33,7 @@ require_once AWPCP_DIR . '/includes/functions/assets.php'; require_once AWPCP_DIR . '/includes/functions/listings.php'; require_once AWPCP_DIR . '/includes/functions/routes.php'; +require_once AWPCP_DIR . '/includes/functions/format.php'; /** * TODO: We probably won't need this if we stop using WordPress testing framework. From 3ccdca7bed18a6b7a6bc75cb672f4a3edfde78af Mon Sep 17 00:00:00 2001 From: stephywells Date: Tue, 19 Mar 2024 10:41:38 -0600 Subject: [PATCH 10/11] add more mocking --- tests/suite/admin/test-uninstall-admin-page.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/suite/admin/test-uninstall-admin-page.php b/tests/suite/admin/test-uninstall-admin-page.php index 04952c2ef..92ace8614 100644 --- a/tests/suite/admin/test-uninstall-admin-page.php +++ b/tests/suite/admin/test-uninstall-admin-page.php @@ -41,6 +41,7 @@ public function test_uninstall_admin_page_dispatch_with_valid_nonce_and_authoriz $uninstaller->shouldReceive( 'uninstall' )->once(); + $this->expectAddQueryArg(); $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); // Simulate a valid request with correct nonce and authorization. @@ -61,8 +62,9 @@ public function test_uninstall_admin_page_dispatch_with_invalid_nonce() { $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); $settings = $this->get_settings_class(); - $page = new AWPCP_UninstallAdminPage($uninstaller, $settings); + $this->expectAddQueryArg(); + $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); $page->dispatch(); } @@ -86,7 +88,7 @@ public function test_uninstall_admin_page_dispatch_without_authorization() { $this->expectException(\Exception::class); // Expect an exception due to lack of authorization. $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); - $settings = Mockery::mock( 'AWPCP_Settings' ); + $settings = $this->get_settings_class(); $page = new AWPCP_UninstallAdminPage( $uninstaller, $settings ); $page->dispatch(); @@ -94,7 +96,7 @@ public function test_uninstall_admin_page_dispatch_without_authorization() { public function test_uninstall_admin_page_dispatch() { $uninstaller = Mockery::mock( 'AWPCP_Uninstaller' ); - $settings = Mockery::mock( 'AWPCP_Settings' ); + $settings = $this->get_settings_class(); $uninstaller->shouldReceive( 'uninstall' )->once(); From 399359e768ced8f1fdbfed96632ab10903cb1170 Mon Sep 17 00:00:00 2001 From: stephywells Date: Wed, 20 Mar 2024 08:39:36 -0600 Subject: [PATCH 11/11] More progress on unit test updates... Maybe --- .github/workflows/phpunit.yml | 4 +- composer.json | 1 - composer.lock | 593 +++++++++++------- tests/bootstrap.php | 7 +- .../class-listing-table-view-test-helper.php | 1 - ...lass-container-configuration-test-case.php | 1 + ...s-listings-table-search-mode-test-case.php | 2 + tests/includes/shims.php | 34 + tests/includes/testcase-awpcp.php | 80 ++- .../import/test-csv-importer-delegate.php | 32 +- ...t-awaiting-approval-listing-table-view.php | 2 - .../test-complete-listing-table-view.php | 2 - .../test-expired-listing-table-view.php | 2 - .../listings/test-listing-fields-metabox.php | 52 +- .../test-listing-information-metabox.php | 16 +- .../test-listings-table-nav-handler.php | 14 +- ...est-make-featured-listing-table-action.php | 11 +- ...est-make-standard-listing-table-action.php | 11 +- ...test-mark-as-spam-listing-table-action.php | 18 +- ...est-mark-reviewed-listing-table-action.php | 11 +- ...t-moderator-renew-listing-table-action.php | 11 +- ...t-send-access-key-listing-table-action.php | 23 +- ...to-facebook-group-listing-table-action.php | 15 +- ...-to-facebook-page-listing-table-action.php | 15 +- .../test-unflag-listing-table-action.php | 14 +- .../test-admin-container-configuration.php | 6 +- tests/suite/admin/test-admin.php | 10 + tests/suite/admin/test-filtered-array.php | 7 +- .../admin/test-list-table-actions-handler.php | 38 +- .../admin/test-list-table-search-handler.php | 26 +- .../admin/test-list-table-views-handler.php | 3 + ...deed-membership-pro-plugin-integration.php | 15 +- .../form-fields/test-form-fields-data.php | 92 ++- .../test-form-fields-validator.php | 18 +- .../form-fields/test-listing-form-fields.php | 2 + .../test-terms-of-service-form-field.php | 4 + .../suite/frontend/test-edit-listing-page.php | 13 +- .../test-frontend-container-configuration.php | 6 +- tests/suite/frontend/test-query.php | 9 +- .../test-submit-listing-form-steps.php | 2 - ...kwards-compatiblity-redirection-helper.php | 24 +- .../functions/test-pagination-functions.php | 77 ++- .../suite/functions/test-routes-functions.php | 52 +- .../categories/test-category-presenter.php | 9 +- .../frontend/test-image-placeholders.php | 24 +- tests/suite/includes/frontend/test-pages.php | 2 - .../frontend/test-show-listing-page.php | 6 +- .../frontend/test-user-listings-shortcode.php | 29 +- .../functions/test-listings-functions.php | 18 +- .../helpers/test-facebook-integration.php | 6 +- tests/suite/includes/helpers/test-request.php | 16 +- .../test-listings-content-renderer.php | 40 +- .../listings/test-listings-permalinks.php | 19 +- .../media/test-image-attachment-creator.php | 14 +- .../includes/media/test-image-renderer.php | 22 +- .../test-media-container-configuration.php | 18 +- .../test-media-uploaded-notification.php | 31 +- tests/suite/includes/test-awpcp.php | 14 +- .../includes/test-listing-authorization.php | 14 +- tests/suite/includes/test-listings-api.php | 117 ++-- tests/suite/includes/test-payments-api.php | 52 +- .../includes/ui/test-classifieds-bar.php | 2 - ...custom-taxonomies-upgrade-task-handler.php | 21 +- ...ia-as-attachments-upgrade-task-handler.php | 46 +- .../facebook/test-send-to-facebook-helper.php | 5 + ...st-listing-renewed-email-notifications.php | 10 +- .../listings/test-listings-collection.php | 22 +- .../test-listings-container-configuration.php | 10 +- .../suite/listings/test-query-integration.php | 23 +- ...est-remove-listing-attachments-service.php | 4 + .../test-settings-container-configuration.php | 6 +- tests/suite/test-container-configuration.php | 34 +- tests/suite/test-uninstaller.php | 38 +- tests/suite/ui/test-categories-selector.php | 10 +- 74 files changed, 1303 insertions(+), 755 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index cdb460f3a..d1a19d86c 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -20,10 +20,10 @@ jobs: name: PHP ${{ matrix.php }} tests in WP ${{ matrix.wordpress }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3.5.3 # get the PHP version - - uses: shivammathur/setup-php@v2 + - uses: shivammathur/setup-php@2.25.5 with: php-version: ${{ matrix.php }} - name: Installing WordPress diff --git a/composer.json b/composer.json index 8ca0dd197..ba5f0c6d4 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "require-dev": { "yoast/phpunit-polyfills": "^1.0", "antecedent/patchwork": "^2.1.21", - "brain/monkey": "dev-dev", "dealerdirect/phpcodesniffer-composer-installer": "0.*", "phake/phake": "^4.0", "phpcompatibility/php-compatibility": "*", diff --git a/composer.lock b/composer.lock index 28bfd8cd7..e0979eef2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "53dbc5d85fcaae13e68209e12848a4f8", + "content-hash": "f724ba0f9fa6235413396df55c4d27b1", "packages": [], "packages-dev": [ { @@ -63,16 +63,16 @@ }, { "name": "antecedent/patchwork", - "version": "2.1.25", + "version": "2.1.28", "source": { "type": "git", "url": "https://github.com/antecedent/patchwork.git", - "reference": "17314e042d45e0dacb0a494c2d1ef50e7621136a" + "reference": "6b30aff81ebadf0f2feb9268d3e08385cebcc08d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/antecedent/patchwork/zipball/17314e042d45e0dacb0a494c2d1ef50e7621136a", - "reference": "17314e042d45e0dacb0a494c2d1ef50e7621136a", + "url": "https://api.github.com/repos/antecedent/patchwork/zipball/6b30aff81ebadf0f2feb9268d3e08385cebcc08d", + "reference": "6b30aff81ebadf0f2feb9268d3e08385cebcc08d", "shasum": "" }, "require": { @@ -93,7 +93,7 @@ } ], "description": "Method redefinition (monkey-patching) functionality for PHP.", - "homepage": "http://patchwork2.org/", + "homepage": "https://antecedent.github.io/patchwork/", "keywords": [ "aop", "aspect", @@ -105,79 +105,9 @@ ], "support": { "issues": "https://github.com/antecedent/patchwork/issues", - "source": "https://github.com/antecedent/patchwork/tree/2.1.25" + "source": "https://github.com/antecedent/patchwork/tree/2.1.28" }, - "time": "2023-02-19T12:51:24+00:00" - }, - { - "name": "brain/monkey", - "version": "dev-dev", - "source": { - "type": "git", - "url": "https://github.com/Brain-WP/BrainMonkey.git", - "reference": "39fefa0550782afa3f957d2436d285d251651319" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/39fefa0550782afa3f957d2436d285d251651319", - "reference": "39fefa0550782afa3f957d2436d285d251651319", - "shasum": "" - }, - "require": { - "antecedent/patchwork": "^2.1.17", - "mockery/mockery": "^1.3.5 || ^1.4.4", - "php": ">=5.6.0" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", - "phpcompatibility/php-compatibility": "^9.3.0", - "phpunit/phpunit": "^5.7.26 || ^6.0 || ^7.0 || >=8.0 <8.5.12 || ^8.5.14 || ^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-version/1": "1.x-dev", - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "files": [ - "inc/api.php" - ], - "psr-4": { - "Brain\\Monkey\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Giuseppe Mazzapica", - "email": "giuseppe.mazzapica@gmail.com", - "homepage": "https://gmazzap.me", - "role": "Developer" - } - ], - "description": "Mocking utility for PHP functions and WordPress plugin API", - "keywords": [ - "Monkey Patching", - "interception", - "mock", - "mock functions", - "mockery", - "patchwork", - "redefinition", - "runkit", - "test", - "testing" - ], - "support": { - "issues": "https://github.com/Brain-WP/BrainMonkey/issues", - "source": "https://github.com/Brain-WP/BrainMonkey" - }, - "time": "2022-01-04T15:10:07+00:00" + "time": "2024-02-06T09:26:11+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -422,31 +352,29 @@ }, { "name": "mockery/mockery", - "version": "1.6.4", + "version": "1.6.10", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "d1413755e26fe56a63455f7753221c86cbb88f66" + "reference": "47065d1be1fa05def58dc14c03cf831d3884ef0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/d1413755e26fe56a63455f7753221c86cbb88f66", - "reference": "d1413755e26fe56a63455f7753221c86cbb88f66", + "url": "https://api.github.com/repos/mockery/mockery/zipball/47065d1be1fa05def58dc14c03cf831d3884ef0b", + "reference": "47065d1be1fa05def58dc14c03cf831d3884ef0b", "shasum": "" }, "require": { "hamcrest/hamcrest-php": "^2.0.1", "lib-pcre": ">=7.0", - "php": ">=7.4,<8.3" + "php": ">=7.3" }, "conflict": { "phpunit/phpunit": "<8.0" }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.3", - "psalm/plugin-phpunit": "^0.18.4", - "symplify/easy-coding-standard": "^11.5.0", - "vimeo/psalm": "^5.13.1" + "phpunit/phpunit": "^8.5 || ^9.6.17", + "symplify/easy-coding-standard": "^12.1.14" }, "type": "library", "autoload": { @@ -503,7 +431,7 @@ "security": "https://github.com/mockery/mockery/security/advisories", "source": "https://github.com/mockery/mockery" }, - "time": "2023-07-19T15:51:02+00:00" + "time": "2024-03-19T16:15:45+00:00" }, { "name": "myclabs/deep-copy", @@ -566,25 +494,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.16.0", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -592,7 +522,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -616,33 +546,33 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2023-06-25T14:52:30+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phake/phake", - "version": "v4.4.0", + "version": "v4.5.0", "source": { "type": "git", "url": "https://github.com/phake/phake.git", - "reference": "5c8954791645d9b7fc027bf76822a221a5a4de8a" + "reference": "0ec89bb1f780018fd34059409d79b7b49d60cc11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phake/phake/zipball/5c8954791645d9b7fc027bf76822a221a5a4de8a", - "reference": "5c8954791645d9b7fc027bf76822a221a5a4de8a", + "url": "https://api.github.com/repos/phake/phake/zipball/0ec89bb1f780018fd34059409d79b7b49d60cc11", + "reference": "0ec89bb1f780018fd34059409d79b7b49d60cc11", "shasum": "" }, "require": { "doctrine/instantiator": "^1.4", "php": "^7.1|^8.0", - "sebastian/comparator": "^1.1|^2.0|^3.0|^4.0|^5.0" + "sebastian/comparator": "^1.1|^2.0|^3.0|^4.0|^5.0|^6.0" }, "require-dev": { "doctrine/annotations": "^1.13", - "hamcrest/hamcrest-php": "1.1.*", - "phpunit/phpunit": "^6.5|^7.0|^8.0|^9.0|^10.0", + "hamcrest/hamcrest-php": "^1.1|^2.0", + "phpunit/phpunit": "^6.5|^7.0|^8.0|^9.0|^10.0|^11.0", "psalm/phar": "^4.18" }, "suggest": { @@ -652,7 +582,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.4-dev" + "dev-master": "5.0.x-dev", + "dev-4.4": "4.4.x-dev" } }, "autoload": { @@ -686,26 +617,27 @@ "support": { "docs": "https://phake.github.io/doc/", "issues": "https://github.com/phake/phake/issues", - "source": "https://github.com/phake/phake/tree/v4.4.0" + "source": "https://github.com/phake/phake/tree/v4.5.0" }, - "time": "2023-02-10T20:32:41+00:00" + "time": "2024-03-05T17:41:33+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + "reference": "54750ef60c58e43759730615a392c31c80e23176" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", "shasum": "" }, "require": { "ext-dom": "*", + "ext-libxml": "*", "ext-phar": "*", "ext-xmlwriter": "*", "phar-io/version": "^3.0.1", @@ -746,9 +678,15 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" + "source": "https://github.com/phar-io/manifest/tree/2.0.4" }, - "time": "2021-07-20T11:28:43+00:00" + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" }, { "name": "phar-io/version", @@ -803,29 +741,31 @@ }, { "name": "php-stubs/wordpress-stubs", - "version": "v6.2.1", + "version": "v6.4.3", "source": { "type": "git", "url": "https://github.com/php-stubs/wordpress-stubs.git", - "reference": "0009429e639b748eef1c955200ea0d4e5ad5627d" + "reference": "6105bdab2f26c0204fe90ecc53d5684754550e8f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/0009429e639b748eef1c955200ea0d4e5ad5627d", - "reference": "0009429e639b748eef1c955200ea0d4e5ad5627d", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/6105bdab2f26c0204fe90ecc53d5684754550e8f", + "reference": "6105bdab2f26c0204fe90ecc53d5684754550e8f", "shasum": "" }, "require-dev": { - "nikic/php-parser": "< 4.12.0", - "php": "~7.3 || ~8.0", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^4.13", + "php": "^7.4 || ~8.0.0", "php-stubs/generator": "^0.8.3", "phpdocumentor/reflection-docblock": "^5.3", - "phpstan/phpstan": "^1.10.12", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan": "^1.10.49", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.11" }, "suggest": { "paragonie/sodium_compat": "Pure PHP implementation of libsodium", - "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" }, "type": "library", @@ -842,9 +782,9 @@ ], "support": { "issues": "https://github.com/php-stubs/wordpress-stubs/issues", - "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.2.1" + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.4.3" }, - "time": "2023-05-18T04:35:23+00:00" + "time": "2024-02-11T18:56:19+00:00" }, { "name": "phpcompatibility/php-compatibility", @@ -908,18 +848,184 @@ }, "time": "2019-12-27T09:44:58+00:00" }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.10", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/51609a5b89f928e0c463d6df80eb38eff1eaf544", + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.9.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-03-17T23:44:50+00:00" + }, { "name": "phpstan/phpstan", - "version": "1.10.26", + "version": "1.10.63", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "5d660cbb7e1b89253a47147ae44044f49832351f" + "reference": "ad12836d9ca227301f5fb9960979574ed8628339" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5d660cbb7e1b89253a47147ae44044f49832351f", - "reference": "5d660cbb7e1b89253a47147ae44044f49832351f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/ad12836d9ca227301f5fb9960979574ed8628339", + "reference": "ad12836d9ca227301f5fb9960979574ed8628339", "shasum": "" }, "require": { @@ -968,27 +1074,27 @@ "type": "tidelift" } ], - "time": "2023-07-19T12:44:37+00:00" + "time": "2024-03-18T16:53:53+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.27", + "version": "9.2.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", + "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -1038,7 +1144,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" }, "funding": [ { @@ -1046,7 +1152,7 @@ "type": "github" } ], - "time": "2023-07-26T13:44:30+00:00" + "time": "2024-03-02T06:37:42+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1291,16 +1397,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.10", + "version": "9.6.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" + "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1a156980d78a6666721b7e8e8502fe210b587fcd", + "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd", "shasum": "" }, "require": { @@ -1315,7 +1421,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1374,7 +1480,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.17" }, "funding": [ { @@ -1390,20 +1496,20 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:04:23+00:00" + "time": "2024-02-23T13:14:51+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/2b56bea83a09de3ac06bb18b92f068e60cc6f50b", + "reference": "2b56bea83a09de3ac06bb18b92f068e60cc6f50b", "shasum": "" }, "require": { @@ -1438,7 +1544,7 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.2" }, "funding": [ { @@ -1446,7 +1552,7 @@ "type": "github" } ], - "time": "2020-09-28T06:08:49+00:00" + "time": "2024-03-02T06:27:43+00:00" }, { "name": "sebastian/code-unit", @@ -1635,20 +1741,20 @@ }, { "name": "sebastian/complexity", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/25f207c40d62b8b7aa32f5ab026c53561964053a", + "reference": "25f207c40d62b8b7aa32f5ab026c53561964053a", "shasum": "" }, "require": { - "nikic/php-parser": "^4.7", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -1680,7 +1786,7 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.3" }, "funding": [ { @@ -1688,20 +1794,20 @@ "type": "github" } ], - "time": "2020-10-26T15:52:27+00:00" + "time": "2023-12-22T06:19:30+00:00" }, { "name": "sebastian/diff", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", + "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", "shasum": "" }, "require": { @@ -1746,7 +1852,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" }, "funding": [ { @@ -1754,7 +1860,7 @@ "type": "github" } ], - "time": "2023-05-07T05:35:17+00:00" + "time": "2024-03-02T06:30:58+00:00" }, { "name": "sebastian/environment", @@ -1821,16 +1927,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.5", + "version": "4.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/78c00df8f170e02473b682df15bfcdacc3d32d72", + "reference": "78c00df8f170e02473b682df15bfcdacc3d32d72", "shasum": "" }, "require": { @@ -1886,7 +1992,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.6" }, "funding": [ { @@ -1894,20 +2000,20 @@ "type": "github" } ], - "time": "2022-09-14T06:03:37+00:00" + "time": "2024-03-02T06:33:00+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", + "reference": "bca7df1f32ee6fe93b4d4a9abbf69e13a4ada2c9", "shasum": "" }, "require": { @@ -1950,7 +2056,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.7" }, "funding": [ { @@ -1958,24 +2064,24 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2024-03-02T06:35:11+00:00" }, { "name": "sebastian/lines-of-code", - "version": "1.0.3", + "version": "1.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e1e4a170560925c26d424b6a03aed157e7dcc5c5", + "reference": "e1e4a170560925c26d424b6a03aed157e7dcc5c5", "shasum": "" }, "require": { - "nikic/php-parser": "^4.6", + "nikic/php-parser": "^4.18 || ^5.0", "php": ">=7.3" }, "require-dev": { @@ -2007,7 +2113,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.4" }, "funding": [ { @@ -2015,7 +2121,7 @@ "type": "github" } ], - "time": "2020-11-28T06:42:11+00:00" + "time": "2023-12-22T06:20:34+00:00" }, { "name": "sebastian/object-enumerator", @@ -2194,16 +2300,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -2215,7 +2321,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -2236,8 +2342,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -2245,7 +2350,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", @@ -2358,16 +2463,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.2", + "version": "3.9.0", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", - "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", "shasum": "" }, "require": { @@ -2377,11 +2482,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -2396,35 +2501,58 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", "standards", "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, - "time": "2023-02-22T23:07:41+00:00" + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-02-16T15:06:51+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.1", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", "shasum": "" }, "require": { @@ -2453,7 +2581,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" }, "funding": [ { @@ -2461,34 +2589,42 @@ "type": "github" } ], - "time": "2021-07-28T10:34:58+00:00" + "time": "2024-03-03T12:36:25+00:00" }, { "name": "wp-coding-standards/wpcs", - "version": "2.3.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "7da1894633f168fe244afc6de00d141f27517b62" + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", - "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", "shasum": "" }, "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.3.1" + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.0", - "phpcsstandards/phpcsdevtools": "^1.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -2505,6 +2641,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -2512,20 +2649,26 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2020-05-13T23:57:56+00:00" + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" }, { "name": "yoast/phpunit-polyfills", - "version": "1.0.5", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "3b59adeef77fb1c03ff5381dbb9d68b0aaff3171" + "reference": "224e4a1329c03d8bad520e3fc4ec980034a4b212" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/3b59adeef77fb1c03ff5381dbb9d68b0aaff3171", - "reference": "3b59adeef77fb1c03ff5381dbb9d68b0aaff3171", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/224e4a1329c03d8bad520e3fc4ec980034a4b212", + "reference": "224e4a1329c03d8bad520e3fc4ec980034a4b212", "shasum": "" }, "require": { @@ -2572,14 +2715,12 @@ "issues": "https://github.com/Yoast/PHPUnit-Polyfills/issues", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2023-03-30T23:39:05+00:00" + "time": "2023-08-19T14:25:08+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "brain/monkey": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5ff6d3983..9131b292b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -17,14 +17,11 @@ define( 'AWPCP_DIR', dirname( __DIR__ ) ); define( 'AWPCP_URL', 'https://example.org/wp-content/plugins/another-wordpress-classifieds-plugin' ); -$patchwork = AWPCP_DIR . '/vendor/antecedent/patchwork/Patchwork.php'; - -if ( file_exists( $patchwork ) ) { - require_once $patchwork; -} require AWPCP_DIR . '/vendor/autoload.php'; +require_once dirname( __DIR__ ) . '/vendor/autoload.php'; // Bootstrap WP_Mock to initialize built-in features +WP_Mock::setUsePatchwork( true ); WP_Mock::bootstrap(); Phake::setClient( Phake::CLIENT_PHPUNIT6 ); diff --git a/tests/includes/admin/listings/class-listing-table-view-test-helper.php b/tests/includes/admin/listings/class-listing-table-view-test-helper.php index 6dbd8e684..6a479f2f5 100644 --- a/tests/includes/admin/listings/class-listing-table-view-test-helper.php +++ b/tests/includes/admin/listings/class-listing-table-view-test-helper.php @@ -6,7 +6,6 @@ /** * Test helper for Listing Table View. */ -use Brain\Monkey\Functions; class AWPCP_ListingTableViewTestHelper { /** diff --git a/tests/includes/class-container-configuration-test-case.php b/tests/includes/class-container-configuration-test-case.php index eec41b3f2..7f837c4ba 100644 --- a/tests/includes/class-container-configuration-test-case.php +++ b/tests/includes/class-container-configuration-test-case.php @@ -47,6 +47,7 @@ public function service( $callback ) { /** * @param mixed $offset The name of the offset to check. * @since 4.0.0 + * @return bool */ public function offsetExists( $offset ) { return true; diff --git a/tests/includes/class-listings-table-search-mode-test-case.php b/tests/includes/class-listings-table-search-mode-test-case.php index 184329432..0ad3be7d6 100644 --- a/tests/includes/class-listings-table-search-mode-test-case.php +++ b/tests/includes/class-listings-table-search-mode-test-case.php @@ -8,6 +8,8 @@ */ abstract class AWPCP_ListingsTableSearchModeTestCase extends AWPCP_UnitTestCase { + protected $query; + /** * @since 4.0.0 */ diff --git a/tests/includes/shims.php b/tests/includes/shims.php index 0d85c12db..22be47989 100644 --- a/tests/includes/shims.php +++ b/tests/includes/shims.php @@ -28,3 +28,37 @@ function wp_strip_all_tags( $data ) { return strip_tags( $data ); } } + +if ( ! function_exists( 'has_action' ) ) { + /** + * Check if any action has been registered for a hook. + * + * @param string $tag The name of the action hook. + * @param callable|bool $function_to_check Optional. The callback to check for. Default false. + * @return int|bool If $function_to_check is omitted, returns boolean for whether the hook has anything registered. + * When checking a specific function, the priority of that hook is returned, or false if the function is not attached. + */ + function has_action( $tag, $function_to_check = false ) { + return has_filter( $tag, $function_to_check ); + } +} + +if ( ! function_exists( 'has_filter' ) ) { + /** + * Check if any filter has been registered for a hook. + * + * @param string $tag The name of the filter hook. + * @param callable|bool $function_to_check Optional. The callback to check for. Default false. + * @return int|bool If $function_to_check is omitted, returns boolean for whether the hook has anything registered. + * When checking a specific function, the priority of that hook is returned, or false if the function is not attached. + */ + function has_filter( $tag, $function_to_check = false ) { + global $wp_filter; + + if ( ! isset( $wp_filter[ $tag ] ) ) { + return false; + } + + return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check ); + } +} diff --git a/tests/includes/testcase-awpcp.php b/tests/includes/testcase-awpcp.php index 84e942ca4..f4c3ef072 100644 --- a/tests/includes/testcase-awpcp.php +++ b/tests/includes/testcase-awpcp.php @@ -3,15 +3,14 @@ * @package AWPCP\Tests */ -use Brain\Monkey; -use Brain\Monkey\Functions; +use WP_Mock\Tools\TestCase; use function Patchwork\redefine; /** * Base class for all plugin tests. */ -abstract class AWPCP_UnitTestCase extends PHPUnit\Framework\TestCase { +abstract class AWPCP_UnitTestCase extends TestCase { protected static $mockCommonWpFunctionsInSetUp = false; /** * @var array [Patchwork\CallRouting\Handle] @@ -28,7 +27,6 @@ abstract class AWPCP_UnitTestCase extends PHPUnit\Framework\TestCase { */ public function setUp(): void { parent::setUp(); - Monkey\setup(); $this->mockCommonWpFunctions(); } @@ -37,7 +35,6 @@ public function setUp(): void { */ public function tearDown(): void { array_map( 'Patchwork\restore', $this->redefined_functions ); - Monkey\teardown(); parent::tearDown(); } @@ -47,10 +44,18 @@ public function tearDown(): void { protected function logout() { $user = (object) [ 'ID' => 0 ]; - Functions\when( 'is_user_logged_in' )->justReturn( false ); - Functions\when( 'wp_get_current_user' )->justReturn( $user ); - Functions\when( 'get_current_user_id' )->justReturn( $user->ID ); - Functions\when( 'awpcp_current_user_is_admin' )->justReturn( false ); + WP_Mock::userFunction( 'is_user_logged_in', [ + 'return' => false, + ] ); + WP_Mock::userFunction( 'wp_get_current_user', [ + 'return' => $user, + ] ); + WP_Mock::userFunction( 'get_current_user_id', [ + 'return' => $user->ID, + ] ); + WP_Mock::userFunction( 'awpcp_current_user_is_admin', [ + 'return' => false, + ] ); } /** @@ -61,10 +66,18 @@ protected function login_as_subscriber() { $user->ID = wp_rand(); - Functions\when( 'is_user_logged_in' )->justReturn( true ); - Functions\when( 'wp_get_current_user' )->justReturn( $user ); - Functions\when( 'get_current_user_id' )->justReturn( $user->ID ); - Functions\when( 'awpcp_current_user_is_admin' )->justReturn( false ); + WP_Mock::userFunction( 'is_user_logged_in', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'wp_get_current_user', [ + 'return' => $user, + ] ); + WP_Mock::userFunction( 'get_current_user_id', [ + 'return' => $user->ID, + ] ); + WP_Mock::userFunction( 'awpcp_current_user_is_admin', [ + 'return' => false, + ] ); } /** @@ -73,7 +86,9 @@ protected function login_as_subscriber() { protected function login_as_administrator() { $this->login_as_subscriber(); - Functions\when( 'awpcp_current_user_is_admin' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_current_user_is_admin', [ + 'return' => true, + ] ); } /** @@ -120,9 +135,6 @@ protected function enable_permalinks() { /** * Use it to redefine methods of the object under the test or static methods. * - * To set expectations or control the behaviour of other methods/functions - * use Brain\Monkey\Functions API. - * * The same can be achieved creating a partial mock of the object under test, * but I find the following easier to write: * @@ -153,8 +165,7 @@ function( $arg ) use ( &$param ) { ); } protected function mockCommonWpFunctions() { - Functions\stubs( - [ + $functions = [ '__', 'esc_attr__', 'esc_html__', @@ -168,6 +179,7 @@ protected function mockCommonWpFunctions() { 'esc_textarea', 'esc_url', 'sanitize_text_field', + 'sanitize_textarea_field', 'wp_parse_args' => static function ( $settings, $defaults ) { return \array_merge( $defaults, $settings ); }, @@ -179,8 +191,21 @@ protected function mockCommonWpFunctions() { return rand(); }, 'esc_url_raw', - ] - ); + 'wp_json_encode' => static function( $value ) { + return \json_encode( $value ); + }, + ]; + + foreach ( $functions as $function => $callback ) { + if ( \is_string( $function ) ) { + WP_Mock::userFunction( $function, [ 'return' => $callback ] ); + } else { + // Return the first argument. + WP_Mock::userFunction( $callback, [ 'return' => function( $arg ) { + return $arg; + } ] ); + } + } $functions = [ '_e', @@ -190,18 +215,23 @@ protected function mockCommonWpFunctions() { ]; foreach ( $functions as $function ) { - Functions\when( $function )->echoArg(); + WP_Mock::userFunction( $function, [ + 'return' => function( $arg ) { + echo $arg; + } + ] ); } } protected function expectAddQueryArg( $key = null, $val = null, $url = null ) { - Functions\expect( 'add_query_arg' )->andReturnUsing( - function () use ( $key, $val, $url ) { + WP_Mock::userFunction( 'add_query_arg', [ + 'return' => function () use ( $key, $val, $url ) { if ( is_array( $key ) ) { return 'https://example.org' . '?' . key( $key ) . '=' . $key[ key( $key ) ]; } else { return $url . '?' . $key . '=' . $val; } - } ); + } + ] ); } } diff --git a/tests/suite/admin/import/test-csv-importer-delegate.php b/tests/suite/admin/import/test-csv-importer-delegate.php index 366e0523e..17d1ea87c 100644 --- a/tests/suite/admin/import/test-csv-importer-delegate.php +++ b/tests/suite/admin/import/test-csv-importer-delegate.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Import */ -use Brain\Monkey\Functions; - /** * Unit tests for CSV Importer Delegate. */ @@ -122,17 +120,25 @@ private function import_row() { 'ID' => wp_rand() + 1, ]; - Functions\expect( 'get_user_by' ) - ->with( 'login', $this->row_data['username'] ) - ->andReturn( null ); - - Functions\expect( 'get_user_by' ) - ->with( 'id', $user->ID ) - ->andReturn( $user ); - - Functions\when( 'wp_generate_password' )->justReturn( 'a secure password' ); - Functions\when( 'wp_create_user' )->justReturn( $user->ID ); - Functions\when( 'is_wp_error' )->justReturn( false ); + WP_Mock::userFunction( 'get_user_by', [ + 'args' => [ 'login', $this->row_data['username'] ], + 'return' => null + ] ); + + WP_Mock::userFunction( 'get_user_by', [ + 'args' => [ 'id', $user->ID ], + 'return' => $user + ] ); + + WP_Mock::userFunction( 'wp_generate_password', [ + 'return' => 'a secure password' + ] ); + WP_Mock::userFunction( 'wp_create_user', [ + 'return' => $user->ID + ] ); + WP_Mock::userFunction( 'is_wp_error', [ + 'return' => false + ] ); return $this->get_test_subject()->import_row( $this->row_data ); } diff --git a/tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php b/tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php index bf2d8a736..de547a367 100644 --- a/tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php +++ b/tests/suite/admin/listings/test-awaiting-approval-listing-table-view.php @@ -6,8 +6,6 @@ /** * Unit tests for Awaiting Approval listings table view. */ -use Brain\Monkey\Functions; - class AWPCP_AwaitingApprovalListingTableViewTest extends AWPCP_UnitTestCase { /** diff --git a/tests/suite/admin/listings/test-complete-listing-table-view.php b/tests/suite/admin/listings/test-complete-listing-table-view.php index e2e4776ce..963edbe24 100644 --- a/tests/suite/admin/listings/test-complete-listing-table-view.php +++ b/tests/suite/admin/listings/test-complete-listing-table-view.php @@ -6,8 +6,6 @@ /** * Unit tests for Complete Listing Table View. */ -use Brain\Monkey\Functions; - class AWPCP_CompleteListingTableViewTest extends AWPCP_UnitTestCase { /** diff --git a/tests/suite/admin/listings/test-expired-listing-table-view.php b/tests/suite/admin/listings/test-expired-listing-table-view.php index 61e57589b..79480f41b 100644 --- a/tests/suite/admin/listings/test-expired-listing-table-view.php +++ b/tests/suite/admin/listings/test-expired-listing-table-view.php @@ -6,8 +6,6 @@ /** * Unit tests for Expired Listings table view. */ -use Brain\Monkey\Functions; - class AWPCP_ExpiredListingTableViewTest extends AWPCP_UnitTestCase { /** diff --git a/tests/suite/admin/listings/test-listing-fields-metabox.php b/tests/suite/admin/listings/test-listing-fields-metabox.php index dbeca8a44..37ef3b112 100644 --- a/tests/suite/admin/listings/test-listing-fields-metabox.php +++ b/tests/suite/admin/listings/test-listing-fields-metabox.php @@ -3,13 +3,23 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Unit tests for Listing Fields metabox. */ class AWPCP_ListingFieldsMetaboxTest extends AWPCP_UnitTestCase { + private $post; + private $post_type; + private $listings_logic; + private $form_fields_data; + private $form_fields_validator; + private $form_fields; + private $date_form_fields; + private $media_center; + private $template_renderer; + private $wordpress; + private $listing_authorization; + /** * @since 4.0.0 */ @@ -78,17 +88,20 @@ public function test_render() { $this->template_renderer->shouldReceive( 'render_template' ) ->andReturn( $output ); - Functions\expect( 'wp_create_nonce' ) - ->with( 'save-listing-fields-metabox' ) - ->andReturn( 'nonce' ); + WP_Mock::userFunction( 'wp_create_nonce', [ + 'args' => [ 'save-listing-fields-metabox' ], + 'return' => 'nonce', + ] ); - Functions\expect( 'get_post_meta' ) - ->with( $this->post->ID, '__awpcp_admin_editor_validation_errors', true ) - ->andReturn( [] ); + WP_Mock::userFunction( 'get_post_meta', [ + 'args' => [ $this->post->ID, '__awpcp_admin_editor_validation_errors', true ], + 'return' => [], + ] ); - Functions\expect( 'get_post_meta' ) - ->with( $this->post->ID, '__awpcp_admin_editor_save_errors', true ) - ->andReturn( [] ); + WP_Mock::userFunction( 'get_post_meta', [ + 'args' => [ $this->post->ID, '__awpcp_admin_editor_save_errors', true ], + 'return' => [], + ] ); // Verification. $this->expectOutputString( $output ); @@ -124,12 +137,17 @@ private function get_test_subject() { public function test_save( $successful_save, $data, $errors ) { $_POST['awpcp_listing_fields_nonce'] = 'nonce'; - Functions\when( 'sanitize_key' )->returnArg(); - - Functions\expect( 'wp_verify_nonce' ) - ->once() - ->with( 'nonce', 'save-listing-fields-metabox' ) - ->andReturn( true ); + WP_Mock::userFunction( 'sanitize_key', [ + 'return' => function( $arg ) { + return $arg; + }, + ] ); + + WP_Mock::userFunction( 'wp_verify_nonce', [ + 'times' => 1, + 'args' => [ 'nonce', 'save-listing-fields-metabox' ], + 'return' => true, + ] ); $this->form_fields_data->shouldReceive( 'get_posted_data' ) ->andReturn( $data ); diff --git a/tests/suite/admin/listings/test-listing-information-metabox.php b/tests/suite/admin/listings/test-listing-information-metabox.php index 8a0350071..5eb1b33f3 100644 --- a/tests/suite/admin/listings/test-listing-information-metabox.php +++ b/tests/suite/admin/listings/test-listing-information-metabox.php @@ -3,13 +3,17 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Unit testss for Listing Information Metabox class. */ class AWPCP_ListingInformationMetaboxTest extends AWPCP_UnitTestCase { + private $listings_logic; + private $listing_renderer; + private $payments; + private $template_renderer; + private $request; + /** * @since 4.0.0 */ @@ -30,7 +34,9 @@ public function test_render_when_the_listing_has_no_payment_term_associated() { 'post_author' => wp_rand() + 1, ]; - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => true, + ] ); $this->listing_renderer->shouldReceive( [ @@ -86,7 +92,9 @@ public function test_save_when_the_listing_has_no_previous_payment_term() { $transaction->shouldReceive( 'set' ); - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => true, + ] ); $this->request->shouldReceive( 'post' ) ->with( 'payment_term' ) diff --git a/tests/suite/admin/listings/test-listings-table-nav-handler.php b/tests/suite/admin/listings/test-listings-table-nav-handler.php index 1672c48b2..e1abde186 100644 --- a/tests/suite/admin/listings/test-listings-table-nav-handler.php +++ b/tests/suite/admin/listings/test-listings-table-nav-handler.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Unit tests for Listings Table Nav Handler. */ @@ -31,10 +29,16 @@ public function test_pre_get_posts_with_category_filter() { $query->shouldReceive( 'is_main_query' )->andReturn( true ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'awpcp_category_id', 'sanitize' => 'absint' ) ) - ->andReturn( '2' ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'awpcp_category_id', 'sanitize' => 'absint' ] ], + 'return' => '2', + ] ); - Functions\when( 'sanitize_key' )->returnArg(); + WP_Mock::userFunction( 'sanitize_key', [ + 'return' => function( $arg ) { + return $arg; + }, + ] ); $html_renderer->shouldReceive( 'get_selected_category' )->andReturn( 2 ); // Execution. diff --git a/tests/suite/admin/listings/test-make-featured-listing-table-action.php b/tests/suite/admin/listings/test-make-featured-listing-table-action.php index 25dcab076..dc8c4f395 100644 --- a/tests/suite/admin/listings/test-make-featured-listing-table-action.php +++ b/tests/suite/admin/listings/test-make-featured-listing-table-action.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Make Listing Featured table action. */ @@ -78,10 +76,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-make-standard-listing-table-action.php b/tests/suite/admin/listings/test-make-standard-listing-table-action.php index fd2842746..9608b502c 100644 --- a/tests/suite/admin/listings/test-make-standard-listing-table-action.php +++ b/tests/suite/admin/listings/test-make-standard-listing-table-action.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Make Listing Standard table action. */ @@ -72,10 +70,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php b/tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php index 2a1250979..3e2823274 100644 --- a/tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php +++ b/tests/suite/admin/listings/test-mark-as-spam-listing-table-action.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Test for Mark as Spam Listing Table Action. */ @@ -52,7 +50,9 @@ private function get_test_subject() { public function test_should_not_show_action_if_akismet_api_key_is_not_set() { $this->wordpress = Mockery::mock( 'AWPCP_WordPress' ); - Functions\when( 'akismet_init' )->justReturn( null ); + WP_Mock::userFunction( 'akismet_init', [ + 'return' => null, + ] ); $this->wordpress->shouldReceive( 'get_option' ) ->with( 'wordpress_api_key' ) @@ -73,7 +73,9 @@ public function test_should_not_show_action_if_akismet_api_key_is_not_set() { public function test_should_show_action_if_akismet_is_available() { $this->wordpress = Mockery::mock( 'AWPCP_WordPress' ); - Functions\when( 'akismet_init' )->justReturn( null ); + WP_Mock::userFunction( 'akismet_init', [ + 'return' => null, + ] ); $this->wordpress->shouldReceive( 'get_option' ) ->with( 'wordpress_api_key' ) @@ -114,12 +116,12 @@ public function test_get_url() { $action = $this->get_test_subject(); - Functions\when( 'add_query_arg' )->alias( - function( $params, $url ) use ( &$query_parms ) { + WP_Mock::userFunction( 'add_query_arg', [ + 'return' => function( $params, $url ) use ( &$query_parms ) { $query_parms = $params; return $url; - } - ); + }, + ] ); // Execution. $url = $action->get_url( $post, $current_url ); diff --git a/tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php b/tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php index a6542f0f0..d06fabe60 100644 --- a/tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php +++ b/tests/suite/admin/listings/test-mark-reviewed-listing-table-action.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Mark Listing Reviewed table action. */ @@ -72,10 +70,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-moderator-renew-listing-table-action.php b/tests/suite/admin/listings/test-moderator-renew-listing-table-action.php index 911f5545c..c8f66e099 100644 --- a/tests/suite/admin/listings/test-moderator-renew-listing-table-action.php +++ b/tests/suite/admin/listings/test-moderator-renew-listing-table-action.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Renew Listing Table Action class. */ @@ -86,10 +84,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-send-access-key-listing-table-action.php b/tests/suite/admin/listings/test-send-access-key-listing-table-action.php index 3d28ccdc2..22f59ed07 100644 --- a/tests/suite/admin/listings/test-send-access-key-listing-table-action.php +++ b/tests/suite/admin/listings/test-send-access-key-listing-table-action.php @@ -3,13 +3,14 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Send Access Key Listing Table Action. */ class AWPCP_SendAccessKeyListingTableActionTest extends AWPCP_UnitTestCase { + private $email_factory; + private $listing_renderer; + /** * @since 4.0.0 */ @@ -66,10 +67,12 @@ public function test_get_url() { $query_params = null; - Functions\when( 'add_query_arg' )->alias( function( $params, $url ) use ( &$query_params ) { - $query_params = $params; - return $url; - } ); + WP_Mock::userFunction( 'add_query_arg', [ + 'return' => function( $params, $url ) use ( &$query_params ) { + $query_params = $params; + return $url; + }, + ] ); $action = $this->get_test_subject(); @@ -109,8 +112,12 @@ public function test_process_item() { 'send' => true, ] ); - Functions\when( 'awpcp_format_recipient_address' )->justReturn( 'formatted address' ); - Functions\when( 'awpcp_get_edit_listing_url_with_access_key' )->justReturn( 'edit url' ); + WP_Mock::userFunction( 'awpcp_format_recipient_address', [ + 'return' => 'formatted address', + ] ); + WP_Mock::userFunction( 'awpcp_get_edit_listing_url_with_access_key', [ + 'return' => 'edit url', + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php b/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php index b5649aa6e..15fbde3d6 100644 --- a/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php +++ b/tests/suite/admin/listings/test-send-to-facebook-group-listing-table-action.php @@ -3,13 +3,15 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Send to Facebook Group listing admin action. */ class AWPCP_SendToFacebookGroupListingTableActionTest extends AWPCP_UnitTestCase { + private $facebook_helper; + private $roles_and_capabilities; + private $wordpress; + /** * @since 4.0.0 */ @@ -76,10 +78,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php b/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php index 103780552..66184cf62 100644 --- a/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php +++ b/tests/suite/admin/listings/test-send-to-facebook-page-listing-table-action.php @@ -3,13 +3,15 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Send to Facebook Page listing admin action. */ class AWPCP_SendToFacebookPageListingTableActionTest extends AWPCP_UnitTestCase { + private $facebook_helper; + private $roles_and_capabilities; + private $wordpress; + /** * @since 4.0.0 */ @@ -76,10 +78,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/listings/test-unflag-listing-table-action.php b/tests/suite/admin/listings/test-unflag-listing-table-action.php index 864345277..0d05ae9a9 100644 --- a/tests/suite/admin/listings/test-unflag-listing-table-action.php +++ b/tests/suite/admin/listings/test-unflag-listing-table-action.php @@ -3,13 +3,14 @@ * @package AWPCP\Tests\Plugin\Admin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Unflag Listing Table Action. */ class AWPCP_UnflagListingTableActionTest extends AWPCP_UnitTestCase { + private $listings_logic; + private $listing_renderer; + /** * @since 4.0.0 */ @@ -87,10 +88,11 @@ public function test_get_url() { 'ids' => $post->ID, ); - Functions\expect( 'add_query_arg' ) - ->once() - ->with( $params, $current_url ) - ->andReturn( $current_url ); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [ $params, $current_url ], + 'return' => $current_url, + ] ); $action = $this->get_test_subject(); diff --git a/tests/suite/admin/test-admin-container-configuration.php b/tests/suite/admin/test-admin-container-configuration.php index 27a40ae0e..9c86b212b 100644 --- a/tests/suite/admin/test-admin-container-configuration.php +++ b/tests/suite/admin/test-admin-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin */ -use Brain\Monkey\Functions; - /** * Tests for Admin Container Configuration. */ @@ -53,7 +51,9 @@ protected function get_test_subject() { * @since 4.0.0 */ public function test_container_defines_listings_table_views_handler() { - Functions\when( 'awpcp_request' )->justReturn( (object) [] ); + WP_Mock::userFunction( 'awpcp_request', [ + 'return' => (object) [], + ] ); $this->test_class_definition( 'ListingsTableViewsHandler', diff --git a/tests/suite/admin/test-admin.php b/tests/suite/admin/test-admin.php index 973b2839e..65e01f4b0 100644 --- a/tests/suite/admin/test-admin.php +++ b/tests/suite/admin/test-admin.php @@ -10,6 +10,16 @@ */ class AWPCP_AdminTest extends AWPCP_UnitTestCase { + private $post_type; + private $container; + private $views; + private $actions; + private $tablenav; + private $search; + private $columns; + private $restrictions; + private $post; + /** * @since 4.0.0 */ diff --git a/tests/suite/admin/test-filtered-array.php b/tests/suite/admin/test-filtered-array.php index da57da7a7..dc9e67744 100644 --- a/tests/suite/admin/test-filtered-array.php +++ b/tests/suite/admin/test-filtered-array.php @@ -3,8 +3,6 @@ * @package AWPCP\Admin */ -use Brain\Monkey\Filters; - /** * Unit tests for Filtered Array class */ @@ -21,9 +19,8 @@ public function test_actions_can_be_iterated_over() { $table_actions = new AWPCP_FilteredArray( 'awpcp_test_filter' ); - Filters\expectApplied( 'awpcp_test_filter' ) - ->once() - ->andReturn( $actions ); + \WP_Mock::onFilter( 'awpcp_test_filter' ) + ->reply( $actions ); $this->markTestSkipped( 'Failing. Needs work' ); diff --git a/tests/suite/admin/test-list-table-actions-handler.php b/tests/suite/admin/test-list-table-actions-handler.php index 3df73b6d2..6171bbe20 100644 --- a/tests/suite/admin/test-list-table-actions-handler.php +++ b/tests/suite/admin/test-list-table-actions-handler.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Admin */ -use Brain\Monkey\Functions; - /** * Unit tests for List Table Actions Handler class. */ @@ -37,13 +35,14 @@ public function test_admin_head() { $_REQUEST['awpcp-action'] = 'custom-action'; $_REQUEST['awpcp-result'] = 'success~1'; - Functions\expect( 'remove_query_arg' ) - ->zeroOrMoreTimes() - ->with( Mockery::any(), $return_uri ); + WP_Mock::userFunction( 'remove_query_arg', [ + 'args' => [ Mockery::any(), $return_uri ], + ] ); - Functions\expect( 'awpcp_current_user_is_moderator' ) - ->once() - ->andReturn( true ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'times' => 1, + 'return' => true, + ] ); $actions = array( 'custom-action' => $action_handler, @@ -91,12 +90,15 @@ public function test_row_actions_links_returns_defined_actions() { ); $current_url = 'https://example.org'; - Functions\expect( 'add_query_arg' ) - ->once() - ->with( [] ) - ->andReturn( $current_url ); - Functions\when( 'wp_nonce_url' ) - ->justReturn( ''); + WP_Mock::userFunction( 'add_query_arg', [ + 'times' => 1, + 'args' => [], + 'return' => $current_url, + ] ); + + WP_Mock::userFunction( 'wp_nonce_url', [ + 'return' => '', + ] ); $table_actions = new AWPCP_ListTableActionsHandler( $actions, null ); $actions = $table_actions->row_actions_links( array(), $post ); @@ -136,12 +138,12 @@ public function test_handle_action() { 'custom-action' => $action_handler, ); - Functions\when( 'add_query_arg' )->alias( - function( $params, $url ) use ( &$query_params ) { + WP_Mock::userFunction( 'add_query_arg', [ + 'return' => function( $params, $url ) use ( &$query_params ) { $query_params = $params; return $url; - } - ); + }, + ] ); $actions_handler = new AWPCP_ListTableActionsHandler( $actions, diff --git a/tests/suite/admin/test-list-table-search-handler.php b/tests/suite/admin/test-list-table-search-handler.php index 70ce35b12..d8c957a37 100644 --- a/tests/suite/admin/test-list-table-search-handler.php +++ b/tests/suite/admin/test-list-table-search-handler.php @@ -6,10 +6,12 @@ /** * Unit tests for List Table Search Handler. */ -use Brain\Monkey\Functions; - class AWPCP_ListTableSearchHandlerTest extends AWPCP_UnitTestCase { + private $search; + private $html_renderer; + private $request; + /** * @since 4.0.0 */ @@ -33,8 +35,10 @@ public function test_pre_get_posts() { $this->search['title']->shouldReceive( 'pre_get_posts' )->once()->with( $query ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'awpcp_search_by' ) ) - ->andReturn( 'title' ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'awpcp_search_by' ] ], + 'return' => 'title', + ] ); // Execution. $this->get_test_subject()->pre_get_posts( $query ); @@ -74,8 +78,11 @@ private function get_test_subject() { public function test_get_search_query() { $search_term = 'Something'; - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 's' ) ) - ->andReturn( $search_term ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 's' ] ], + 'return' => $search_term, + ] ); + // Execution and Verification. $this->assertEquals( $search_term, $this->get_test_subject()->get_search_query( null ) ); } @@ -95,8 +102,11 @@ public function test_render_search_mode_dropdown() { $this->search[ $search_mode_id ]->shouldReceive( 'get_name' )->andReturn( $search_mode_name ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'awpcp_search_by') ) - ->andReturn( $selected_search_mode_id ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'awpcp_search_by' ] ], + 'return' => $selected_search_mode_id, + ] ); + // Verification. $this->html_renderer->shouldReceive( 'render' )->once()->with( Mockery::on( diff --git a/tests/suite/admin/test-list-table-views-handler.php b/tests/suite/admin/test-list-table-views-handler.php index b69ae8da1..8074ea405 100644 --- a/tests/suite/admin/test-list-table-views-handler.php +++ b/tests/suite/admin/test-list-table-views-handler.php @@ -8,6 +8,9 @@ */ class AWPCP_ListTableViewsHandlerTest extends AWPCP_UnitTestCase { + private $views; + private $request; + /** * @since 4.0.0 */ diff --git a/tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php b/tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php index 7bddd4c4a..1af64f5f3 100644 --- a/tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php +++ b/tests/suite/compatibility/test-indeed-membership-pro-plugin-integration.php @@ -3,13 +3,13 @@ * @package AWPCP\Tests\Compatibility */ -use Brain\Monkey\Functions; - /** * @since 4.0.4 */ class AWPCP_IndeedMemebershipProPluginIntegrationTest extends AWPCP_UnitTestCase { + private $query; + /** * @since 4.0.4 */ @@ -57,8 +57,15 @@ public function test_maybe_dequeue_select2( $times, $expectations ) { $this->query->shouldReceive( $expectations ); - Functions\expect( 'wp_dequeue_style' )->times( $times )->with( 'ihc_select2_style' ); - Functions\expect( 'wp_dequeue_script' )->times( $times )->with( 'ihc-select2' ); + WP_Mock::userFunction( 'wp_dequeue_style', [ + 'times' => $times, + 'args' => [ 'ihc_select2_style' ], + ] ); + + WP_Mock::userFunction( 'wp_dequeue_script', [ + 'times' => $times, + 'args' => [ 'ihc-select2' ], + ] ); // Execution & Verification. $this->get_test_subject()->maybe_dequeue_select2(); diff --git a/tests/suite/form-fields/test-form-fields-data.php b/tests/suite/form-fields/test-form-fields-data.php index 88ef95b13..1aa13f348 100644 --- a/tests/suite/form-fields/test-form-fields-data.php +++ b/tests/suite/form-fields/test-form-fields-data.php @@ -3,26 +3,30 @@ * @package AWPCP\Tests\Suite\FormFields */ -use Brain\Monkey\Filters; -use Brain\Monkey\Functions; - /** * Test for Form Fields Data class. */ class AWPCP_FormFieldsDataTest extends AWPCP_UnitTestCase { + private $authorization; + private $listing_renderer; + /** * @since 4.0.0 */ protected $request; + public function setUp(): void { parent::setUp(); $this->authorization = Mockery::mock( 'AWPCP_ListingAuthorization' ); $this->listing_renderer = Mockery::mock( 'AWPCP_ListingRenderer' ); $this->request = Mockery::mock( 'AWPCP_Request' ); - Functions\when( 'awpcp_maybe_add_http_to_url' )->returnArg(); - Functions\when( 'sanitize_textarea_field' )->returnArg(); + WP_Mock::userFunction( 'awpcp_maybe_add_http_to_url', [ + 'return' => function( $arg ) { + return $arg; + }, + ] ); } /** @@ -40,13 +44,26 @@ public function test_get_posted_data_return_data_for_standard_fields() { $this->listing_renderer->shouldReceive( 'get_plain_end_date' ) ->andReturn( null ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'ad_id' ) )->andReturn( '1' ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'ad_title' ) ) - ->andReturn( 'Test Title' ); - Functions\when( 'awpcp_parse_money' )->justReturn('1'); - Functions\when( 'awpcp_strip_all_tags_deep' )->returnArg(); - Functions\when( 'awpcp_get_digits_from_string' )->returnArg(); - Functions\when( 'current_time' )->justReturn(time()); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'ad_details', 'sanitize' => 'sanitize_textarea_field' ] ], + 'return' => '1', + ] ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'ad_title' ] ], + 'return' => 'Test Title', + ] ); + WP_Mock::userFunction( 'awpcp_parse_money', [ + 'return' => '1', + ] ); + + WP_Mock::userFunction( 'awpcp_get_digits_from_string', [ + 'return' => function( $arg ) { + return strip_tags( $arg ); + }, + ] ); + WP_Mock::userFunction( 'current_time', [ + 'return' => time(), + ] ); $form_fields_data = $this->get_test_subject(); @@ -58,7 +75,7 @@ public function test_get_posted_data_return_data_for_standard_fields() { $this->assertNotEmpty( $data['post_fields']['post_title'] ); $this->markTestSkipped( 'Failing. Needs work' ); - $this->assertTrue( Filters\applied( 'awpcp-get-posted-data' ) > 0 ); + //$this->assertTrue( Brain\Monkey\Filters\applied( 'awpcp-get-posted-data' ) > 0 ); } /** @@ -82,8 +99,6 @@ public function test_get_posted_data_returns_original_date_if_no_value_was_provi $this->request->shouldReceive( 'param' )->andReturn( null ); - Functions\when( 'awpcp_strip_all_tags_deep' )->returnArg(); - $this->authorization ->shouldReceive( 'is_current_user_allowed_to_edit_listing_start_date' ) ->andReturn( true ); @@ -121,23 +136,36 @@ public function test_get_posted_data_keeps_html_in_details_field() { ->shouldReceive( 'is_current_user_allowed_to_edit_listing_end_date' ) ->andReturn( true ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'ad_details', 'sanitize' => 'sanitize_textarea_field' ) ) - ->andReturn( $html_content ); - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'ad_title') ) - ->andReturn( 'ad_title' ); - - Functions\expect( 'awpcp_strip_all_tags_deep' ) - ->once() - ->with( $html_content ) - ->andReturn( strip_tags( $html_content ) );// phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags - - - Functions\expect( 'awpcp_get_var' )->with( array( 'param' => 'ad_item_price') ) - ->andReturn( 150 ); - Functions\expect( 'awpcp_parse_money' )->with(150)->once()->andReturn( 150 ); - - Functions\expect( 'awpcp_get_digits_from_string' ); - Functions\expect( 'current_time' ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ array( 'param' => 'ad_details', 'sanitize' => 'sanitize_textarea_field' ) ], + 'return' => $html_content, + ] ); + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ array( 'param' => 'ad_title') ], + 'return' => 'ad_title', + ] ); + + WP_Mock::userFunction( 'awpcp_strip_all_tags_deep', [ + 'times' => 1, + 'args' => [ $html_content ], + 'return' => function( $arg ) { + return strip_tags( $arg ); + }, + ] ); + + WP_Mock::userFunction( 'awpcp_get_var', [ + 'args' => [ [ 'param' => 'ad_item_price' ] ], + 'return' => 150, + ] ); + + WP_Mock::userFunction( 'awpcp_parse_money', [ + 'times' => 1, + 'args' => [ 150 ], + 'return' => '150', + ] ); + + WP_Mock::userFunction( 'awpcp_get_digits_from_string' ); + WP_Mock::userFunction( 'current_time' ); $this->listing_renderer->shouldReceive( 'get_plain_start_date' ) ->andReturn( '' ); $this->listing_renderer->shouldReceive( 'get_plain_end_date' ) diff --git a/tests/suite/form-fields/test-form-fields-validator.php b/tests/suite/form-fields/test-form-fields-validator.php index 6b8db5a7d..925b7091e 100644 --- a/tests/suite/form-fields/test-form-fields-validator.php +++ b/tests/suite/form-fields/test-form-fields-validator.php @@ -3,14 +3,16 @@ * @package AWPCP\Tests\Plugin\FormFields */ -use Brain\Monkey\Filters; -use Brain\Monkey\Functions; - /** * Unit tests for Form Fields Data Validator. */ class AWPCP_FormFieldsDataValidatorTest extends AWPCP_UnitTestCase { + private $authorization; + private $roles; + private $settings; + private $data; + /** * @since 4.0.0 */ @@ -33,7 +35,9 @@ public function setUp(): void { 'terms_of_service' => 'accepted', ); - Functions\when( 'awpcp_is_email_address_allowed' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_is_email_address_allowed', [ + 'return' => true, + ] ); } /** @@ -43,7 +47,7 @@ public function test_get_validation_errors_applies_filter() { $this->get_validation_errors(); $this->markTestSkipped( 'Failing. Needs work' ); - $this->assertTrue( Filters\applied( 'awpcp-validate-post-listing-details' ) > 0 ); + //$this->assertTrue( Brain\Monkey\Filters\applied( 'awpcp-validate-post-listing-details' ) > 0 ); } /** @@ -158,7 +162,9 @@ public function test_contact_email_must_be_a_valid_email_address() { * @since 4.0.0 */ public function test_contact_email_must_be_one_of_the_allowed_addresses() { - Functions\when( 'awpcp_is_email_address_allowed' )->justReturn( false ); + WP_Mock::userFunction( 'awpcp_is_email_address_allowed', [ + 'return' => false, + ] ); $this->check_metadata_error( '_awpcp_contact_email', 'not@allowed.address.test', 'ad_contact_email' ); } diff --git a/tests/suite/form-fields/test-listing-form-fields.php b/tests/suite/form-fields/test-listing-form-fields.php index 552975718..9e869fe05 100644 --- a/tests/suite/form-fields/test-listing-form-fields.php +++ b/tests/suite/form-fields/test-listing-form-fields.php @@ -8,6 +8,8 @@ */ class AWPCP_ListingFormFieldsTest extends AWPCP_UnitTestCase { + private $authorization; + /** * @since 4.0.2 */ diff --git a/tests/suite/form-fields/test-terms-of-service-form-field.php b/tests/suite/form-fields/test-terms-of-service-form-field.php index 83ae7a6e7..bdb314566 100644 --- a/tests/suite/form-fields/test-terms-of-service-form-field.php +++ b/tests/suite/form-fields/test-terms-of-service-form-field.php @@ -8,6 +8,10 @@ */ class AWPCP_TermsOfServiceFormFieldTest extends AWPCP_UnitTestCase { + private $roles; + private $settings; + private $template_renderer; + /** * @since 4.0.2 */ diff --git a/tests/suite/frontend/test-edit-listing-page.php b/tests/suite/frontend/test-edit-listing-page.php index 835c28c99..4f10358ee 100644 --- a/tests/suite/frontend/test-edit-listing-page.php +++ b/tests/suite/frontend/test-edit-listing-page.php @@ -5,8 +5,6 @@ * @package AnotherWordPressClassifiedsPlugin */ -use Brain\Monkey\Functions; - /** * Tests for Edit Listing Page class. */ @@ -204,7 +202,9 @@ public function test_do_send_access_key_step() { ], ]; - Functions\when( 'awpcp' )->justReturn( $awpcp ); + WP_Mock::userFunction( 'awpcp', [ + 'return' => $awpcp, + ] ); $email_address = 'john@example.org'; @@ -216,9 +216,10 @@ public function test_do_send_access_key_step() { ->with( 'attempts', 0 ) ->andReturn( 3 ); // A number greater or equal than 1. - Functions\expect( 'is_email' ) - ->with( $email_address ) - ->andReturn( true ); + WP_Mock::userFunction( 'is_email', [ + 'args' => [ $email_address ], + 'return' => true, + ] ); $query_vars_matcher = function( $query_vars ) use ( $email_address ) { if ( ! isset( $query_vars['meta_query'][0]['value'] ) ) { diff --git a/tests/suite/frontend/test-frontend-container-configuration.php b/tests/suite/frontend/test-frontend-container-configuration.php index f8434e3a6..5800ce392 100644 --- a/tests/suite/frontend/test-frontend-container-configuration.php +++ b/tests/suite/frontend/test-frontend-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Frontend */ -use Brain\Monkey\Functions; - /** * Tests for main Container Configuration class. */ @@ -23,7 +21,9 @@ public function setUp(): void { ], ]; - Functions\when( 'awpcp' )->justReturn( $awpcp ); + WP_Mock::userFunction( 'awpcp', [ + 'return' => $awpcp, + ] ); } /** diff --git a/tests/suite/frontend/test-query.php b/tests/suite/frontend/test-query.php index b87b6f6d1..abd88b728 100644 --- a/tests/suite/frontend/test-query.php +++ b/tests/suite/frontend/test-query.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Frontend */ -use Brain\Monkey\Functions; - class AWPCP_Test_Query extends AWPCP_UnitTestCase { /** @@ -110,9 +108,10 @@ public function test_is_search_listings_page() { $wp_the_query->shouldReceive( 'is_page' )->andReturn( true ); $wp_the_query->shouldReceive( 'get_queried_object' )->andReturn( $page ); - Functions\expect( 'has_shortcode' ) - ->with( $page->post_content, 'AWPCPSEARCHADS' ) - ->andReturn( true ); + WP_Mock::userFunction( 'has_shortcode', [ + 'args' => [ $page->post_content, 'AWPCPSEARCHADS' ], + 'return' => true, + ] ); // Verification. $this->assertTrue( $this->get_test_subject()->is_search_listings_page() ); diff --git a/tests/suite/frontend/test-submit-listing-form-steps.php b/tests/suite/frontend/test-submit-listing-form-steps.php index 8c002c1fd..f5bf5dcbe 100644 --- a/tests/suite/frontend/test-submit-listing-form-steps.php +++ b/tests/suite/frontend/test-submit-listing-form-steps.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Frontend */ -use Brain\Monkey\Functions; - /** * Unit tests for Listing Form Steps Component class. */ diff --git a/tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php b/tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php index c5b1b82c7..f171b1aa1 100644 --- a/tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php +++ b/tests/suite/frontend/test-url-backwards-compatiblity-redirection-helper.php @@ -3,8 +3,6 @@ * @package AWPCP\Test\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for URL Backwards Compatiblity Redirection Helper class. * @@ -41,19 +39,23 @@ public function test_url_redirection_when_rewrite_rule_includes_pagename() { ->with( 'show-listing-page' ) ->andReturn( rand() + 1 ); - Functions\when( 'get_page_uri' )->justReturn( $single_listing_page_uri ); + WP_Mock::userFunction( 'get_page_uri', [ + 'return' => $single_listing_page_uri, + ] ); - Functions\expect( 'get_permalink' ) - ->once() - ->with( $listing ) - ->andReturn( $listing_permalink ); + WP_Mock::userFunction( 'get_permalink', [ + 'times' => 1, + 'args' => [ $listing ], + 'return' => $listing_permalink, + ] ); $helper = new AWPCP_URL_Backwards_Compatibility_Redirection_Helper( null, null, null, $listings, null, $settings ); - Functions\expect( 'wp_redirect' ) - ->once() - ->with( $listing_permalink, 301 ) - ->andReturn( false ); // To prevent exit() from being called. + WP_Mock::userFunction( 'wp_redirect', [ + 'times' => 1, + 'args' => [ $listing_permalink, 301 ], + 'return' => false, // To prevent exit() from being called. + ] ); // Execution. $helper->maybe_redirect_from_old_listing_url( $query ); diff --git a/tests/suite/functions/test-pagination-functions.php b/tests/suite/functions/test-pagination-functions.php index c05846062..94b4784e1 100644 --- a/tests/suite/functions/test-pagination-functions.php +++ b/tests/suite/functions/test-pagination-functions.php @@ -3,8 +3,6 @@ * @package AWPCP\Test\Functions */ -use Brain\Monkey\Functions; - /** * Unit tests for functions involved in generating pagination controls. */ @@ -13,9 +11,15 @@ class AWPCP_Test_Pagination_Functions extends AWPCP_UnitTestCase { public function test_pagination_forms_keep_page_id_url_parameter() { $_GET['page_id'] = wp_rand(); - Functions\when( 'is_admin' )->justReturn( false ); - Functions\when( 'get_awpcp_option' )->justReturn( 0 ); - Functions\when( 'awpcp_pagination_options' )->justReturn( [ 10, 20 ] ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => false, + ] ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => 0, + ] ); + WP_Mock::userFunction( 'awpcp_pagination_options', [ + 'return' => [ 10, 20 ], + ] ); $pagination_form = awpcp_pagination( array(), '' ); @@ -32,8 +36,12 @@ public function test_get_results_per_page() { 'results' => 3, ]; - Functions\when( 'awpcp_request_param' )->justReturn( 4 ); - Functions\when( 'get_awpcp_option' )->justReturn( 5 ); + WP_Mock::userFunction( 'awpcp_request_param', [ + 'return' => 4, + ] ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => 5, + ] ); $this->assertEquals( 1, awpcp_get_results_per_page( $query_vars ) ); @@ -49,11 +57,19 @@ public function test_get_results_per_page() { $this->assertEquals( 4, awpcp_get_results_per_page( $query_vars ) ); - Functions\when( 'awpcp_request_param' )->returnArg( 2 ); + WP_Mock::userFunction( 'awpcp_request_param', [ + 'return' => function( $param, $default ) { + return $default; + }, + ] ); $this->assertEquals( 5, awpcp_get_results_per_page( $query_vars ) ); - Functions\when( 'get_awpcp_option' )->returnArg( 2 ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => function( $param, $default ) { + return $default; + }, + ] ); $this->assertEquals( 10, awpcp_get_results_per_page( $query_vars ) ); } @@ -69,25 +85,30 @@ public function test_get_results_offset() { 'offset' => 1, ]; - Functions\expect( 'awpcp_request_param' ) - ->with( 'offset', 15 ) - ->andReturn( 15 ); - - Functions\expect( 'awpcp_request_param' ) - ->with( 'offset', 20 ) - ->andReturn( 20 ); - - Functions\expect( 'awpcp_request_param' ) - ->with( 'offset', Mockery::any() ) - ->andReturn( 3 ); - - Functions\expect( 'get_query_var' ) - ->with( 'page' ) - ->andReturn( 5 ); - - Functions\expect( 'get_query_var' ) - ->with( 'paged' ) - ->andReturnValues( [ wp_rand(), wp_rand(), wp_rand(), 4, 0 ] ); + WP_Mock::userFunction( 'awpcp_request_param', [ + 'args' => [ 'offset', 15 ], + 'return' => 15, + ] ); + + WP_Mock::userFunction( 'awpcp_request_param', [ + 'args' => [ 'offset', 20 ], + 'return' => 20, + ] ); + + WP_Mock::userFunction( 'awpcp_request_param', [ + 'args' => [ 'offset', Mockery::any() ], + 'return' => 3, + ] ); + + WP_Mock::userFunction( 'get_query_var', [ + 'args' => [ 'page' ], + 'return' => 5, + ] ); + + WP_Mock::userFunction( 'get_query_var', [ + 'args' => [ 'paged' ], + 'return' => [ wp_rand(), wp_rand(), wp_rand(), 4, 0 ] + ] ); $this->assertEquals( 1, awpcp_get_results_offset( $results_per_page, $query_vars ) ); diff --git a/tests/suite/functions/test-routes-functions.php b/tests/suite/functions/test-routes-functions.php index 089da6121..0b37fa1f1 100644 --- a/tests/suite/functions/test-routes-functions.php +++ b/tests/suite/functions/test-routes-functions.php @@ -1,7 +1,5 @@ settings->set_or_update_option( 'requireuserregistration', true ); - Functions::expect( 'awpcp_get_edit_listing_direct_url' )->once()->with( $listing ); + WP_Mock::userFunction( 'awpcp_get_edit_listing_direct_url', [ + 'times' => 1, + 'args' => [ $listing ], + ] ); /* Execution */ awpcp_get_edit_listing_url( $listing ); @@ -74,7 +75,9 @@ public function test_get_edit_listing_url_for_non_privileged_users_when_registra awpcp()->settings->set_or_update_option( 'requireuserregistration', false ); - Functions::expect( 'awpcp_get_edit_listing_generic_url' )->once()->withNoArgs(); + WP_Mock::userFunction( 'awpcp_get_edit_listing_generic_url', [ + 'times' => 1, + ] ); /* Execution */ awpcp_get_edit_listing_url( $listing ); @@ -86,7 +89,10 @@ public function test_get_edit_listing_url_for_non_privileged_users_when_registra public function test_get_edit_listing_direct_url_when_user_panel_is_off() { $listing = awpcp_tests_create_listing(); - Functions::expect( 'awpcp_get_edit_listing_page_url_with_listing_id' )->once()->with( $listing ); + WP_Mock::userFunction( 'awpcp_get_edit_listing_page_url_with_listing_id', [ + 'times' => 1, + 'args' => [ $listing ], + ] ); /* Execution */ $url = awpcp_get_edit_listing_direct_url( $listing ); @@ -98,12 +104,26 @@ public function test_get_edit_listing_direct_url_when_user_panel_is_off() { public function test_get_edit_listing_page_url_with_listing_id_when_firendly_urls_are_enabled() { $listing = awpcp_tests_create_listing(); - Functions::when( 'awpcp_get_page_id_by_ref' )->justReturn( rand() + 1 ); - Functions::when( 'get_permalink' )->justReturn( 'http://example.org/%pagename%/' ); - Functions::when( 'get_page_uri' )->justReturn( 'plugin-page' ); - - Functions::expect( 'get_awpcp_option' )->once()->with( 'seofriendlyurls' )->andReturn( true ); - Functions::expect( 'get_option' )->once()->with( 'permalink_structure' )->andReturn( '/%postname%/' ); + WP_Mock::userFunction( 'awpcp_get_page_id_by_ref', [ + 'return' => rand() + 1, + ] ); + WP_Mock::userFunction( 'get_permalink', [ + 'return' => 'http://example.org/%pagename%/', + ] ); + WP_Mock::userFunction( 'get_page_uri', [ + 'return' => 'plugin-page', + ] ); + + WP_Mock::userFunction( 'get_awpcp_option', [ + 'times' => 1, + 'args' => [ 'seofriendlyurls' ], + 'return' => true, + ] ); + WP_Mock::userFunction( 'get_option', [ + 'times' => 1, + 'args' => [ 'permalink_structure' ], + 'return' => '/%postname%/', + ] ); /* Execution */ $url = awpcp_get_edit_listing_page_url_with_listing_id( $listing ); @@ -115,9 +135,15 @@ public function test_get_edit_listing_page_url_with_listing_id_when_firendly_url public function test_get_edit_listing_page_url_with_listing_id_when_firendly_urls_are_disabled() { $listing = awpcp_tests_create_listing(); - Functions::when( 'awpcp_get_page_url' )->justReturn( 'http://example.org/plugin-page/' ); + WP_Mock::userFunction( 'awpcp_get_page_url', [ + 'return' => 'http://example.org/plugin-page/', + ] ); - Functions::expect( 'get_awpcp_option' )->once()->with( 'seofriendlyurls' )->andReturn( false ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'times' => 1, + 'args' => [ 'seofriendlyurls' ], + 'return' => false, + ] ); /* Execution */ $url = awpcp_get_edit_listing_page_url_with_listing_id( $listing ); diff --git a/tests/suite/includes/categories/test-category-presenter.php b/tests/suite/includes/categories/test-category-presenter.php index 600c503ec..c5a97bc84 100644 --- a/tests/suite/includes/categories/test-category-presenter.php +++ b/tests/suite/includes/categories/test-category-presenter.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Categories */ -use Brain\Monkey\Functions; - /** * @since 4.0.0 */ @@ -22,9 +20,10 @@ public function setUp(): void { * @since 4.0.0 */ public function test_get_full_name_from_meta( $category, $full_name, $stored_name, $categories ) { - Functions\expect( 'get_term_meta' ) - ->with( $category->term_id, '_awpcp_full_name', true ) - ->andReturn( $stored_name ); + WP_Mock::userFunction( 'get_term_meta', [ + 'args' => [ $category->term_id, '_awpcp_full_name', true ], + 'return' => $stored_name, + ] ); foreach ( $categories as $c ) { $this->categories_collection->shouldReceive( 'get' ) diff --git a/tests/suite/includes/frontend/test-image-placeholders.php b/tests/suite/includes/frontend/test-image-placeholders.php index da9465249..22464599a 100644 --- a/tests/suite/includes/frontend/test-image-placeholders.php +++ b/tests/suite/includes/frontend/test-image-placeholders.php @@ -5,8 +5,6 @@ * @package AWPCP\Tests\Frontend */ -use Brain\Monkey\Functions; - /** * @since 4.0.1 */ @@ -43,17 +41,21 @@ public function test_hide_no_image_placeholders_setting( $placeholder ) { $this->attachments_collection->shouldReceive( 'count_attachments_of_type' ) ->andReturn( 0 ); - Functions\expect( 'get_awpcp_option' ) - ->once() - ->with( 'displayadthumbwidth' ) - ->andReturn( wp_rand() ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'times' => 1, + 'args' => 'displayadthumbwidth', + 'return' => wp_rand(), + ] ); - Functions\expect( 'get_awpcp_option' ) - ->once() - ->with( 'hide-noimage-placeholder', 1 ) - ->andReturn( true ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'times' => 1, + 'args' => [ 'hide-noimage-placeholder', 1 ], + 'return' => true, + ] ); - Functions\when( 'awpcp_are_images_allowed' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_are_images_allowed', [ + 'return' => true, + ] ); $output = $this->get_test_subject()->do_image_placeholders( $listing, diff --git a/tests/suite/includes/frontend/test-pages.php b/tests/suite/includes/frontend/test-pages.php index 31973e5f6..071eb4b46 100644 --- a/tests/suite/includes/frontend/test-pages.php +++ b/tests/suite/includes/frontend/test-pages.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Frontend */ -use Brain\Monkey\Functions; - /** * @since 4.0.0 */ diff --git a/tests/suite/includes/frontend/test-show-listing-page.php b/tests/suite/includes/frontend/test-show-listing-page.php index 9e352d2ca..547d4b6d6 100644 --- a/tests/suite/includes/frontend/test-show-listing-page.php +++ b/tests/suite/includes/frontend/test-show-listing-page.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Frontend */ -use Brain\Monkey\Functions; - /** * @group core */ @@ -44,7 +42,9 @@ public function test_dispatch() { ->once() ->andReturn( 'some-content' ); - Functions\when( 'get_awpcp_option' )->justReturn( true ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => true, + ] ); $content = $this->get_test_subject()->dispatch(); diff --git a/tests/suite/includes/frontend/test-user-listings-shortcode.php b/tests/suite/includes/frontend/test-user-listings-shortcode.php index cf54abd85..96f0d66c4 100644 --- a/tests/suite/includes/frontend/test-user-listings-shortcode.php +++ b/tests/suite/includes/frontend/test-user-listings-shortcode.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Frontend */ -use Brain\Monkey\Functions; - /** * Unit tests for the AWPCPUSERLISTINGS shortcode. */ @@ -23,16 +21,24 @@ public function test_shortcode_attrs( $attrs, $query, $options, $current_user_id $this->redefine( 'awpcp_browse_listings_page', Patchwork\always( (object) [] ) ); - Functions\when( 'get_awpcp_option' )->justReturn( true ); - Functions\when( 'is_user_logged_in' )->justReturn( true ); - Functions\when( 'wp_enqueue_script' )->justReturn(); - Functions\when( 'get_current_user_id' )->justReturn( $current_user_id ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'is_user_logged_in', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'wp_enqueue_script', [ + 'return' => '', + ] ); + WP_Mock::userFunction( 'get_current_user_id', [ + 'return' => $current_user_id, + ] ); $arguments = []; - Functions\expect( 'awpcp_display_listings' ) - ->once() - ->withArgs( + WP_Mock::userFunction( 'awpcp_display_listings', [ + 'times' => 1, + 'args' => [ function( $query, $context, $options ) use ( &$arguments ) { if ( $context !== 'user-listings-shortcode' ) { return false; @@ -43,8 +49,9 @@ function( $query, $context, $options ) use ( &$arguments ) { $arguments['options'] = $options; return true; - } - ); + }, + ], + ] ); $pages = new AWPCP_Pages( $container ); diff --git a/tests/suite/includes/functions/test-listings-functions.php b/tests/suite/includes/functions/test-listings-functions.php index 3f9e1b65f..d4534a4d9 100644 --- a/tests/suite/includes/functions/test-listings-functions.php +++ b/tests/suite/includes/functions/test-listings-functions.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Functions */ -use Brain\Monkey\Functions; - class AWPCP_Test_Listings_Functions extends AWPCP_UnitTestCase { public function test_display_listings() { @@ -24,8 +22,12 @@ public function test_render_classifieds_bar( $is_admin, $expected_output ) { $classifieds_bar->shouldReceive( 'render' )->andReturn( 'classifieds-bar' ); - Functions\when( 'awpcp_classifieds_bar' )->justReturn( $classifieds_bar ); - Functions\when( 'is_admin' )->justReturn( $is_admin ); + WP_Mock::userFunction( 'awpcp_classifieds_bar', [ + 'return' => $classifieds_bar, + ] ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => $is_admin, + ] ); // Execution. $output = awpcp_render_classifieds_bar(); @@ -54,8 +56,12 @@ public function test_get_results_per_page( $results_per_page, $query_vars, $quer $query_parameter = $default; } - Functions\when( 'awpcp_request_param' )->justReturn( $query_parameter ); - Functions\when( 'get_awpcp_option' )->justReturn( $default ); + WP_Mock::userFunction( 'awpcp_request_param', [ + 'return' => $query_parameter, + ] ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'return' => $default, + ] ); $this->assertEquals( $results_per_page, awpcp_get_results_per_page( $query_vars ) ); } diff --git a/tests/suite/includes/helpers/test-facebook-integration.php b/tests/suite/includes/helpers/test-facebook-integration.php index f7babe1b1..9308b39b7 100644 --- a/tests/suite/includes/helpers/test-facebook-integration.php +++ b/tests/suite/includes/helpers/test-facebook-integration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests */ -use Brain\Monkey\Functions; - class AWPCP_TestSendListingToFacebookHelper extends AWPCP_UnitTestCase { public function setUp(): void { @@ -33,7 +31,9 @@ public function test_schedule_listing_if_necessary() { Phake::when( $this->wordpress )->current_time->thenReturn( $current_time ); - Functions\when( 'wp_next_scheduled' )->justReturn( false ); + WP_Mock::userFunction( 'wp_next_scheduled', [ + 'return' => false, + ] ); $this->get_test_subject()->maybe_schedelue_send_to_facebook_action( $listing ); diff --git a/tests/suite/includes/helpers/test-request.php b/tests/suite/includes/helpers/test-request.php index 76151fa7e..1ad6ae4d0 100644 --- a/tests/suite/includes/helpers/test-request.php +++ b/tests/suite/includes/helpers/test-request.php @@ -5,8 +5,6 @@ * @package AWPCP\Tests\Helpers */ -use Brain\Monkey\Functions; - /** * @group core */ @@ -123,7 +121,10 @@ public function test_post() { * @dataProvider get_query_var_data_provider */ public function test_get_query_var( $name, $real_value, $expected_value, $default = '' ) { - Functions\expect( 'get_query_var' )->with( $name )->andReturn( $real_value ); + WP_Mock::userFunction( 'get_query_var', [ + 'args' => [ $name ], + 'return' => $real_value, + ] ); $returned_value = $this->get_test_subject()->get_query_var( $name, $default ); @@ -184,7 +185,10 @@ public function test_get_category_id_from_request() { } public function test_get_category_id_from_query_var() { - Functions\expect( 'get_query_var' )->with( 'cid' )->andReturn( 13 ); + WP_Mock::userFunction( 'get_query_var', [ + 'args' => [ 'cid' ], + 'return' => 13, + ] ); $request = new AWPCP_Request(); @@ -192,7 +196,9 @@ public function test_get_category_id_from_query_var() { } public function test_get_current_listing_from_request() { - Functions\when( 'get_query_var' )->justReturn( false ); + WP_Mock::userFunction( 'get_query_var', [ + 'return' => false, + ] ); $request = new AWPCP_Request(); diff --git a/tests/suite/includes/listings/test-listings-content-renderer.php b/tests/suite/includes/listings/test-listings-content-renderer.php index d96a248e6..e42ee0e94 100644 --- a/tests/suite/includes/listings/test-listings-content-renderer.php +++ b/tests/suite/includes/listings/test-listings-content-renderer.php @@ -3,9 +3,6 @@ * @package AWPCP\Tests\Listings */ -use Brain\Monkey\Functions; -use Brain\Monkey\Filters; - /** * @since 4.0.0 */ @@ -36,23 +33,36 @@ public function test_render_content_without_notices() { $content_with_percentage_character = 'Content including % character.'; - Functions\when( 'awpcp' )->justReturn( $awpcp ); - Functions\when( 'awpcp_maybe_add_thickbox' )->justReturn( null ); - Functions\when( 'awpcp_maybe_enqueue_font_awesome_style' )->justReturn( null ); - Functions\when( 'wp_create_nonce' )->justReturn( '' ); - Functions\when( 'wp_enqueue_script' )->justReturn( null ); - Functions\when( 'awpcp_get_listing_single_view_layout' )->justReturn( '' ); - Functions\when( 'awpcp_do_placeholders' )->justReturn( '' ); + WP_Mock::userFunction( 'awpcp', [ + 'return' => $awpcp, + ] ); + WP_Mock::userFunction( 'awpcp_maybe_add_thickbox', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_maybe_enqueue_font_awesome_style', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'wp_create_nonce', [ + 'return' => '', + ] ); + WP_Mock::userFunction( 'wp_enqueue_script', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_get_listing_single_view_layout', [ + 'return' => '', + ] ); + WP_Mock::userFunction( 'awpcp_do_placeholders', [ + 'return' => '', + ] ); + + $this->markTestSkipped( 'Failing. Needs work' ); - Filters\expectApplied( 'awpcp-content-before-listing-page' ) - ->once() - ->andReturn( $content_with_percentage_character ); + \WP_Mock::onFilter( 'awpcp-content-before-listing-page' ) + ->reply( $content_with_percentage_character ); $awpcp->js->shouldReceive( 'set' ); $awpcp->js->shouldReceive( 'localize' ); - $this->markTestSkipped( 'Failing. Needs work' ); - $output = $this->get_test_subject()->render_content_without_notices( $listing->post_content, $listing ); $this->assertContains( $content_with_percentage_character, $output ); diff --git a/tests/suite/includes/listings/test-listings-permalinks.php b/tests/suite/includes/listings/test-listings-permalinks.php index 512963335..242d0111a 100644 --- a/tests/suite/includes/listings/test-listings-permalinks.php +++ b/tests/suite/includes/listings/test-listings-permalinks.php @@ -3,8 +3,6 @@ * @package \AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Test cases for Listings Permalinks class. * @@ -26,10 +24,11 @@ public function test_filter_post_type_link_returns_proper_urls_when_friendly_url ->with( 'seofriendlyurls' ) ->andReturn( false ); - Functions\expect( 'get_option' ) - ->once() - ->with( 'permalink_structure' ) - ->andReturn( 'something' ); + WP_Mock::userFunction( 'get_option', array( + 'times' => 1, + 'args' => array( 'permalink_structure' ), + 'return' => 'something', + ) ); $listings_permalinks = new AWPCP_ListingsPermalinks( $post_type, null, null, $settings ); @@ -51,10 +50,10 @@ public function test_filter_post_type_link_returns_proper_urls_when_friendly_url } public function test_get_post_type_permastruct_includes_location_placeholder() { - Functions\expect( 'get_option' ) - ->zeroOrMoreTimes() - ->with( 'permalink_structure' ) - ->andReturn( 'something' ); + WP_Mock::userFunction( 'get_option', array( + 'args' => array( 'permalink_structure' ), + 'return' => 'something', + ) ); // Execution & Verification $this->check_placeholder_is_inclued_when_setting_is_enabled( 'include-country-in-listing-url' ); diff --git a/tests/suite/includes/media/test-image-attachment-creator.php b/tests/suite/includes/media/test-image-attachment-creator.php index d6d7fe24b..c2160958b 100644 --- a/tests/suite/includes/media/test-image-attachment-creator.php +++ b/tests/suite/includes/media/test-image-attachment-creator.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Media */ -use Brain\Monkey\Functions; - /** * Unit tests for Image Attachment Creator. */ @@ -27,7 +25,9 @@ public function setUp(): void { * @since unknown */ public function test_create_attachment_as_moderator() { - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( true ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => true, + ] ); $this->verify_create_attachment( AWPCP_Attachment_Status::STATUS_APPROVED ); } @@ -76,7 +76,9 @@ private function get_test_subject() { * @since unknown */ public function test_create_attachment_as_subscriber_when_imagesapprove_is_enabled() { - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( false ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => false, + ] ); Phake::when( $this->settings )->get_option( 'imagesapprove' )->thenReturn( true ); @@ -103,7 +105,9 @@ public function test_create_attachment_marks_listings_as_having_images_awaiting_ ->once() ->with( $post ); - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( false ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => false, + ] ); Phake::when( $this->settings )->get_option( 'imagesapprove' )->thenReturn( true ); Phake::when( $this->attachments_creator )->create_attachment->thenReturn( $attachment ); diff --git a/tests/suite/includes/media/test-image-renderer.php b/tests/suite/includes/media/test-image-renderer.php index 5fb95506c..5cf5e5138 100644 --- a/tests/suite/includes/media/test-image-renderer.php +++ b/tests/suite/includes/media/test-image-renderer.php @@ -3,9 +3,6 @@ * @package AWPCP\Tests\Media */ -use Brain\Monkey\Functions; - - /** * @since 4.0.0 */ @@ -37,16 +34,17 @@ public function test_render_attachment_thumbnail( $thumbnails_per_row, $thumbnai ->with( 'display-thumbnails-in-columns' ) ->andReturn( $thumbnails_per_row ); - Functions\when( 'wp_get_additional_image_sizes' )->justReturn( $image_sizes ); + WP_Mock::userFunction( 'wp_get_additional_image_sizes', [ + 'return' => $image_sizes, + ] ); - Functions\expect( 'wp_get_attachment_image' ) - ->once() - ->andReturnUsing( - function( $attachment_id, $size, $icon, $attributes ) use ( $sizes, $default_size ) { - $this->assertContains( $sizes, $attributes['sizes'] ); - $this->assertContains( $default_size, $attributes['sizes'] ); - } - ); + WP_Mock::userFunction( 'wp_get_attachment_image', [ + 'times' => 1, + 'return' => function( $attachment_id, $size, $icon, $attributes ) use ( $sizes, $default_size ) { + $this->assertContains( $sizes, $attributes['sizes'] ); + $this->assertContains( $default_size, $attributes['sizes'] ); + } + ] ); // Execution. $this->get_test_subject()->render_attachment_thumbnail( wp_rand() ); diff --git a/tests/suite/includes/media/test-media-container-configuration.php b/tests/suite/includes/media/test-media-container-configuration.php index c23ebfc08..ebc50f646 100644 --- a/tests/suite/includes/media/test-media-container-configuration.php +++ b/tests/suite/includes/media/test-media-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Media */ -use Brain\Monkey\Functions; - /** * Test for Media Container Configuration. */ @@ -18,10 +16,18 @@ public function setUp(): void { // Constructors functions still required by the constructors of the // classes registered in this container. - Functions\when( 'awpcp_file_types' )->justReturn( null ); - Functions\when( 'awpcp_image_file_validator' )->justReturn( null ); - Functions\when( 'awpcp_image_file_processor' )->justReturn( null ); - Functions\when( 'awpcp_image_attachment_creator' )->justReturn( null ); + WP_Mock::userFunction( 'awpcp_file_types', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_image_file_validator', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_image_file_processor', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_image_attachment_creator', [ + 'return' => null, + ] ); } /** diff --git a/tests/suite/includes/media/test-media-uploaded-notification.php b/tests/suite/includes/media/test-media-uploaded-notification.php index 6c977a811..2505bf630 100644 --- a/tests/suite/includes/media/test-media-uploaded-notification.php +++ b/tests/suite/includes/media/test-media-uploaded-notification.php @@ -1,7 +1,5 @@ listings )->get( $listing->ID )->thenReturn( $listing ); Phake::when( $this->attachments )->get( $attachment->ID )->thenReturn( $attachment ); - Functions::expect( 'get_option' ) - ->once() - ->with( "awpcp-media-uploaded-notification-files-{$listing->ID}", array() ) - ->andReturn( array( + WP_Mock::userFunction( 'get_option', [ + 'times' => 1, + 'args' => array( "awpcp-media-uploaded-notification-files-{$listing->ID}", array() ), + 'return' => array( array( 'id' => $attachment->ID ), - ) ); - - Functions::when( 'awpcp_admin_email_to' )->justReturn( 'admin@example.org' ); - Functions::when( 'awpcp_get_admin_listings_url' )->justReturn( 'http://example.org/wp-admin/admin.php?page=awpcp-admin-listings' ); - Functions::when( 'awpcp_get_blog_name' )->justReturn( 'Test Blog' ); - Functions::when( 'home_url' )->justReturn( 'http://example.org' ); + ), + ]); + + WP_Mock::userFunction( 'awpcp_admin_email_to', [ + 'return' => 'admin@example.org', + ] ); + WP_Mock::userFunction( 'awpcp_get_admin_listings_url', [ + 'return' => 'http://example.org/wp-admin/admin.php?page=awpcp-admin-listings', + ] ); + WP_Mock::userFunction( 'awpcp_get_blog_name', [ + 'return' => 'Test Blog', + ] ); + WP_Mock::userFunction( 'home_url', [ + 'return' => 'http://example.org', + ] ); redefine( 'AWPCP_Email::prepare', function( $template, $params ) use ( &$other_attachments ) { $other_attachments = $params['other_attachments']; diff --git a/tests/suite/includes/test-awpcp.php b/tests/suite/includes/test-awpcp.php index cdada77b4..6dfa28837 100644 --- a/tests/suite/includes/test-awpcp.php +++ b/tests/suite/includes/test-awpcp.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests */ -use Brain\Monkey\Functions; - /** * Unit tests for the plugin's main class. */ @@ -69,10 +67,16 @@ public function test_init_register_listing_payment_transaction_handler_hooks_on_ $this->container['SendListingToFacebookHelper'] = Mockery::mock( 'AWPCP_SendToFacebookHelper' ); $this->container['CategoriesListCache'] = Mockery::mock( 'AWPCP_CategoriesListCache' ); - Functions\when( 'awpcp_facebook_cache_helper' )->justReturn( Mockery::mock( 'AWPCP_FacebookCacheHelper' ) ); + WP_Mock::userFunction( 'awpcp_facebook_cache_helper', [ + 'return' => Mockery::mock( 'AWPCP_FacebookCacheHelper' ), + ] ); - Functions\when( 'wp_doing_ajax' )->justReturn( true ); - Functions\when( 'is_admin' )->justReturn( true ); + WP_Mock::userFunction( 'wp_doing_ajax', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => true, + ] ); // Execution. $this->get_test_subject()->init(); diff --git a/tests/suite/includes/test-listing-authorization.php b/tests/suite/includes/test-listing-authorization.php index 0143cc5ce..e4c6b5bea 100644 --- a/tests/suite/includes/test-listing-authorization.php +++ b/tests/suite/includes/test-listing-authorization.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Unit tests for Listing Authorization. */ @@ -34,7 +32,9 @@ public function test_is_current_user_allowed_to_edit_listing_with_anonymous_user 'post_author' => null, ); - Functions\when( 'is_user_logged_in' )->justReturn( false ); + WP_Mock::userFunction( 'is_user_logged_in', [ + 'return' => false, + ] ); $this->request = Phake::mock( 'AWPCP_Request' ); @@ -111,7 +111,9 @@ public function test_is_current_user_allowed_to_edit_listing_start_date_when_sta $this->listing_renderer->shouldReceive( 'get_start_date' ) ->andReturn( $start_date ); - Functions\when( 'current_time' )->justReturn( $now ); + WP_Mock::userFunction( 'current_time', [ + 'return' => $now, + ] ); $this->assertFalse( $this->get_test_subject()->is_current_user_allowed_to_edit_listing_start_date( null ) ); } @@ -132,7 +134,9 @@ public function test_is_current_user_allowed_to_edit_listing_start_date_when_sta $this->listing_renderer->shouldReceive( 'get_start_date' ) ->andReturn( $start_date ); - Functions\when( 'current_time' )->justReturn( $now ); + WP_Mock::userFunction( 'current_time', [ + 'return' => $now, + ] ); $this->request->shouldReceive( 'post' )->with( 'mode' )->andReturn( 'edit', 'create' ); $this->assertTrue( $this->get_test_subject()->is_current_user_allowed_to_edit_listing_start_date( null ) ); diff --git a/tests/suite/includes/test-listings-api.php b/tests/suite/includes/test-listings-api.php index 9568f4a63..0e2963ca5 100644 --- a/tests/suite/includes/test-listings-api.php +++ b/tests/suite/includes/test-listings-api.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * @group core */ @@ -428,9 +426,10 @@ public function test_flag_listing() { ->with( $post->ID, '_awpcp_flagged', true ) ->andReturn( wp_rand() + 1 ); - Functions\expect( 'awpcp_send_listing_was_flagged_notification' ) - ->once() - ->with( $post ); + WP_Mock::userFunction( 'awpcp_send_listing_was_flagged_notification', [ + 'times' => 1, + 'args' => [ $post ], + ] ); $listings_logic = $this->get_test_subject(); @@ -501,14 +500,23 @@ public function test_send_verification_email() { $contact_name = 'John Doe'; $contact_email = 'john.doe@example.org'; - Functions\when( 'awpcp_get_blog_name' )->justReturn( 'Test Blog' ); - Functions\when( 'home_url' )->justReturn( 'https://example.org' ); - Functions\when( 'awpcp' )->justReturn( $awpcp ); - Functions\when( 'awpcp_get_email_verification_url' )->justReturn( 'https://example.org' ); - - Functions\expect( 'awpcp_format_recipient_address' ) - ->once() - ->with( $contact_email, $contact_name ); + WP_Mock::userFunction( 'awpcp_get_blog_name', [ + 'return' => 'Test Blog', + ] ); + WP_Mock::userFunction( 'home_url', [ + 'return' => 'https://example.org', + ] ); + WP_Mock::userFunction( 'awpcp', [ + 'return' => $awpcp, + ] ); + WP_Mock::userFunction( 'awpcp_get_email_verification_url', [ + 'return' => 'https://example.org', + ] ); + + WP_Mock::userFunction( 'awpcp_format_recipient_address', [ + 'times' => 1, + 'args' => [ $contact_email, $contact_name ], + ] ); $this->listing_renderer->shouldReceive( [ @@ -549,13 +557,15 @@ public function test_calculate_start_and_end_dates_using_payment_term( ->andReturn( $expected_end_date ); } - Functions\expect( 'current_time' ) - ->with( 'mysql' ) - ->andReturn( $now_date ); + WP_Mock::userFunction( 'current_time', [ + 'with' => [ 'mysql' ], + 'return' => $now_date, + ] ); - Functions\expect( 'current_time' ) - ->with( 'timestamp' ) - ->andReturn( $now_timestamp ); + WP_Mock::userFunction( 'current_time', [ + 'with' => [ 'timestamp' ], + 'return' => $now_timestamp, + ] ); $metadata = $this->get_test_subject()->calculate_start_and_end_dates_using_payment_term( $payment_term, @@ -608,16 +618,24 @@ public function test_fill_default_listing_metadata( $metadata, $stored, $expecte 'ID' => wp_rand(), ]; - Functions\when( 'get_post_meta' )->justReturn( $stored ); - Functions\when( 'current_time' )->justReturn( $expected['_awpcp_most_recent_start_date'] ); - Functions\when( 'awpcp_getip' )->justReturn( $expected['_awpcp_poster_ip'] ); - Functions\when( 'awpcp_current_user_is_moderator' )->justReturn( false ); - - Functions\when( 'wp_parse_args' )->alias( - function( $a, $b ) { + WP_Mock::userFunction( 'get_post_meta', [ + 'return' => $stored, + ] ); + WP_Mock::userFunction( 'current_time', [ + 'return' => $expected['_awpcp_most_recent_start_date'], + ] ); + WP_Mock::userFunction( 'awpcp_getip', [ + 'return' => $expected['_awpcp_poster_ip'], + ] ); + WP_Mock::userFunction( 'awpcp_current_user_is_moderator', [ + 'return' => false, + ] ); + + WP_Mock::userFunction( 'wp_parse_args', [ + 'return' => function( $a, $b ) { return array_merge( $b, $a ); - } - ); + }, + ] ); $this->redefine( 'AWPCP_ListingsAPI::generate_access_key', @@ -701,25 +719,30 @@ public function test_send_ad_posted_email_notifications() { ->with( $listing ) ->andReturn( true ); - Functions\expect( 'awpcp_send_listing_posted_notification_to_user' ) - ->once() - ->with( $listing, $transaction, Mockery::any() ); - - Functions\expect( 'awpcp_send_listing_posted_notification_to_moderators' ) - ->once() - ->with( $listing, $transaction, Mockery::any() ); - - Functions\expect( 'get_awpcp_option' ) - ->with( 'adapprove' ) - ->andReturn( $moderate_listings ); - - Functions\expect( 'get_awpcp_option' ) - ->with( 'imagesapprove' ) - ->andReturn( $moderate_images ); - - Functions\expect( 'awpcp_send_listing_awaiting_approval_notification_to_moderators' ) - ->once() - ->with( $listing, $moderate_listings, $moderate_images ); + WP_Mock::userFunction( 'awpcp_send_listing_posted_notification_to_user', [ + 'times' => 1, + 'args' => [ $listing, $transaction, Mockery::any() ], + ] ); + + WP_Mock::userFunction( 'awpcp_send_listing_posted_notification_to_moderators', [ + 'times' => 1, + 'args' => [ $listing, $transaction, Mockery::any() ], + ] ); + + WP_Mock::userFunction( 'get_awpcp_option', [ + 'args' => [ 'adapprove' ], + 'return' => $moderate_listings, + ] ); + + WP_Mock::userFunction( 'get_awpcp_option', [ + 'args' => [ 'imagesapprove' ], + 'return' => $moderate_images, + ] ); + + WP_Mock::userFunction( 'awpcp_send_listing_awaiting_approval_notification_to_moderators', [ + 'times' => 1, + 'args' => [ $listing, $moderate_listings, $moderate_images ], + ] ); // Execution & Verification. $this->get_test_subject()->send_ad_posted_email_notifications( diff --git a/tests/suite/includes/test-payments-api.php b/tests/suite/includes/test-payments-api.php index 480474be7..2ab4428c4 100644 --- a/tests/suite/includes/test-payments-api.php +++ b/tests/suite/includes/test-payments-api.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests */ -use Brain\Monkey\Functions; - /** * @group core */ @@ -15,21 +13,30 @@ public function test_render_account_balance() { 'ID' => wp_rand(), ]; - Functions\expect( 'get_awpcp_option' ) - ->with( 'freepay' ) - ->andReturn( 1 ); - - Functions\expect( 'get_awpcp_option' ) - ->with( 'enable-credit-system' ) - ->andReturn( 1 ); - - Functions\expect( 'get_user_meta' ) - ->with( $user->ID, 'awpcp-account-balance', true ) - ->andReturn( 45000 ); - - Functions\when( 'is_admin' )->justReturn( false ); - Functions\when( 'is_user_logged_in' )->justReturn( true ); - Functions\when( 'wp_get_current_user' )->justReturn( $user ); + WP_Mock::userFunction( 'get_awpcp_option', [ + 'args' => 'freepay', + 'return' => 1, + ] ); + + WP_Mock::userFunction( 'get_awpcp_option', [ + 'args' => 'enable-credit-system', + 'return' => 1, + ] ); + + WP_Mock::userFunction( 'get_user_meta', [ + 'args' => [ $user->ID, 'awpcp-account-balance', true ], + 'return' => 45000, + ] ); + + WP_Mock::userFunction( 'is_admin', [ + 'return' => false, + ] ); + WP_Mock::userFunction( 'is_user_logged_in', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'wp_get_current_user', [ + 'return' => $user, + ] ); $api = $this->get_test_subject(); @@ -64,11 +71,14 @@ public function test_render_account_balance_for_transaction() { $transaction->shouldReceive( 'get_total_credits' ) ->andReturn( 35000 ); - Functions\when( 'is_admin' )->justReturn( false ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => false, + ] ); - Functions\expect( 'get_user_meta' ) - ->with( $transaction->user_id, 'awpcp-account-balance', true ) - ->andReturn( 45000 ); + WP_Mock::userFunction( 'get_user_meta', [ + 'args' => [ $transaction->user_id, 'awpcp-account-balance', true ], + 'return' => 45000, + ] ); $this->redefine( 'AWPCP_PaymentsAPI::get_credit_plan', \Patchwork\always( $credit_plan ) ); diff --git a/tests/suite/includes/ui/test-classifieds-bar.php b/tests/suite/includes/ui/test-classifieds-bar.php index 753ecb7cb..8a26e6631 100644 --- a/tests/suite/includes/ui/test-classifieds-bar.php +++ b/tests/suite/includes/ui/test-classifieds-bar.php @@ -1,7 +1,5 @@ term_id = rand() + 1; $this->last_item_id = rand() + 1; - Functions\when( 'is_wp_error' )->justReturn( false ); + WP_Mock::userFunction( 'is_wp_error', [ + 'return' => false, + ] ); } public function test_process_item() { @@ -203,11 +203,18 @@ function( $category_name, $category_slug ) { } ); - Functions\when( 'sanitize_title' )->alias( 'strtolower' ); + WP_Mock::userFunction( 'sanitize_title', [ + 'return' => function( $name ) { + return strtolower( $name ); + }, + ] ); - Functions\expect( 'get_term_by' ) - ->with( 'slug', 'unknown', 'awpcp_listing_category' ) - ->andReturn( null ); + // Q: convert to WP_Mock + + WP_Mock::userFunction( 'get_term_by', [ + 'args' => [ 'slug', 'unknown', 'awpcp_listing_category' ], + 'return' => null, + ] ); $this->categories->shouldReceive( 'get_categories_registry' ) ->andReturn( null ); diff --git a/tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php b/tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php index 5e4384af8..569cfe58d 100644 --- a/tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php +++ b/tests/suite/includes/upgrade/test-store-media-as-attachments-upgrade-task-handler.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Upgrade */ -use Brain\Monkey\Functions; - class AWPCP_Test_Store_Media_As_Attachments_Upgrade_Task_Handler extends AWPCP_UnitTestCase { public function setUp(): void { @@ -33,17 +31,39 @@ public function setUp(): void { public function test_process_item() { $parent_listing = (object) array( 'ID' => wp_rand() + 1 ); - Functions\when( 'get_post_meta' )->justReturn( '' ); - Functions\when( 'media_handle_upload' )->justReturn( null ); - Functions\when( 'get_temp_dir' )->justReturn( '/tmp/' ); - Functions\when( 'wp_unique_filename' )->returnArg( 2 ); - Functions\when( 'is_wp_error' )->justReturn( false ); - Functions\when( 'update_post_meta' )->justReturn( true ); - Functions\when( 'get_intermediate_image_sizes' )->justReturn( [] ); - - Functions\when( 'awpcp_sanitize_file_name' )->returnArg(); - - Functions\when( 'add_post_meta' )->justReturn( true ); + WP_Mock::userFunction( 'get_post_meta', [ + 'return' => '', + ] ); + WP_Mock::userFunction( 'media_handle_upload', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'get_temp_dir', [ + 'return' => '/tmp/', + ] ); + WP_Mock::userFunction( 'wp_unique_filename', [ + 'return' => function( $dir, $filename ) { + return $filename; + }, + ] ); + WP_Mock::userFunction( 'is_wp_error', [ + 'return' => false, + ] ); + WP_Mock::userFunction( 'update_post_meta', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'get_intermediate_image_sizes', [ + 'return' => [], + ] ); + + WP_Mock::userFunction( 'awpcp_sanitize_file_name', [ + 'return' => function( $arg ) { + return $arg; + }, + ] ); + + WP_Mock::userFunction( 'add_post_meta', [ + 'return' => true, + ] ); Phake::when( $this->settings )->get_runtime_option->thenReturn( WP_TESTS_DATA_DIR . '/upgrade' ); diff --git a/tests/suite/listings/facebook/test-send-to-facebook-helper.php b/tests/suite/listings/facebook/test-send-to-facebook-helper.php index 42d26eb69..5922c85d0 100644 --- a/tests/suite/listings/facebook/test-send-to-facebook-helper.php +++ b/tests/suite/listings/facebook/test-send-to-facebook-helper.php @@ -8,6 +8,11 @@ */ class AWPCP_SendToFacebookHelperTest extends AWPCP_UnitTestCase { + private $facebook; + private $listing_renderer; + private $settings; + private $wordpress; + /** * @since 4.0.0 */ diff --git a/tests/suite/listings/test-listing-renewed-email-notifications.php b/tests/suite/listings/test-listing-renewed-email-notifications.php index 5a282b91f..5f5497ac9 100644 --- a/tests/suite/listings/test-listing-renewed-email-notifications.php +++ b/tests/suite/listings/test-listing-renewed-email-notifications.php @@ -3,13 +3,15 @@ * @package AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Test ListingRenewedEmailNotification class. */ class AWPCP_ListingRenewedEmailNotificationTest extends AWPCP_UnitTestCase { + private $listing_renderer; + private $template_renderer; + private $settings; + /** * @since 4.0.0 */ @@ -47,7 +49,9 @@ private function get_test_subject() { public function test_send_admin_notification() { $notifications = $this->get_test_subject(); - Functions\when( 'awpcp_admin_email_to' )->justReturn( 'admin@example.org' ); + WP_Mock::userFunction( 'awpcp_admin_email_to', [ + 'return' => 'admin@example.org', + ] ); // Execution. $email_sent = $notifications->send_admin_notification( null ); diff --git a/tests/suite/listings/test-listings-collection.php b/tests/suite/listings/test-listings-collection.php index fbe713b5a..b8ad01eb3 100644 --- a/tests/suite/listings/test-listings-collection.php +++ b/tests/suite/listings/test-listings-collection.php @@ -3,7 +3,6 @@ * @package AWPCP\Tests\Listings */ -use Brain\Monkey\Functions; use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts; /** @@ -12,6 +11,11 @@ class AWPCP_ListingsCollectionTest extends AWPCP_UnitTestCase { use ArraySubsetAsserts; + + private $wordpress; + private $roles; + private $query; + /** * @since 4.0.0 */ @@ -25,8 +29,14 @@ public function setUp(): void { $this->wordpress = Mockery::mock( 'AWPCP_WordPress' ); $this->roles = Mockery::mock( 'AWPCP_RolesAndCapabilities' ); - Functions\when( 'apply_filters' )->returnArg( 2 ); - Functions\when( 'is_admin' )->justReturn( false ); + WP_Mock::userFunction( 'apply_filters', [ + 'return' => function( $hook, $value ) { + return $value; + }, + ] ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => false, + ] ); } /** @@ -286,7 +296,11 @@ function( $query_vars ) { $this->roles->shouldReceive( 'current_user_is_moderator' )->andReturn( true ); - Functions\when( 'apply_filters' )->returnArg( 2 ); + WP_Mock::userFunction( 'apply_filters', [ + 'return' => function( $hook, $value ) { + return $value; + }, + ] ); $collection = $this->get_test_subject(); diff --git a/tests/suite/listings/test-listings-container-configuration.php b/tests/suite/listings/test-listings-container-configuration.php index 26829c85c..6638940cf 100644 --- a/tests/suite/listings/test-listings-container-configuration.php +++ b/tests/suite/listings/test-listings-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Tests for Listings Container Configuration. */ @@ -16,8 +14,12 @@ class AWPCP_ListingsContainerConfigurationTest extends AWPCP_ContainerConfigurat public function setUp(): void { parent::setUp(); - Functions\when( 'awpcp_roles_and_capabilities' )->justReturn( null ); - Functions\when( 'awpcp_categories_registry' )->justReturn( null ); + WP_Mock::userFunction( 'awpcp_roles_and_capabilities', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_categories_registry', [ + 'return' => null, + ] ); } /** diff --git a/tests/suite/listings/test-query-integration.php b/tests/suite/listings/test-query-integration.php index 6ae3372b4..8849728ea 100644 --- a/tests/suite/listings/test-query-integration.php +++ b/tests/suite/listings/test-query-integration.php @@ -3,14 +3,17 @@ * @package AWPCP\Tests\Plugin\Listings */ -use Brain\Monkey\Functions; - /** * Unit tests for the class that integrates with WP Query to support Classifieds * query parameters. */ class AWPCP_QueryIntegrationTest extends AWPCP_UnitTestCase { + private $settings; + private $db; + private $post_type; + private $query_vars; + /** * @since 4.0.0 */ @@ -388,7 +391,9 @@ public function test_is_disabled_query_parameter() { public function test_is_enabled_query_parameter() { $this->query_vars['classifieds_query']['is_enabled'] = true; - Functions\when( 'current_time' )->justReturn( 1 ); + WP_Mock::userFunction( 'current_time', [ + 'return' => 1, + ] ); $query_vars = $this->process_query_parameters(); $meta_keys = $this->get_meta_keys( $query_vars ); @@ -408,7 +413,9 @@ public function test_is_about_to_expire_query_parameter() { ->with( 'ad-renew-email-threshold' ) ->andReturn( 1 ); - Functions\when( 'current_time' )->justReturn( 1 ); + WP_Mock::userFunction( 'current_time', [ + 'return' => 1, + ] ); $query_vars = $this->process_query_parameters(); $meta_keys = $this->get_meta_keys( $query_vars ); @@ -424,7 +431,9 @@ public function test_is_about_to_expire_query_parameter() { public function test_is_expired_query_parameter() { $this->query_vars['classifieds_query']['is_expired'] = true; - Functions\when( 'current_time' )->justReturn( 1 ); + WP_Mock::userFunction( 'current_time', [ + 'return' => 1, + ] ); $query_vars = $this->process_query_parameters(); $meta_keys = $this->get_meta_keys( $query_vars ); @@ -638,7 +647,9 @@ public function test_contact_phone_query_parameter() { $this->query_vars['classifieds_query']['contact_phone'] = '(316) 632 61 98'; - Functions\when( 'awpcp_get_digits_from_string' )->justReturn( $phone_number_digits ); + WP_Mock::userFunction( 'awpcp_get_digits_from_string', [ + 'return' => $phone_number_digits, + ] ); // Execution. $query_vars = $this->process_query_parameters(); diff --git a/tests/suite/listings/test-remove-listing-attachments-service.php b/tests/suite/listings/test-remove-listing-attachments-service.php index e04d690f9..289fabae0 100644 --- a/tests/suite/listings/test-remove-listing-attachments-service.php +++ b/tests/suite/listings/test-remove-listing-attachments-service.php @@ -8,6 +8,10 @@ */ class AWPCP_RemoveListingAttachmentsServiceTest extends AWPCP_UnitTestCase { + private $listing_post_type; + private $attachments; + private $wordpress; + public function setUp(): void { parent::setUp(); diff --git a/tests/suite/settings/test-settings-container-configuration.php b/tests/suite/settings/test-settings-container-configuration.php index b1b378cf7..78d139e4a 100644 --- a/tests/suite/settings/test-settings-container-configuration.php +++ b/tests/suite/settings/test-settings-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin\Settings */ -use Brain\Monkey\Functions; - /** * Tests for Settings Container Configuration. */ @@ -17,7 +15,9 @@ public function setUp(): void { parent::setUp(); // XXX: The Settings class does some stuff on the constructor. - Functions\when( 'get_option' )->justReturn( false ); + WP_Mock::userFunction( 'get_option', [ + 'return' => false, + ] ); } /** diff --git a/tests/suite/test-container-configuration.php b/tests/suite/test-container-configuration.php index 15fdf22e8..44b8799c8 100644 --- a/tests/suite/test-container-configuration.php +++ b/tests/suite/test-container-configuration.php @@ -3,8 +3,6 @@ * @package AWPCP\Tests\Plugin */ -use Brain\Monkey\Functions; - /** * Tests for main Container Configuration class. */ @@ -20,12 +18,20 @@ public function setUp(): void { $GLOBALS['wpdb'] = (object) []; // Required by ModulesManager. - Functions\when( 'awpcp_upgrade_tasks_manager' )->justReturn( null ); - Functions\when( 'awpcp_licenses_manager' )->justReturn( null ); - Functions\when( 'awpcp_modules_updater' )->justReturn( null ); + WP_Mock::userFunction( 'awpcp_upgrade_tasks_manager', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_licenses_manager', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_modules_updater', [ + 'return' => null, + ] ); // Used by AWPCP_PaymentsAPI's constructor. - Functions\when( 'is_admin' )->justReturn( false ); + WP_Mock::userFunction( 'is_admin', [ + 'return' => false, + ] ); } /** @@ -114,10 +120,18 @@ public function test_template_renderer_definition() { * @since 4.0.0 */ public function test_send_listing_to_facebook_helper_definition() { - Functions\when( 'awpcp_attachment_properties' )->justReturn( null ); - Functions\when( 'awpcp_attachments_collection' )->justReturn( null ); - Functions\when( 'awpcp_facebook_integration' )->justReturn( null ); - Functions\when( 'awpcp' )->justReturn( (object) [ 'settings' => null ] ); + WP_Mock::userFunction( 'awpcp_attachment_properties', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_attachments_collection', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp_facebook_integration', [ + 'return' => null, + ] ); + WP_Mock::userFunction( 'awpcp', [ + 'return' => (object) [ 'settings' => null ], + ] ); $this->test_class_definition( 'SendListingToFacebookHelper', diff --git a/tests/suite/test-uninstaller.php b/tests/suite/test-uninstaller.php index 04d061a16..5dfcfd098 100644 --- a/tests/suite/test-uninstaller.php +++ b/tests/suite/test-uninstaller.php @@ -3,13 +3,19 @@ * @package AWPCP\Tests\Plugin */ -use Brain\Monkey\Functions; - /** * Unit tests for Uninstaller. */ class AWPCP_UninstallerTest extends AWPCP_UnitTestCase { + private $listings_logic; + private $listings_collection; + private $categories_logic; + private $categories_collection; + private $roles_and_capabilities; + private $settings; + private $db; + /** * @since 4.0.0 */ @@ -38,13 +44,27 @@ public function test_uninstall() { $this->settings = Mockery::mock( 'AWPCP_SettingsAPI' ); $this->db = Mockery::mock( 'wpdb' ); - Functions\when( 'awpcp_get_plugin_pages_ids' )->justReturn( [] ); - Functions\when( 'awpcp_setup_uploads_dir' )->justReturn( [ $uploads_dir, null ] ); - Functions\when( 'esc_sql' )->justReturn( '' ); - Functions\when( 'delete_option' )->justReturn( true ); - Functions\when( 'wp_clear_scheduled_hook' )->justReturn( true ); - Functions\when( 'get_option' )->justReturn( [] ); - Functions\when( 'deactivate_plugins' )->justReturn( null ); + WP_Mock::userFunction( 'awpcp_get_plugin_pages_ids', [ + 'return' => [], + ] ); + WP_Mock::userFunction( 'awpcp_setup_uploads_dir', [ + 'return' => [ $uploads_dir, null ], + ] ); + WP_Mock::userFunction( 'esc_sql', [ + 'return' => '', + ] ); + WP_Mock::userFunction( 'delete_option', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'wp_clear_scheduled_hook', [ + 'return' => true, + ] ); + WP_Mock::userFunction( 'get_option', [ + 'return' => [], + ] ); + WP_Mock::userFunction( 'deactivate_plugins', [ + 'return' => null, + ] ); $this->categories_collection->shouldReceive( 'find_categories' ) ->andReturn( $categories ); diff --git a/tests/suite/ui/test-categories-selector.php b/tests/suite/ui/test-categories-selector.php index cf13f1cf6..af7671633 100644 --- a/tests/suite/ui/test-categories-selector.php +++ b/tests/suite/ui/test-categories-selector.php @@ -3,13 +3,15 @@ * @package AWPCP\Tests\Plugin\UI */ -use Brain\Monkey\Functions; - /** * Unit tests for Categories Selector component. */ class AWPCP_CategoriesSelectorTest extends AWPCP_UnitTestCase { + private $categories_selector_helper; + private $categories_collection; + private $template_renderer; + /** * @since 4.0.0 */ @@ -40,7 +42,9 @@ public function test_placeholder_parameter() { 'use_multiple_dropdowns' => null, ]; - Functions\when( 'awpcp_render_categories_dropdown_options' )->justReturn( '' ); + WP_Mock::userFunction( 'awpcp_render_categories_dropdown_options', [ + 'return' => '', + ] ); $this->get_test_subject(); $template_renderer = new AWPCP_Template_Renderer();