mirror of
https://github.com/buddypress/buddypress.git
synced 2026-07-24 21:16:56 +08:00
Using these polyfills let us use PHPUnit v9.x for our tests and add PHP 8.1 to our testing matrix. Some additional edits to our PHP unit tests suite were needed: - Stop using PHPunit deprecated functions. - Rename some `BP_UnitTestCase` methods to use Yoast's polyfills. - Edit the PHP Unit test GH action and also run this action on pull requests. - Update some composer dependencies, remove the one about `phpunit/phpunit:^7.5` and add a new composer script to use PHPUnit v9.x. Props renatonascalves, rafiahmedd Closes https://github.com/buddypress/buddypress/pull/13 Fixes #8649 git-svn-id: https://buddypress.svn.wordpress.org/trunk@13314 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
95 lines
2.5 KiB
PHP
95 lines
2.5 KiB
PHP
<?php
|
|
|
|
include_once BP_TESTS_DIR . '/assets/bp-rest-api-controllers.php';
|
|
include_once BP_TESTS_DIR . '/assets/class-bptest-component.php';
|
|
|
|
/**
|
|
* @group core
|
|
* @group BP_Component
|
|
*/
|
|
class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase {
|
|
public function set_up() {
|
|
parent::set_up();
|
|
|
|
$bp = buddypress();
|
|
$bp->unit_test_rest = new stdClass;
|
|
$bp->unit_test_rest->controllers = array();
|
|
}
|
|
|
|
public function remove_controller( $controllers ) {
|
|
return array_diff( $controllers, array( 'BP_REST_Members_Endpoint' ) );
|
|
}
|
|
|
|
public function add_controller( $controllers ) {
|
|
return array_merge( $controllers, array( 'Foo_Bar' ) );
|
|
}
|
|
|
|
public function test_rest_api_init_for_members_component() {
|
|
$bp_members = new BP_Members_Component();
|
|
$bp = buddypress();
|
|
|
|
$bp_members->rest_api_init();
|
|
|
|
$this->assertSame( $bp->unit_test_rest->controllers, array(
|
|
'BP_REST_Members_Endpoint',
|
|
'BP_REST_Attachments_Member_Avatar_Endpoint',
|
|
'BP_REST_Attachments_Member_Cover_Endpoint',
|
|
) );
|
|
}
|
|
|
|
public function test_rest_api_init_for_members_component_can_remove_controller() {
|
|
$bp_members = new BP_Members_Component();
|
|
$bp = buddypress();
|
|
|
|
add_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
|
|
|
|
$bp_members->rest_api_init();
|
|
|
|
remove_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
|
|
|
|
$this->assertSame( $bp->unit_test_rest->controllers, array(
|
|
'BP_REST_Attachments_Member_Avatar_Endpoint',
|
|
'BP_REST_Attachments_Member_Cover_Endpoint',
|
|
) );
|
|
}
|
|
|
|
public function test_rest_api_init_for_members_component_cannot_add_controller() {
|
|
$bp_members = new BP_Members_Component();
|
|
$bp = buddypress();
|
|
|
|
add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
|
|
|
|
$bp_members->rest_api_init();
|
|
|
|
remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
|
|
|
|
$this->assertSame( $bp->unit_test_rest->controllers, array(
|
|
'BP_REST_Members_Endpoint',
|
|
'BP_REST_Attachments_Member_Avatar_Endpoint',
|
|
'BP_REST_Attachments_Member_Cover_Endpoint',
|
|
) );
|
|
}
|
|
|
|
/**
|
|
* @group bp_blocks
|
|
*/
|
|
public function test_component_block_globals() {
|
|
$expected = array(
|
|
'dynamic_widget_classname' => 'widget_example_classname',
|
|
);
|
|
|
|
$example = new BPTest_Component(
|
|
array(
|
|
'globals' => array(
|
|
'block_globals' => array(
|
|
'bp/example-block' => $expected,
|
|
)
|
|
),
|
|
)
|
|
);
|
|
|
|
do_action( 'bp_setup_globals' );
|
|
|
|
$this->assertEquals( $expected, $example->block_globals['bp/example-block']->props );
|
|
}
|
|
}
|