Skip to:
Content

BuddyPress.org

Ticket #6347: 6347.alt.2.tests.patch

File 6347.alt.2.tests.patch, 3.7 KB (added by imath, 4 years ago)
  • new file tests/phpunit/testcases/xprofile/template.php

    diff --git tests/phpunit/testcases/xprofile/template.php tests/phpunit/testcases/xprofile/template.php
    new file mode 100644
    index 000000000..c8fe38d49
    - +  
     1<?php
     2/**
     3 * @group xprofile
     4 */
     5class BP_Tests_xProfile_Template extends BP_UnitTestCase {
     6
     7        /**
     8         * @group bp_has_profile
     9         */
     10        public function test_bp_has_profile_default() {
     11                global $profile_template;
     12                $reset_profile_template = $profile_template;
     13                $prev_user = get_current_user_id();
     14
     15                $u1 = self::factory()->user->create(
     16                        array(
     17                                'display_name' => 'Foo Bar',
     18                        )
     19                );
     20
     21                $this->set_current_user( $u1 );
     22
     23                bp_has_profile(
     24                        array(
     25                                'profile_group_id' => 1,
     26                                'user_id'          => $u1,
     27                        )
     28                );
     29
     30                $group = reset( $profile_template->groups );
     31                $field = reset( $group->fields );
     32                $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' );
     33
     34                $this->set_current_user( $prev_user );
     35                $profile_template = $reset_profile_template;
     36        }
     37
     38        /**
     39         * @group bp_has_profile
     40         * @group bp_xprofile_signup_args
     41         */
     42        public function test_bp_has_profile_signup_from_same_group() {
     43                global $profile_template;
     44                $reset_profile_template = $profile_template;
     45                add_filter( 'bp_get_signup_allowed', '__return_true' );
     46
     47                $field_not_in = self::factory()->xprofile_field->create(
     48                        array(
     49                                'field_group_id' => 1,
     50                                'type' => 'textbox',
     51                                'name' => 'NotInSignupForm'
     52                        )
     53                );
     54
     55                $field_in = self::factory()->xprofile_field->create(
     56                        array(
     57                                'field_group_id' => 1,
     58                                'type' => 'textbox',
     59                                'name' => 'InSignupForm'
     60                        )
     61                );
     62
     63                // Add the field to signup ones.
     64                bp_xprofile_update_field_meta( $field_in, 'signup_position', 2 );
     65
     66                bp_has_profile( bp_xprofile_signup_args() );
     67
     68                $group          = reset( $profile_template->groups );
     69                $names          = wp_list_pluck( $group->fields, 'name' );
     70                $expected_names = array( 'Name', 'InSignupForm' );
     71
     72                $this->assertSame( $expected_names, $names );
     73
     74                xprofile_delete_field( $field_in );
     75                xprofile_delete_field( $field_not_in );
     76
     77                remove_filter( 'bp_get_signup_allowed', '__return_true' );
     78                $profile_template = $reset_profile_template;
     79        }
     80
     81        /**
     82         * @group bp_has_profile
     83         * @group bp_xprofile_signup_args
     84         */
     85        public function test_bp_has_profile_signup_from_different_group() {
     86                global $profile_template;
     87                $reset_profile_template = $profile_template;
     88                add_filter( 'bp_get_signup_allowed', '__return_true' );
     89
     90                $group_1 = self::factory()->xprofile_group->create();
     91                $group_2 = self::factory()->xprofile_group->create();
     92
     93                $field_in_1 = self::factory()->xprofile_field->create(
     94                        array(
     95                                'field_group_id' => $group_1,
     96                                'type' => 'textbox',
     97                                'name' => 'InSignupForm1'
     98                        )
     99                );
     100
     101                // Put the field at the last position
     102                bp_xprofile_update_field_meta( $field_in_1, 'signup_position', 3 );
     103
     104                $field_in_2 = self::factory()->xprofile_field->create(
     105                        array(
     106                                'field_group_id' => $group_2,
     107                                'type' => 'textbox',
     108                                'name' => 'InSignupForm2'
     109                        )
     110                );
     111
     112                // Put the field at the second position
     113                bp_xprofile_update_field_meta( $field_in_2, 'signup_position', 2 );
     114
     115                bp_has_profile( bp_xprofile_signup_args() );
     116
     117                $group          = reset( $profile_template->groups );
     118                $names          = wp_list_pluck( $group->fields, 'name' );
     119                $expected_names = array( 'Name', 'InSignupForm2', 'InSignupForm1' );
     120
     121                $this->assertSame( $expected_names, $names );
     122
     123                xprofile_delete_field_group( $group_1 );
     124                xprofile_delete_field_group( $group_2 );
     125
     126                remove_filter( 'bp_get_signup_allowed', '__return_true' );
     127                $profile_template = $reset_profile_template;
     128        }
     129}