diff --git .gitignore .gitignore
index 31e1164a..103b7309 100644
|
|
|
14 | 14 | /phpcs.xml |
15 | 15 | /phpunit.xml |
16 | 16 | /pnpm-lock.yaml |
| 17 | .phpunit.result.cache |
17 | 18 | |
18 | 19 | # Output directory. |
19 | 20 | /build/ |
diff --git composer.json composer.json
index ab12dbcb..7be27081 100644
|
|
|
5 | 5 | "require-dev": { |
6 | 6 | "phpcompatibility/phpcompatibility-wp": "^2.1", |
7 | 7 | "wp-coding-standards/wpcs": "^2.3", |
8 | | "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2" |
| 8 | "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", |
| 9 | "phpunit/phpunit": "^9", |
| 10 | "yoast/phpunit-polyfills": "^3.0" |
9 | 11 | }, |
10 | 12 | "minimum-stability": "dev", |
11 | 13 | "prefer-stable": true, |
… |
… |
|
15 | 17 | ], |
16 | 18 | "lint": [ |
17 | 19 | "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" |
| 20 | ], |
| 21 | "test": [ |
| 22 | "@php ./vendor/bin/phpunit -c phpunit.xml.dist" |
| 23 | ], |
| 24 | "phpunit": [ |
| 25 | "@test" |
18 | 26 | ] |
| 27 | }, |
| 28 | "config": { |
| 29 | "allow-plugins": { |
| 30 | "composer/installers": true, |
| 31 | "dealerdirect/phpcodesniffer-composer-installer": true |
| 32 | } |
19 | 33 | } |
20 | 34 | } |
diff --git package.json package.json
index c73476f5..cbab792e 100644
|
|
|
30 | 30 | "devDependencies": { |
31 | 31 | "@wordpress/browserslist-config": "~2.1.3", |
32 | 32 | "@wordpress/stylelint-config": "~22.4.0", |
| 33 | "@wordpress/env": "^10.8.0", |
33 | 34 | "autoprefixer": "~8.2.0", |
34 | 35 | "browserslist": "~4.23.2", |
35 | 36 | "grunt": "~1.6.1", |
… |
… |
|
48 | 49 | "grunt-postcss": "~0.9.0", |
49 | 50 | "grunt-rtlcss": "~2.0.2", |
50 | 51 | "grunt-sass": "~3.1.0", |
51 | | "grunt-stylelint": "~0.8.0", |
| 52 | "grunt-stylelint": "~0.18", |
52 | 53 | "grunt-terser": "~2.0.0", |
53 | 54 | "grunt-wp-i18n": "~1.0.3", |
| 55 | "grunt-composer": "~0.4.5", |
54 | 56 | "matchdep": "~2.0.0", |
55 | 57 | "node-sass": "~9.0.0", |
56 | 58 | "postcss": "~8.4.40", |
57 | 59 | "postcss-markdown": "~1.2.0", |
58 | 60 | "postcss-scss": "~1.0.2", |
59 | | "stylelint": "~15.11.0", |
60 | | "stylelint-scss": "~6.4.1", |
| 61 | "stylelint": "~14", |
| 62 | "stylelint-scss": "~5", |
61 | 63 | "terser": "~5.31.3" |
| 64 | }, |
| 65 | "scripts": { |
| 66 | "wp-env": "wp-env", |
| 67 | "test-php": "npm run wp-env run cli -- --env-cwd=wp-content/plugins/bbPress composer test" |
62 | 68 | } |
63 | 69 | } |
diff --git phpunit.xml.dist phpunit.xml.dist
index dc7a8445..d95eea8c 100644
|
|
|
7 | 7 | convertWarningsToExceptions="true" |
8 | 8 | > |
9 | 9 | <testsuites> |
10 | | <testsuite> |
| 10 | <testsuite name="bbPress Test Suite"> |
11 | 11 | <directory suffix=".php">tests/phpunit/testcases/</directory> |
12 | 12 | </testsuite> |
13 | 13 | </testsuites> |
… |
… |
|
27 | 27 | <!-- </arguments>--> |
28 | 28 | <!-- </listener>--> |
29 | 29 | <!-- </listeners>--> |
30 | | <filter> |
31 | | <whitelist processUncoveredFilesFromWhitelist="true"> |
32 | | <directory suffix=".php">src</directory> |
33 | | </whitelist> |
34 | | </filter> |
| 30 | <coverage> |
| 31 | <include> |
| 32 | <directory suffix=".php">./src</directory> |
| 33 | </include> |
| 34 | <exclude> |
| 35 | <directory suffix=".php">./tests</directory> |
| 36 | <directory suffix=".php">./vendor</directory> |
| 37 | </exclude> |
| 38 | </coverage> |
35 | 39 | </phpunit> |
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index c5496633..ea773579 100644
|
|
class BBP_UnitTestCase extends WP_UnitTestCase { |
7 | 7 | /** |
8 | 8 | * Fake WP mail globals, to avoid errors |
9 | 9 | */ |
10 | | public static function setUpBeforeClass() { |
| 10 | public static function setUpBeforeClass(): void { |
11 | 11 | add_filter( 'wp_mail', array( 'BBP_UnitTestCase', 'setUp_wp_mail' ) ); |
12 | 12 | add_filter( 'wp_mail_from', array( 'BBP_UnitTestCase', 'tearDown_wp_mail' ) ); |
13 | 13 | } |
14 | 14 | |
15 | | public function setUp() { |
| 15 | public function setUp(): void { |
16 | 16 | parent::setUp(); |
17 | 17 | |
18 | 18 | $this->factory = new BBP_UnitTest_Factory; |
… |
… |
class BBP_UnitTestCase extends WP_UnitTestCase { |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | | public function tearDown() { |
| 33 | public function tearDown(): void { |
34 | 34 | global $wpdb; |
35 | 35 | |
36 | 36 | parent::tearDown(); |
… |
… |
class BBP_UnitTestCase extends WP_UnitTestCase { |
56 | 56 | parent::clean_up_global_scope(); |
57 | 57 | } |
58 | 58 | |
59 | | function assertPreConditions() { |
| 59 | function assertPreConditions(): void { |
60 | 60 | parent::assertPreConditions(); |
61 | 61 | } |
62 | 62 | |
diff --git tests/phpunit/testcases/admin/tools.php tests/phpunit/testcases/admin/tools.php
index 96914e00..1a54d0cc 100644
|
|
|
7 | 7 | */ |
8 | 8 | class BBP_Tests_Admin_Tools extends BBP_UnitTestCase { |
9 | 9 | protected $old_current_user = 0; |
| 10 | protected $keymaster_id; |
10 | 11 | |
11 | | public function setUp() { |
| 12 | public function setUp(): void { |
12 | 13 | parent::setUp(); |
13 | 14 | $this->old_current_user = get_current_user_id(); |
14 | 15 | $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
… |
… |
class BBP_Tests_Admin_Tools extends BBP_UnitTestCase { |
22 | 23 | } |
23 | 24 | } |
24 | 25 | |
25 | | public function tearDown() { |
| 26 | public function tearDown(): void { |
26 | 27 | parent::tearDown(); |
27 | 28 | $this->set_current_user( $this->old_current_user ); |
28 | 29 | } |
diff --git tests/phpunit/testcases/common/functions.php tests/phpunit/testcases/common/functions.php
index 0a9740f4..ef20648f 100644
|
|
|
8 | 8 | |
9 | 9 | class BBP_Tests_Common_Functions extends BBP_UnitTestCase { |
10 | 10 | |
| 11 | protected $old_current_user; |
| 12 | protected $moderator_id; |
| 13 | protected $keymaster_id; |
| 14 | |
11 | 15 | /** |
12 | 16 | * @covers ::bbp_number_format |
13 | 17 | * @todo Implement test_bbp_number_format(). |
diff --git tests/phpunit/testcases/common/verify-nonce.php tests/phpunit/testcases/common/verify-nonce.php
index 98d621d9..dba7c468 100644
|
|
class BBP_Tests_Common_Functions_BBPVerifyNonceRequest extends BBP_UnitTestCase |
10 | 10 | private $server_port = ''; |
11 | 11 | private $request_uri = ''; |
12 | 12 | |
13 | | public function setUp() { |
| 13 | public function setUp(): void { |
14 | 14 | parent::setUp(); |
15 | 15 | |
16 | 16 | if ( isset( $_SERVER['HTTP_HOST'] ) ) { |
… |
… |
class BBP_Tests_Common_Functions_BBPVerifyNonceRequest extends BBP_UnitTestCase |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | | public function tearDown() { |
| 29 | public function tearDown(): void { |
30 | 30 | $_SERVER['HTTP_HOST'] = $this->http_host; |
31 | 31 | |
32 | 32 | $_SERVER['SERVER_PORT'] = $this->server_port; |
diff --git tests/phpunit/testcases/replies/template/status.php tests/phpunit/testcases/replies/template/status.php
index 588e59d1..30ad0ccc 100644
|
|
|
9 | 9 | */ |
10 | 10 | class BBP_Tests_Repliess_Template_Status extends BBP_UnitTestCase { |
11 | 11 | protected $old_current_user = 0; |
| 12 | protected $keymaster_id; |
12 | 13 | |
13 | | public function setUp() { |
| 14 | public function setUp(): void { |
14 | 15 | parent::setUp(); |
15 | 16 | $this->old_current_user = get_current_user_id(); |
16 | 17 | $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
… |
… |
class BBP_Tests_Repliess_Template_Status extends BBP_UnitTestCase { |
18 | 19 | bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() ); |
19 | 20 | } |
20 | 21 | |
21 | | public function tearDown() { |
| 22 | public function tearDown(): void { |
22 | 23 | parent::tearDown(); |
23 | 24 | $this->set_current_user( $this->old_current_user ); |
24 | 25 | } |
diff --git tests/phpunit/testcases/topics/functions/topic.php tests/phpunit/testcases/topics/functions/topic.php
index ef89acf2..5eec2fdc 100644
|
|
|
9 | 9 | */ |
10 | 10 | class BBP_Tests_Topics_Functions_Topic extends BBP_UnitTestCase { |
11 | 11 | |
| 12 | protected $old_current_user; |
| 13 | protected $keymaster_id; |
| 14 | |
12 | 15 | /** |
13 | 16 | * @group canonical |
14 | 17 | * @covers ::bbp_insert_topic |
diff --git tests/phpunit/testcases/users/template/user.php tests/phpunit/testcases/users/template/user.php
index 60ef23c0..91579633 100644
|
|
|
8 | 8 | */ |
9 | 9 | class BBP_Tests_Users_Template_User extends BBP_UnitTestCase { |
10 | 10 | |
| 11 | protected $keymaster_userdata; |
| 12 | protected $keymaster_id; |
11 | 13 | protected $old_current_user = 0; |
12 | 14 | |
13 | | public function setUp() { |
| 15 | public function setUp(): void { |
14 | 16 | parent::setUp(); |
15 | 17 | $this->old_current_user = get_current_user_id(); |
16 | 18 | $this->set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
… |
… |
class BBP_Tests_Users_Template_User extends BBP_UnitTestCase { |
19 | 21 | bbp_set_user_role( $this->keymaster_id, bbp_get_keymaster_role() ); |
20 | 22 | } |
21 | 23 | |
22 | | public function tearDown() { |
| 24 | public function tearDown(): void { |
23 | 25 | parent::tearDown(); |
24 | 26 | $this->set_current_user( $this->old_current_user ); |
25 | 27 | } |
… |
… |
class BBP_Tests_Users_Template_User extends BBP_UnitTestCase { |
37 | 39 | $this->assertSame( $this->keymaster_id, $user_id ); |
38 | 40 | |
39 | 41 | // Output. |
40 | | $this->expectOutputString( $formatted_value ); |
41 | | bbp_user_id( $this->keymaster_id ); |
| 42 | $this->expectOutputRegex( '/' . preg_quote($formatted_value, '/') . '/' ); |
| 43 | bbp_user_id( $this->keymaster_id ); |
42 | 44 | } |
43 | 45 | |
44 | 46 | /** |