1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-23 21:06:56 +08:00
buddypress/tests/phpunit/testcases/xprofile/template.php
Mathieu Viet 73ce84cd3b Update both Template Pack registration forms to use signup fields
- Nouveau and Legacy are now usinf the `bp_xprofile_signup_args()` to build the argument of their registration's form xProfile loop.
- Include a backward compatibility mechanism if the `register.php` page has been overriden from a theme or a plugin.
- This commit also includes PHP Unit tests about the xProfile loop and Signup Fields.

Props johnjamesjacoby, boonebgorges, DJPaul, Offereins

Fixes #6347



git-svn-id: https://buddypress.svn.wordpress.org/trunk@12887 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2021-04-16 05:37:03 +00:00

129 lines
3.4 KiB
PHP

<?php
/**
* @group xprofile
*/
class BP_Tests_xProfile_Template extends BP_UnitTestCase {
/**
* @group bp_has_profile
*/
public function test_bp_has_profile_default() {
global $profile_template;
$reset_profile_template = $profile_template;
$prev_user = get_current_user_id();
$u1 = self::factory()->user->create(
array(
'display_name' => 'Foo Bar',
)
);
$this->set_current_user( $u1 );
bp_has_profile(
array(
'profile_group_id' => 1,
'user_id' => $u1,
)
);
$group = reset( $profile_template->groups );
$field = reset( $group->fields );
$this->assertEquals( 'Foo Bar', $field->data->value, 'The primary field should be the Name one and its value should be the same than the display name, by default' );
$this->set_current_user( $prev_user );
$profile_template = $reset_profile_template;
}
/**
* @group bp_has_profile
* @group bp_xprofile_signup_args
*/
public function test_bp_has_profile_signup_from_same_group() {
global $profile_template;
$reset_profile_template = $profile_template;
add_filter( 'bp_get_signup_allowed', '__return_true' );
$field_not_in = self::factory()->xprofile_field->create(
array(
'field_group_id' => 1,
'type' => 'textbox',
'name' => 'NotInSignupForm'
)
);
$field_in = self::factory()->xprofile_field->create(
array(
'field_group_id' => 1,
'type' => 'textbox',
'name' => 'InSignupForm'
)
);
// Add the field to signup ones.
bp_xprofile_update_field_meta( $field_in, 'signup_position', 2 );
bp_has_profile( bp_xprofile_signup_args() );
$group = reset( $profile_template->groups );
$names = wp_list_pluck( $group->fields, 'name' );
$expected_names = array( 'Name', 'InSignupForm' );
$this->assertSame( $expected_names, $names );
xprofile_delete_field( $field_in );
xprofile_delete_field( $field_not_in );
remove_filter( 'bp_get_signup_allowed', '__return_true' );
$profile_template = $reset_profile_template;
}
/**
* @group bp_has_profile
* @group bp_xprofile_signup_args
*/
public function test_bp_has_profile_signup_from_different_group() {
global $profile_template;
$reset_profile_template = $profile_template;
add_filter( 'bp_get_signup_allowed', '__return_true' );
$group_1 = self::factory()->xprofile_group->create();
$group_2 = self::factory()->xprofile_group->create();
$field_in_1 = self::factory()->xprofile_field->create(
array(
'field_group_id' => $group_1,
'type' => 'textbox',
'name' => 'InSignupForm1'
)
);
// Put the field at the last position
bp_xprofile_update_field_meta( $field_in_1, 'signup_position', 3 );
$field_in_2 = self::factory()->xprofile_field->create(
array(
'field_group_id' => $group_2,
'type' => 'textbox',
'name' => 'InSignupForm2'
)
);
// Put the field at the second position
bp_xprofile_update_field_meta( $field_in_2, 'signup_position', 2 );
bp_has_profile( bp_xprofile_signup_args() );
$group = reset( $profile_template->groups );
$names = wp_list_pluck( $group->fields, 'name' );
$expected_names = array( 'Name', 'InSignupForm2', 'InSignupForm1' );
$this->assertSame( $expected_names, $names );
xprofile_delete_field_group( $group_1 );
xprofile_delete_field_group( $group_2 );
remove_filter( 'bp_get_signup_allowed', '__return_true' );
$profile_template = $reset_profile_template;
}
}