[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/xprofile/ -> class-bp-xprofile-field-type-wordpress.php (source)

   1  <?php
   2  /**
   3   * @group xprofile
   4   * @group BP_Tests_XProfile_Field_Type_WordPress
   5   * @ticket BP7162
   6   */
   7  class BP_Tests_XProfile_Field_Type_WordPress extends BP_UnitTestCase {
   8  
   9  	public function test_wp_textbox_validate_string() {
  10          $field = bp_xprofile_create_field_type( 'wp-textbox' );
  11          $this->assertTrue( $field->is_valid( 'Hello WordPress Fields!' ) );
  12      }
  13  
  14      /**
  15       * @group xprofile_set_field_data
  16       */
  17  	public function test_wp_textbox_set_last_name_field_data() {
  18          $user_id  = self::factory()->user->create();
  19          $group_id = self::factory()->xprofile_group->create();
  20          $field_id = self::factory()->xprofile_field->create(
  21              array(
  22                  'field_group_id' => $group_id,
  23                  'type'           => 'wp-textbox',
  24                  'name'           => 'WP Last Name',
  25              )
  26          );
  27  
  28          // Set the WP User Key.
  29          bp_xprofile_update_meta( $field_id, 'field', 'wp_user_key', 'last_name' );
  30  
  31          $field_data = xprofile_set_field_data( $field_id, $user_id, 'bar' );
  32  
  33          $user = get_user_by( 'id', $user_id );
  34  
  35          $this->assertEquals( 'bar', $user->last_name );
  36      }
  37  
  38      /**
  39       * @group bp_xprofile_get_groups
  40       */
  41  	public function test_wp_textbox_get_user_url_field_data() {
  42          $user_id  = self::factory()->user->create(
  43              array(
  44                  'user_url' => 'https://buddypress.org',
  45              )
  46          );
  47          $group_id = self::factory()->xprofile_group->create();
  48          $field_id = self::factory()->xprofile_field->create(
  49              array(
  50                  'field_group_id' => $group_id,
  51                  'type'           => 'wp-textbox',
  52                  'name'           => 'WP User URL',
  53              )
  54          );
  55  
  56          // Set the WP User Key.
  57          bp_xprofile_update_meta( $field_id, 'field', 'wp_user_key', 'user_url' );
  58  
  59          $groups = bp_xprofile_get_groups(
  60              array(
  61                  'profile_group_id'       => $group_id,
  62                  'user_id'                => $user_id,
  63                  'fetch_fields'           => true,
  64                  'fetch_field_data'       => true,
  65              )
  66          );
  67          $group  = reset( $groups );
  68          $field  = reset( $group->fields );
  69  
  70          $this->assertEquals( 'https://buddypress.org', $field->data->value );
  71      }
  72  
  73      /**
  74       * @group xprofile_get_field_data
  75       */
  76  	public function test_wp_textbox_get_first_name_field_value() {
  77          $user_id  = self::factory()->user->create(
  78              array(
  79                  'first_name' => 'foo',
  80              )
  81          );
  82          $group_id = self::factory()->xprofile_group->create();
  83          $field_id = self::factory()->xprofile_field->create(
  84              array(
  85                  'field_group_id' => $group_id,
  86                  'type'           => 'wp-textbox',
  87                  'name'           => 'WP First Name',
  88              )
  89          );
  90  
  91          // Set the WP User Key.
  92          bp_xprofile_update_meta( $field_id, 'field', 'wp_user_key', 'first_name' );
  93  
  94          $field_data = xprofile_get_field_data( $field_id, $user_id );
  95  
  96          $this->assertEquals( 'foo', $field_data );
  97      }
  98  
  99      /**
 100       * @group bp_member_profile_data
 101       * @group bp_get_member_profile_data
 102       */
 103  	public function test_wp_biography_get_field_value() {
 104          global $members_template;
 105          $reset_members_template = $members_template;
 106  
 107          $user_id  = self::factory()->user->create(
 108              array(
 109                  'description' => 'The BuddyPress community is awesome!',
 110              )
 111          );
 112          $group_id = self::factory()->xprofile_group->create();
 113          $field_id = self::factory()->xprofile_field->create(
 114              array(
 115                  'field_group_id' => $group_id,
 116                  'type'           => 'wp-biography',
 117                  'name'           => 'About Me',
 118              )
 119          );
 120  
 121          $members_template = new BP_Core_Members_Template(
 122              array(
 123                  'include'  => $user_id,
 124                  'type'     => 'alphabetical',
 125                  'page'     => 1,
 126                  'per_page' => 1,
 127              )
 128          );
 129  
 130          bp_the_member();
 131  
 132          $profile_data = bp_get_member_profile_data(
 133              array(
 134                  'field' => 'About Me'
 135              )
 136          );
 137  
 138          $members_template = $reset_members_template;
 139  
 140          $this->assertEquals( 'The BuddyPress community is awesome!', $profile_data );
 141      }
 142  }


Generated: Sat Apr 27 01:00:55 2024 Cross-referenced by PHPXref 0.7.1