[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/xprofile/ -> functions.php (source)

   1  <?php
   2  
   3  /**
   4   * @group xprofile
   5   * @group functions
   6   */
   7  class BP_Tests_XProfile_Functions extends BP_UnitTestCase {
   8      public function test_get_hidden_field_types_for_user_loggedout() {
   9          $duser = self::factory()->user->create();
  10  
  11          $old_current_user = bp_loggedin_user_id();
  12          $this->set_current_user( 0 );
  13  
  14          $this->assertEquals( array( 'friends', 'loggedin', 'adminsonly' ), bp_xprofile_get_hidden_field_types_for_user( $duser, bp_loggedin_user_id() ) );
  15  
  16          $this->set_current_user( $old_current_user );
  17      }
  18  
  19  	public function test_get_hidden_field_types_for_user_loggedin() {
  20          $duser = self::factory()->user->create();
  21          $cuser = self::factory()->user->create();
  22  
  23          $old_current_user = bp_loggedin_user_id();
  24          $this->set_current_user( $cuser );
  25  
  26          $this->assertEquals( array( 'friends', 'adminsonly' ), bp_xprofile_get_hidden_field_types_for_user( $duser, bp_loggedin_user_id() ) );
  27  
  28          $this->set_current_user( $old_current_user );
  29      }
  30  
  31  	public function test_get_hidden_field_types_for_user_friends() {
  32          $duser = self::factory()->user->create();
  33          $cuser = self::factory()->user->create();
  34          friends_add_friend( $duser, $cuser, true );
  35  
  36          $old_current_user = bp_loggedin_user_id();
  37          $this->set_current_user( $cuser );
  38  
  39          $this->assertEquals( array( 'adminsonly' ), bp_xprofile_get_hidden_field_types_for_user( $duser, bp_loggedin_user_id() ) );
  40  
  41          $this->set_current_user( $old_current_user );
  42      }
  43  
  44  	public function test_get_hidden_field_types_for_user_admin() {
  45          $duser = self::factory()->user->create();
  46          $cuser = self::factory()->user->create();
  47          $this->grant_bp_moderate( $cuser );
  48  
  49          $old_current_user = bp_loggedin_user_id();
  50          $this->set_current_user( $cuser );
  51  
  52          $this->assertEquals( array(), bp_xprofile_get_hidden_field_types_for_user( $duser, bp_loggedin_user_id() ) );
  53  
  54          $this->revoke_bp_moderate( $cuser );
  55          $this->set_current_user( $old_current_user );
  56      }
  57  
  58      /**
  59       * @group bp_xprofile_update_meta
  60       * @ticket BP5180
  61       */
  62  	public function test_bp_xprofile_update_meta_with_line_breaks() {
  63          $g = self::factory()->xprofile_group->create();
  64          $f = self::factory()->xprofile_field->create( array(
  65              'field_group_id' => $g,
  66          ) );
  67  
  68          $meta_value = 'Foo!
  69  
  70  Bar!';
  71          bp_xprofile_update_meta( $f, 'field', 'linebreak_field', $meta_value );
  72          $this->assertEquals( $meta_value, bp_xprofile_get_meta( $f, 'field', 'linebreak_field' ) );
  73      }
  74  
  75      /**
  76       * @group bp_xprofile_fullname_field_id
  77       * @group cache
  78       */
  79      public function test_bp_xprofile_fullname_field_id_invalidation() {
  80          // Prime the cache
  81          $id = bp_xprofile_fullname_field_id();
  82  
  83          bp_update_option( 'bp-xprofile-fullname-field-name', 'foo' );
  84  
  85          $this->assertFalse( wp_cache_get( 'fullname_field_id', 'bp_xprofile' ) );
  86      }
  87  
  88      /**
  89       * @group xprofile_get_field_visibility_level
  90       */
  91      public function test_bp_xprofile_get_field_visibility_level_missing_params() {
  92          $this->assertSame( '', xprofile_get_field_visibility_level( 0, 1 ) );
  93          $this->assertSame( '', xprofile_get_field_visibility_level( 1, 0 ) );
  94      }
  95  
  96      /**
  97       * @group xprofile_get_field_visibility_level
  98       */
  99      public function test_bp_xprofile_get_field_visibility_level_user_set() {
 100          $u = self::factory()->user->create();
 101          $g = self::factory()->xprofile_group->create();
 102          $f = self::factory()->xprofile_field->create( array(
 103              'field_group_id' => $g,
 104          ) );
 105  
 106          bp_xprofile_update_meta( $f, 'field', 'default_visibility', 'adminsonly' );
 107          bp_xprofile_update_meta( $f, 'field', 'allow_custom_visibility', 'allowed' );
 108  
 109          xprofile_set_field_visibility_level( $f, $u, 'loggedin' );
 110  
 111          $this->assertSame( 'loggedin', xprofile_get_field_visibility_level( $f, $u ) );
 112      }
 113  
 114      /**
 115       * @group xprofile_get_field_visibility_level
 116       */
 117      public function test_bp_xprofile_get_field_visibility_level_user_unset() {
 118          $u = self::factory()->user->create();
 119          $g = self::factory()->xprofile_group->create();
 120          $f = self::factory()->xprofile_field->create( array(
 121              'field_group_id' => $g,
 122          ) );
 123  
 124          bp_xprofile_update_meta( $f, 'field', 'default_visibility', 'adminsonly' );
 125          bp_xprofile_update_meta( $f, 'field', 'allow_custom_visibility', 'allowed' );
 126  
 127          $this->assertSame( 'adminsonly', xprofile_get_field_visibility_level( $f, $u ) );
 128  
 129      }
 130  
 131      /**
 132       * @group xprofile_get_field_visibility_level
 133       */
 134      public function test_bp_xprofile_get_field_visibility_level_admin_override() {
 135          $u = self::factory()->user->create();
 136          $g = self::factory()->xprofile_group->create();
 137          $f = self::factory()->xprofile_field->create( array(
 138              'field_group_id' => $g,
 139          ) );
 140  
 141          bp_xprofile_update_meta( $f, 'field', 'default_visibility', 'adminsonly' );
 142          bp_xprofile_update_meta( $f, 'field', 'allow_custom_visibility', 'disabled' );
 143  
 144          xprofile_set_field_visibility_level( $f, $u, 'loggedin' );
 145  
 146          $this->assertSame( 'adminsonly', xprofile_get_field_visibility_level( $f, $u ) );
 147      }
 148  
 149      /**
 150       * @group xprofilemeta
 151       * @group bp_xprofile_delete_meta
 152       */
 153  	public function test_bp_xprofile_delete_meta_empty_object_id() {
 154          $this->assertFalse( bp_xprofile_delete_meta( '', 'group' ) );
 155      }
 156  
 157      /**
 158       * @group xprofilemeta
 159       * @group bp_xprofile_delete_meta
 160       */
 161      public function test_bp_xprofile_delete_meta_empty_object_type() {
 162          $this->assertFalse( bp_xprofile_delete_meta( 1, '' ) );
 163      }
 164  
 165      /**
 166       * @group xprofilemeta
 167       * @group bp_xprofile_delete_meta
 168       */
 169      public function test_bp_xprofile_delete_meta_illegal_object_type() {
 170          $this->assertFalse( bp_xprofile_delete_meta( 1, 'foo' ) );
 171      }
 172  
 173      /**
 174       * @group xprofilemeta
 175       * @group bp_xprofile_delete_meta
 176       * @ticket BP5399
 177       */
 178      public function test_bp_xprofile_delete_meta_illegal_characters() {
 179          $g = self::factory()->xprofile_group->create();
 180          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 181          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 182  
 183          $krazy_key = ' f!@#$%^o *(){}o?+';
 184          bp_xprofile_delete_meta( $g, 'group', $krazy_key );
 185          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 186      }
 187  
 188      /**
 189       * @group xprofilemeta
 190       * @group bp_xprofile_delete_meta
 191       * @ticket BP5399
 192       */
 193  	public function test_bp_xprofile_delete_meta_trim_meta_value() {
 194          $g = self::factory()->xprofile_group->create();
 195          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 196          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 197  
 198          bp_xprofile_delete_meta( $g, 'group', 'foo', ' bar  ' );
 199          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 200      }
 201  
 202      /**
 203       * @group xprofilemeta
 204       * @group bp_xprofile_delete_meta
 205       */
 206  	public function test_bp_xprofile_delete_meta_meta_value_match() {
 207          $g = self::factory()->xprofile_group->create();
 208          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 209          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 210          $this->assertTrue( bp_xprofile_delete_meta( $g, 'group', 'foo', 'bar' ) );
 211          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 212      }
 213  
 214      /**
 215       * @group xprofilemeta
 216       * @group bp_xprofile_delete_meta
 217       */
 218  	public function test_bp_xprofile_delete_meta_delete_all() {
 219          $g = self::factory()->xprofile_group->create();
 220          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 221          bp_xprofile_update_meta( $g, 'group', 'foo2', 'bar' );
 222          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 223          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
 224  
 225          $this->assertTrue( bp_xprofile_delete_meta( $g, 'group' ) );
 226  
 227          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 228          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo2' ) );
 229      }
 230  
 231      /**
 232       * @group xprofilemeta
 233       * @group bp_xprofile_delete_meta
 234       */
 235      public function test_bp_xprofile_delete_meta_with_delete_all_but_no_meta_key() {
 236          // With no meta key, don't delete for all items - just delete
 237          // all for a single item
 238          $g1 = self::factory()->xprofile_group->create();
 239          $g2 = self::factory()->xprofile_group->create();
 240          bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
 241          bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
 242          bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
 243          bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
 244  
 245          $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', '', '', true ) );
 246          $this->assertEmpty( bp_xprofile_get_meta( $g1, 'group' ) );
 247          $this->assertSame( 'bar', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
 248          $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
 249      }
 250  
 251      /**
 252       * @group xprofilemeta
 253       * @group bp_xprofile_delete_meta
 254       */
 255  	public function test_bp_xprofile_delete_meta_with_delete_all() {
 256          // With no meta key, don't delete for all items - just delete
 257          // all for a single item
 258          $g1 = self::factory()->xprofile_group->create();
 259          $g2 = self::factory()->xprofile_group->create();
 260          bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
 261          bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
 262          bp_xprofile_add_meta( $g2, 'group', 'foo', 'bar' );
 263          bp_xprofile_add_meta( $g2, 'group', 'foo1', 'bar1' );
 264  
 265          $this->assertTrue( bp_xprofile_delete_meta( $g1, 'group', 'foo', '', true ) );
 266          $this->assertSame( '', bp_xprofile_get_meta( $g1, 'group', 'foo' ) );
 267          $this->assertSame( '', bp_xprofile_get_meta( $g2, 'group', 'foo' ) );
 268          $this->assertSame( 'bar1', bp_xprofile_get_meta( $g1, 'group', 'foo1' ) );
 269          $this->assertSame( 'bar1', bp_xprofile_get_meta( $g2, 'group', 'foo1' ) );
 270      }
 271  
 272      /**
 273       * @group xprofilemeta
 274       * @group bp_xprofile_get_meta
 275       */
 276  	public function test_bp_xprofile_get_meta_empty_object_id() {
 277          $this->assertFalse( bp_xprofile_get_meta( 0, 'group' ) );
 278      }
 279  
 280      /**
 281       * @group xprofilemeta
 282       * @group bp_xprofile_get_meta
 283       */
 284  	public function test_bp_xprofile_get_meta_empty_object_type() {
 285          $this->assertFalse( bp_xprofile_get_meta( 1, '' ) );
 286      }
 287  
 288      /**
 289       * @group xprofilemeta
 290       * @group bp_xprofile_get_meta
 291       */
 292  	public function test_bp_xprofile_get_meta_illegal_object_type() {
 293          $this->assertFalse( bp_xprofile_get_meta( 1, 'foo' ) );
 294      }
 295  
 296      /**
 297       * @group xprofilemeta
 298       * @group bp_xprofile_get_meta
 299       */
 300  	public function test_bp_xprofile_get_meta_no_meta_key() {
 301          $g = self::factory()->xprofile_group->create();
 302          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 303          bp_xprofile_update_meta( $g, 'group', 'foo2', 'bar' );
 304  
 305          $expected = array(
 306              'foo' => array(
 307                  'bar',
 308              ),
 309              'foo2' => array(
 310                  'bar',
 311              ),
 312          );
 313          $this->assertSame( $expected, bp_xprofile_get_meta( $g, 'group' ) );
 314      }
 315  
 316      /**
 317       * @group xprofilemeta
 318       * @group bp_xprofile_get_meta
 319       */
 320  	public function test_bp_xprofile_get_meta_single_true() {
 321          $g = self::factory()->xprofile_group->create();
 322          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 323          bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
 324          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) ); // default is true
 325          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo', true ) );
 326      }
 327  
 328      /**
 329       * @group xprofilemeta
 330       * @group bp_xprofile_get_meta
 331       */
 332  	public function test_bp_xprofile_get_meta_single_false() {
 333          $g = self::factory()->xprofile_group->create();
 334          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 335          bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
 336          $this->assertSame( array( 'bar', 'baz' ), bp_xprofile_get_meta( $g, 'group', 'foo', false ) );
 337      }
 338  
 339      /**
 340       * @group xprofilemeta
 341       * @group bp_xprofile_get_meta
 342       */
 343      public function test_bp_xprofile_get_meta_no_meta_key_no_results() {
 344          $g = self::factory()->xprofile_group->create();
 345  
 346          $expected = array();
 347          $this->assertSame( $expected, bp_xprofile_get_meta( $g, 'group' ) );
 348      }
 349  
 350      /**
 351       * @group xprofilemeta
 352       * @group bp_xprofile_update_meta
 353       */
 354  	public function test_bp_xprofile_update_meta_no_object_id() {
 355          $this->assertFalse( bp_xprofile_update_meta( 0, 'group', 'foo', 'bar' ) );
 356      }
 357  
 358      /**
 359       * @group xprofilemeta
 360       * @group bp_xprofile_update_meta
 361       */
 362  	public function test_bp_xprofile_update_meta_no_object_type() {
 363          $this->assertFalse( bp_xprofile_update_meta( 1, '', 'foo', 'bar' ) );
 364      }
 365  
 366      /**
 367       * @group xprofilemeta
 368       * @group bp_xprofile_update_meta
 369       */
 370      public function test_bp_xprofile_update_meta_illegal_object_type() {
 371          $this->assertFalse( bp_xprofile_update_meta( 1, 'foo', 'foo', 'bar' ) );
 372      }
 373  
 374      /**
 375       * @group xprofilemeta
 376       * @group bp_xprofile_update_meta
 377       * @ticket BP5399
 378       */
 379      public function test_bp_xprofile_update_meta_illegal_characters() {
 380          $g = self::factory()->xprofile_group->create();
 381          $krazy_key = ' f!@#$%^o *(){}o?+';
 382          bp_xprofile_update_meta( $g, 'group', $krazy_key, 'bar' );
 383          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 384      }
 385  
 386      /**
 387       * @group xprofilemeta
 388       * @group bp_xprofile_update_meta
 389       */
 390  	public function test_bp_xprofile_update_meta_stripslashes() {
 391          $g = self::factory()->xprofile_group->create();
 392          $v = "Totally \'tubular\'";
 393          bp_xprofile_update_meta( $g, 'group', 'foo', $v );
 394          $this->assertSame( stripslashes( $v ), bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 395      }
 396  
 397      /**
 398       * @group xprofilemeta
 399       * @group bp_xprofile_update_meta
 400       */
 401      public function test_bp_xprofile_update_meta_empty_value_delete() {
 402          $g = self::factory()->xprofile_group->create();
 403          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 404          bp_xprofile_update_meta( $g, 'group', 'foo', '' );
 405          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 406      }
 407  
 408      /**
 409       * @group xprofilemeta
 410       * @group bp_xprofile_update_meta
 411       */
 412  	public function test_bp_xprofile_update_meta_new() {
 413          $g = self::factory()->xprofile_group->create();
 414          $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 415          $this->assertNotEmpty( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' ) );
 416          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 417      }
 418  
 419      /**
 420       * @group xprofilemeta
 421       * @group bp_xprofile_update_meta
 422       */
 423  	public function test_bp_xprofile_update_meta_existing() {
 424          $g = self::factory()->xprofile_group->create();
 425          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 426          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 427          $this->assertTrue( bp_xprofile_update_meta( $g, 'group', 'foo', 'baz' ) );
 428          $this->assertSame( 'baz', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 429      }
 430  
 431      /**
 432       * @group xprofilemeta
 433       * @group bp_xprofile_update_meta
 434       */
 435  	public function test_bp_xprofile_update_meta_same_value() {
 436          $g = self::factory()->xprofile_group->create();
 437          bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
 438          $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 439          $this->assertFalse( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' ) );
 440      }
 441  
 442      /**
 443       * @group xprofilemeta
 444       * @group bp_xprofile_update_meta
 445       */
 446  	public function test_bp_xprofile_update_meta_prev_value() {
 447          $g = self::factory()->xprofile_group->create();
 448          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 449  
 450          // In earlier versions of WordPress, bp_activity_update_meta()
 451          // returns true even on failure. However, we know that in these
 452          // cases the update is failing as expected, so we skip this
 453          // assertion just to keep our tests passing
 454          // See https://core.trac.wordpress.org/ticket/24933
 455          if ( version_compare( $GLOBALS['wp_version'], '3.7', '>=' ) ) {
 456              $this->assertFalse( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar2', 'baz' ) );
 457          }
 458  
 459          $this->assertTrue( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar2', 'bar' ) );
 460      }
 461  
 462      /**
 463       * @group xprofilemeta
 464       * @group bp_xprofile_update_meta
 465       * @ticket BP5919
 466       */
 467      public function test_bp_xprofile_update_meta_where_sql_filter_keywords_are_in_quoted_value() {
 468          $g = self::factory()->xprofile_group->create();
 469          $value = "SELECT object_id FROM wp_bp_xprofile_groups WHERE \"foo\" VALUES (foo = 'bar'";
 470          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 471          bp_xprofile_update_meta( $g, 'group', 'foo', $value );
 472          $this->assertSame( $value, bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 473      }
 474  
 475      /**
 476       * @group xprofilemeta
 477       * @group bp_xprofile_update_meta
 478       * @ticket BP5919
 479       */
 480      public function test_bp_xprofile_update_meta_where_meta_id_is_in_quoted_value() {
 481          $g = self::factory()->xprofile_group->create();
 482          $value = "foo meta_id bar";
 483          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 484          bp_xprofile_update_meta( $g, 'group', 'foo', $value );
 485          $this->assertSame( $value, bp_xprofile_get_meta( $g, 'group', 'foo' ) );
 486      }
 487  
 488      /**
 489       * @group xprofilemeta
 490       * @group bp_xprofile_add_meta
 491       */
 492  	public function test_bp_xprofile_add_meta_no_meta_key() {
 493          $this->assertFalse( bp_xprofile_add_meta( 1, 'group', '', 'bar' ) );
 494      }
 495  
 496      /**
 497       * @group xprofilemeta
 498       * @group bp_xprofile_add_meta
 499       */
 500  	public function test_bp_xprofile_add_meta_empty_object_id() {
 501          $this->assertFalse( bp_xprofile_add_meta( 0, 'group', 'foo', 'bar' ) );
 502      }
 503  
 504      /**
 505       * @group xprofilemeta
 506       * @group bp_xprofile_add_meta
 507       */
 508  	public function test_bp_xprofile_add_meta_existing_unique() {
 509          $g = self::factory()->xprofile_group->create();
 510          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 511          $this->assertFalse( bp_xprofile_add_meta( $g, 'group', 'foo', 'baz', true ) );
 512      }
 513  
 514      /**
 515       * @group xprofilemeta
 516       * @group bp_xprofile_add_meta
 517       */
 518  	public function test_bp_xprofile_add_meta_existing_not_unique() {
 519          $g = self::factory()->xprofile_group->create();
 520          bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
 521          $this->assertNotEmpty( bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' ) );
 522      }
 523  
 524      /**
 525       * @group bp_get_member_profile_data
 526       */
 527  	public function test_bp_get_member_profile_data_inside_loop() {
 528          $u = self::factory()->user->create();
 529          $g = self::factory()->xprofile_group->create();
 530          $f = self::factory()->xprofile_field->create( array(
 531              'field_group_id' => $g,
 532              'name' => 'Neato',
 533          ) );
 534          xprofile_set_field_data( $f, $u, 'foo' );
 535  
 536          if ( bp_has_members() ) : while ( bp_members() ) : bp_the_member();
 537          $found = bp_get_member_profile_data( array(
 538              'user_id' => $u,
 539              'field' => 'Neato',
 540          ) );
 541          endwhile; endif;
 542  
 543          // Cleanup
 544          unset( $GLOBALS['members_template'] );
 545  
 546          $this->assertSame( 'foo', $found );
 547      }
 548      /**
 549       * @group bp_get_member_profile_data
 550       */
 551      public function test_bp_get_member_profile_data_outside_of_loop() {
 552          $u = self::factory()->user->create();
 553          $g = self::factory()->xprofile_group->create();
 554          $f = self::factory()->xprofile_field->create( array(
 555              'field_group_id' => $g,
 556              'name' => 'Kewl',
 557          ) );
 558          xprofile_set_field_data( $f, $u, 'foo' );
 559  
 560          $found = bp_get_member_profile_data( array(
 561              'user_id' => $u,
 562              'field' => 'Kewl',
 563          ) );
 564  
 565          $this->assertSame( 'foo', $found );
 566      }
 567  
 568      /**
 569       * @group xprofile_set_field_data
 570       */
 571  	public function test_get_field_data_integer_zero() {
 572          $u = self::factory()->user->create();
 573          $g = self::factory()->xprofile_group->create();
 574          $f = self::factory()->xprofile_field->create( array(
 575              'field_group_id' => $g,
 576              'type' => 'number',
 577              'name' => 'Pens',
 578          ) );
 579          xprofile_set_field_data( $f, $u, 0 );
 580  
 581          $this->assertEquals( 0, xprofile_get_field_data( 'Pens', $u ) );
 582      }
 583  
 584      /**
 585       * @group xprofile_set_field_data
 586       * @ticket BP5836
 587       */
 588  	public function test_xprofile_sync_bp_profile_new_user() {
 589          $post_vars = $_POST;
 590  
 591          $_POST = array(
 592              'user_login' => 'foobar',
 593              'pass1'      => 'password',
 594              'pass2'      => 'password',
 595              'role'       => 'subscriber',
 596              'email'      => 'foo@bar.com',
 597              'first_name' => 'Foo',
 598              'last_name'  => 'Bar',
 599          );
 600  
 601          $id = add_user();
 602  
 603          $display_name = 'Bar Foo';
 604  
 605          $_POST = array(
 606              'display_name' => $display_name,
 607              'email' => 'foo@bar.com',
 608              'nickname' => 'foobar',
 609          );
 610  
 611          $id = edit_user( $id );
 612  
 613          // clean up post vars
 614          $_POST = $post_vars;
 615  
 616          $this->assertEquals( $display_name, xprofile_get_field_data( bp_xprofile_fullname_field_id(), $id ) );
 617      }
 618  
 619      /**
 620       * @group xprofile_insert_field
 621       */
 622  	public function test_xprofile_insert_field_type_option() {
 623          $g = self::factory()->xprofile_group->create();
 624          $parent = self::factory()->xprofile_field->create( array(
 625              'field_group_id' => $g,
 626              'type' => 'selectbox',
 627              'name' => 'Parent',
 628          ) );
 629  
 630          $f = xprofile_insert_field( array(
 631              'field_group_id' => $g,
 632              'parent_id' => $parent,
 633              'type' => 'option',
 634              'name' => 'Option 1',
 635              'field_order' => 5,
 636          ) );
 637  
 638          $this->assertNotEmpty( $f );
 639      }
 640  
 641      /**
 642       * @group xprofile_insert_field
 643       * @ticket BP6354
 644       */
 645      public function test_xprofile_insert_field_should_process_falsey_values_for_boolean_params_on_existing_fields() {
 646          $g = self::factory()->xprofile_group->create();
 647          $f = xprofile_insert_field( array(
 648              'field_group_id' => $g,
 649              'type' => 'textbox',
 650              'name' => 'Foo',
 651              'is_required' => true,
 652              'can_delete' => true,
 653              'is_default_option' => true,
 654              'parent_id' => 13,
 655              'field_order' => 5,
 656              'option_order' => 8,
 657              'description' => 'foo',
 658              'order_by' => 'custom',
 659          ) );
 660  
 661          $this->assertNotEmpty( $f );
 662  
 663          $field = new BP_XProfile_Field( $f );
 664          $this->assertEquals( 1, $field->is_required );
 665          $this->assertEquals( 1, $field->can_delete );
 666          $this->assertEquals( 1, $field->is_default_option );
 667          $this->assertEquals( 13, $field->parent_id );
 668          $this->assertEquals( 5, $field->field_order );
 669          $this->assertEquals( 8, $field->option_order );
 670          $this->assertEquals( 'foo', $field->description );
 671          $this->assertEquals( 'custom', $field->order_by );
 672  
 673          $f = xprofile_insert_field( array(
 674              'field_group_id' => $g,
 675              'type' => 'textbox',
 676              'name' => 'Foo',
 677              'is_required' => false,
 678              'can_delete' => false,
 679              'is_default_option' => false,
 680              'parent_id' => 0,
 681              'field_order' => 0,
 682              'option_order' => 0,
 683              'description' => '',
 684              'order_by' => '',
 685          ) );
 686  
 687          $this->assertNotEmpty( $f );
 688  
 689          $field = new BP_XProfile_Field( $f );
 690          $this->assertEquals( 0, $field->is_required );
 691          $this->assertEquals( 0, $field->can_delete );
 692          $this->assertEquals( 0, $field->is_default_option );
 693          $this->assertEquals( 0, $field->parent_id );
 694          $this->assertEquals( 0, $field->field_order );
 695          $this->assertEquals( 0, $field->option_order );
 696          $this->assertEquals( '', $field->description );
 697          $this->assertEquals( '', $field->order_by );
 698      }
 699  
 700      /**
 701       * @group xprofile_insert_field
 702       */
 703      public function test_xprofile_insert_field_type_option_option_order() {
 704          $g = self::factory()->xprofile_group->create();
 705          $parent = self::factory()->xprofile_field->create( array(
 706              'field_group_id' => $g,
 707              'type' => 'selectbox',
 708              'name' => 'Parent',
 709          ) );
 710  
 711          $f = xprofile_insert_field( array(
 712              'field_group_id' => $g,
 713              'parent_id' => $parent,
 714              'type' => 'option',
 715              'name' => 'Option 1',
 716              'option_order' => 5,
 717          ) );
 718  
 719          $field = new BP_XProfile_Field( $f );
 720  
 721          $this->assertEquals( 5, $field->option_order );
 722      }
 723  
 724      /**
 725       * @group xprofile_insert_field
 726       * @ticket BP6137
 727       */
 728      public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_new_option() {
 729          $g = self::factory()->xprofile_group->create();
 730          $parent = self::factory()->xprofile_field->create( array(
 731              'field_group_id' => $g,
 732              'type' => 'selectbox',
 733              'name' => 'Parent',
 734          ) );
 735  
 736          $f = xprofile_insert_field( array(
 737              'field_group_id' => $g,
 738              'parent_id' => $parent,
 739              'type' => 'option',
 740              'name' => 'Option 1',
 741              'field_order' => 5,
 742              'is_default_option' => false,
 743          ) );
 744  
 745          $this->assertNotEmpty( $f );
 746          $field = new BP_XProfile_Field( $f );
 747          $this->assertEquals( 0, $field->is_default_option );
 748      }
 749  
 750      /**
 751       * @group xprofile_insert_field
 752       * @ticket BP6137
 753       */
 754      public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_new_option() {
 755          $g = self::factory()->xprofile_group->create();
 756          $parent = self::factory()->xprofile_field->create( array(
 757              'field_group_id' => $g,
 758              'type' => 'selectbox',
 759              'name' => 'Parent',
 760          ) );
 761  
 762          $f = xprofile_insert_field( array(
 763              'field_group_id' => $g,
 764              'parent_id' => $parent,
 765              'type' => 'option',
 766              'name' => 'Option 1',
 767              'field_order' => 5,
 768              'is_default_option' => true,
 769          ) );
 770  
 771          $this->assertNotEmpty( $f );
 772          $field = new BP_XProfile_Field( $f );
 773          $this->assertEquals( 1, $field->is_default_option );
 774      }
 775  
 776      /**
 777       * @group xprofile_insert_field
 778       * @ticket BP6137
 779       */
 780      public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_existing_option() {
 781          $g = self::factory()->xprofile_group->create();
 782          $parent = self::factory()->xprofile_field->create( array(
 783              'field_group_id' => $g,
 784              'type' => 'selectbox',
 785              'name' => 'Parent',
 786          ) );
 787  
 788          $f = xprofile_insert_field( array(
 789              'field_group_id' => $g,
 790              'parent_id' => $parent,
 791              'type' => 'option',
 792              'name' => 'Option 1',
 793              'field_order' => 5,
 794              'is_default_option' => true,
 795          ) );
 796  
 797          $this->assertNotEmpty( $f );
 798          $field = new BP_XProfile_Field( $f );
 799          $this->assertEquals( 1, $field->is_default_option );
 800  
 801          $f = xprofile_insert_field( array(
 802              'field_id' => $f,
 803              'field_group_id' => $g,
 804              'type' => 'textbox',
 805              'is_default_option' => false,
 806          ) );
 807  
 808          $field2 = new BP_XProfile_Field( $f );
 809          $this->assertEquals( 0, $field2->is_default_option );
 810      }
 811  
 812      /**
 813       * @group xprofile_insert_field
 814       * @ticket BP6137
 815       */
 816      public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_existing_option() {
 817          $g = self::factory()->xprofile_group->create();
 818          $parent = self::factory()->xprofile_field->create( array(
 819              'field_group_id' => $g,
 820              'type' => 'selectbox',
 821              'name' => 'Parent',
 822          ) );
 823  
 824          $f = xprofile_insert_field( array(
 825              'field_group_id' => $g,
 826              'parent_id' => $parent,
 827              'type' => 'option',
 828              'name' => 'Option 1',
 829              'field_order' => 5,
 830              'is_default_option' => false,
 831          ) );
 832  
 833          $this->assertNotEmpty( $f );
 834          $field = new BP_XProfile_Field( $f );
 835          $this->assertEquals( 0, $field->is_default_option );
 836  
 837          $f = xprofile_insert_field( array(
 838              'field_id' => $f,
 839              'field_group_id' => $g,
 840              'type' => 'textbox',
 841              'is_default_option' => true,
 842          ) );
 843  
 844          $field2 = new BP_XProfile_Field( $f );
 845  
 846          $this->assertEquals( 1, $field2->is_default_option );
 847      }
 848  
 849      /**
 850       * @group xprofile_update_field_group_position
 851       * @group bp_profile_get_field_groups
 852       */
 853      public function test_bp_profile_get_field_groups_update_position() {
 854          $g1 = self::factory()->xprofile_group->create();
 855          $g2 = self::factory()->xprofile_group->create();
 856          $g3 = self::factory()->xprofile_group->create();
 857  
 858          // prime the cache
 859          bp_profile_get_field_groups();
 860  
 861          // switch the field group positions for the last two groups
 862          xprofile_update_field_group_position( $g2, 3 );
 863          xprofile_update_field_group_position( $g3, 2 );
 864  
 865          // now refetch field groups
 866          $field_groups = bp_profile_get_field_groups();
 867  
 868          // assert!
 869          $this->assertEquals( array( 1, $g1, $g3, $g2 ), wp_list_pluck( $field_groups, 'id' ) );
 870      }
 871  
 872      /**
 873       * @ticket BP6638
 874       */
 875      public function test_xprofile_get_field_should_return_bp_xprofile_field_object() {
 876          global $wpdb;
 877  
 878          $g = self::factory()->xprofile_group->create();
 879          $f = self::factory()->xprofile_field->create( array(
 880              'field_group_id' => $g,
 881              'type' => 'selectbox',
 882              'name' => 'Foo',
 883          ) );
 884  
 885          $field = xprofile_get_field( $f );
 886  
 887          $this->assertTrue( $field instanceof BP_XProfile_Field );
 888      }
 889  
 890      /**
 891       * @ticket BP6638
 892       * @group cache
 893       */
 894      public function test_xprofile_get_field_should_prime_field_cache() {
 895          global $wpdb;
 896  
 897          $g = self::factory()->xprofile_group->create();
 898          $f = self::factory()->xprofile_field->create( array(
 899              'field_group_id' => $g,
 900              'type' => 'selectbox',
 901              'name' => 'Foo',
 902          ) );
 903  
 904          $num_queries = $wpdb->num_queries;
 905  
 906          // Prime the cache.
 907          $field_1 = xprofile_get_field( $f );
 908          $num_queries++;
 909          $this->assertSame( $num_queries, $wpdb->num_queries );
 910  
 911          // No more queries.
 912          $field_2 = xprofile_get_field( $f );
 913          $this->assertEquals( $field_1, $field_2 );
 914          $this->assertSame( $num_queries, $wpdb->num_queries );
 915      }
 916  
 917      /**
 918       * @ticket BP5625
 919       */
 920      public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_true_for_textareas() {
 921          $g = self::factory()->xprofile_group->create();
 922          $f = self::factory()->xprofile_field->create( array(
 923              'field_group_id' => $g,
 924              'type' => 'textarea',
 925          ) );
 926  
 927          $this->assertTrue( bp_xprofile_is_richtext_enabled_for_field( $f ) );
 928      }
 929  
 930      /**
 931       * @ticket BP5625
 932       */
 933      public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_false_for_non_textareas() {
 934          $g = self::factory()->xprofile_group->create();
 935          $f = self::factory()->xprofile_field->create( array(
 936              'field_group_id' => $g,
 937              'type' => 'radio',
 938          ) );
 939  
 940          $this->assertFalse( bp_xprofile_is_richtext_enabled_for_field( $f ) );
 941      }
 942  
 943      /**
 944       * @group bp_get_field_css_class
 945       */
 946  	public function test_bp_get_field_css_class_empty_param() {
 947          // Fake the global
 948          global $profile_template;
 949          $reset_profile_template = $profile_template;
 950  
 951          $profile_template = new stdClass;
 952          // Avoid the 'alt' class being added
 953          $profile_template->current_field = 2;
 954          $profile_template->field = new stdClass;
 955          $profile_template->field->id = 145;
 956          $profile_template->field->name = 'Pie';
 957          $profile_template->field->type = 'textbox';
 958  
 959          $expected_classes = array(
 960              'optional-field',
 961              'field_' . $profile_template->field->id,
 962              'field_' . sanitize_title( $profile_template->field->name ),
 963              'field_type_' . sanitize_title( $profile_template->field->type ),
 964              'visibility-public'
 965              );
 966  
 967          $classes = bp_get_field_css_class();
 968          preg_match( '/class=["\']?([^"\']*)["\' ]/is', $classes, $matches );
 969          $ret_classes = explode( ' ', $matches[1] );
 970          $this->assertEqualSets( $expected_classes, $ret_classes );
 971  
 972          // Clean up!
 973          $profile_template = $reset_profile_template;
 974      }
 975  
 976      /**
 977       * @group bp_get_field_css_class
 978       */
 979      public function test_bp_get_field_css_class_space_delimited_string() {
 980          // Fake the global
 981          global $profile_template;
 982          $reset_profile_template = $profile_template;
 983  
 984          $profile_template = new stdClass;
 985          // Avoid the 'alt' class being added
 986          $profile_template->current_field = 2;
 987          $profile_template->field = new stdClass;
 988          $profile_template->field->id = 145;
 989          $profile_template->field->name = 'Pie';
 990          $profile_template->field->type = 'textbox';
 991  
 992          $expected_classes = array(
 993              'optional-field',
 994              'field_' . $profile_template->field->id,
 995              'field_' . sanitize_title( $profile_template->field->name ),
 996              'field_type_' . sanitize_title( $profile_template->field->type ),
 997              'visibility-public',
 998              'rhubarb',
 999              'apple'
1000              );
1001  
1002          $classes = bp_get_field_css_class( 'rhubarb apple' );
1003          preg_match( '/class=["\']?([^"\']*)["\' ]/is', $classes, $matches );
1004          $ret_classes = explode( ' ', $matches[1] );
1005          $this->assertEqualSets( $expected_classes, $ret_classes );
1006  
1007          // Clean up!
1008          $profile_template = $reset_profile_template;
1009      }
1010  
1011      /**
1012       * @group bp_get_field_css_class
1013       */
1014  	public function test_bp_get_field_css_class_array() {
1015          // Fake the global
1016          global $profile_template;
1017          $reset_profile_template = $profile_template;
1018  
1019          $profile_template = new stdClass;
1020          // Avoid the 'alt' class being added
1021          $profile_template->current_field = 2;
1022          $profile_template->field = new stdClass;
1023          $profile_template->field->id = 145;
1024          $profile_template->field->name = 'Pie';
1025          $profile_template->field->type = 'textbox';
1026  
1027          $expected_classes = array(
1028              'optional-field',
1029              'field_' . $profile_template->field->id,
1030              'field_' . sanitize_title( $profile_template->field->name ),
1031              'field_type_' . sanitize_title( $profile_template->field->type ),
1032              'visibility-public',
1033              'blueberry',
1034              'gooseberry'
1035              );
1036  
1037          $classes = bp_get_field_css_class( array( 'blueberry', 'gooseberry' ) );
1038          preg_match( '/class=["\']?([^"\']*)["\' ]/is', $classes, $matches );
1039          $ret_classes = explode( ' ', $matches[1] );
1040          $this->assertEqualSets( $expected_classes, $ret_classes );
1041  
1042          // Clean up!
1043          $profile_template = $reset_profile_template;
1044      }
1045  
1046      /**
1047       * @group xprofile_filter_link_profile_data
1048       */
1049      public function test_field_comma_seperated_values_are_autolinked() {
1050          $field_group_id = self::factory()->xprofile_group->create();
1051          $field_id = self::factory()->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
1052          $GLOBALS['field'] = new BP_XProfile_Field( $field_id );
1053          $GLOBALS['field']->do_autolink = true;
1054  
1055          $output = xprofile_filter_link_profile_data( 'Hello world this is a test; with, some, words', 'textbox' );
1056          $regex = '#^Hello world this is a test; with, <a href="([^"]+)" rel="nofollow">some</a>, <a href="([^"]+)" rel="nofollow">words</a>$#i';
1057  
1058          $this->assertRegExp( $regex, $output );
1059          unset( $GLOBALS['field'] );
1060      }
1061  
1062      /**
1063       * @group xprofile_filter_link_profile_data
1064       */
1065      public function test_field_semicolon_seperated_values_are_autolinked() {
1066          $field_group_id = self::factory()->xprofile_group->create();
1067          $field_id = self::factory()->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
1068          $GLOBALS['field'] = new BP_XProfile_Field( $field_id );
1069          $GLOBALS['field']->do_autolink = true;
1070  
1071          $output = xprofile_filter_link_profile_data( 'Hello world this is a test with; some; words', 'textbox' );
1072          $regex = '#^Hello world this is a test with; <a href="([^"]+)" rel="nofollow">some</a>; <a href="([^"]+)" rel="nofollow">words</a>$#i';
1073  
1074          $this->assertRegExp( $regex, $output );
1075          unset( $GLOBALS['field'] );
1076      }
1077  
1078      /**
1079       * @ticket BP7817
1080       * @ticket BP7698
1081       */
1082  	public function test_bp_xprofile_personal_data_exporter() {
1083          $u = self::factory()->user->create();
1084  
1085          $field_group_id = self::factory()->xprofile_group->create();
1086          $f1 = self::factory()->xprofile_field->create(
1087              array(
1088                  'field_group_id' => $field_group_id,
1089              )
1090          );
1091          $f2 = self::factory()->xprofile_field->create(
1092              array(
1093                  'field_group_id' => $field_group_id,
1094                  'type'           => 'checkbox',
1095              )
1096          );
1097  
1098          $option1 = xprofile_insert_field( array(
1099              'field_group_id' => $field_group_id,
1100              'parent_id'      => $f2,
1101              'type'           => 'option',
1102              'name'           => 'Option 1',
1103          ) );
1104  
1105          $option2 = xprofile_insert_field( array(
1106              'field_group_id' => $field_group_id,
1107              'parent_id'      => $f2,
1108              'type'           => 'option',
1109              'name'           => 'Option 2',
1110          ) );
1111  
1112          $option3 = xprofile_insert_field( array(
1113              'field_group_id' => $field_group_id,
1114              'parent_id'      => $f2,
1115              'type'           => 'option',
1116              'name'           => 'Option 3',
1117          ) );
1118  
1119          xprofile_set_field_data( $f1, $u, 'foo' );
1120          xprofile_set_field_data( $f2, $u, array( 'Option 1', 'Option 3' ) );
1121  
1122          $test_user = new WP_User( $u );
1123  
1124          $actual = bp_xprofile_personal_data_exporter( $test_user->user_email );
1125  
1126          $this->assertTrue( $actual['done'] );
1127  
1128          // Number of exported users.
1129          $this->assertSame( 1, count( $actual['data'] ) );
1130  
1131          // Number of exported user properties.
1132          $this->assertSame( 3, count( $actual['data'][0]['data'] ) );
1133      }
1134  
1135      /**
1136       * @ticket BP8175
1137       */
1138      public function test_xprofile_data_should_be_deleted_on_user_delete_non_multisite() {
1139          if ( is_multisite() ) {
1140              $this->markTestSkipped( __METHOD__ . ' requires non-multisite.' );
1141          }
1142  
1143          $u = self::factory()->user->create();
1144  
1145          $fg = self::factory()->xprofile_group->create();
1146          $f1 = self::factory()->xprofile_field->create(
1147              array(
1148                  'field_group_id' => $fg,
1149              )
1150          );
1151  
1152          xprofile_set_field_data( $f1, $u, 'foo' );
1153          $this->assertSame( 'foo', xprofile_get_field_data( $f1, $u ) );
1154  
1155          wp_delete_user( $u );
1156  
1157          $this->assertSame( '', xprofile_get_field_data( $f1, $u ) );
1158      }
1159  
1160      /**
1161       * @ticket BP8175
1162       */
1163      public function test_xprofile_data_should_be_deleted_on_user_delete_multisite() {
1164          if ( ! is_multisite() ) {
1165              $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
1166          }
1167  
1168          $u = self::factory()->user->create();
1169  
1170          $fg = self::factory()->xprofile_group->create();
1171          $f1 = self::factory()->xprofile_field->create(
1172              array(
1173                  'field_group_id' => $fg,
1174              )
1175          );
1176  
1177          xprofile_set_field_data( $f1, $u, 'foo' );
1178          $this->assertSame( 'foo', xprofile_get_field_data( $f1, $u ) );
1179  
1180          wpmu_delete_user( $u );
1181  
1182          $this->assertSame( '', xprofile_get_field_data( $f1, $u ) );
1183      }
1184  
1185      /**
1186       * @ticket BP8175
1187       */
1188      public function test_xprofile_data_should_not_be_deleted_on_wp_delete_user_multisite() {
1189          if ( ! is_multisite() ) {
1190              $this->markTestSkipped( __METHOD__ . ' requires multisite.' );
1191          }
1192  
1193          $u = self::factory()->user->create();
1194  
1195          $fg = self::factory()->xprofile_group->create();
1196          $f1 = self::factory()->xprofile_field->create(
1197              array(
1198                  'field_group_id' => $fg,
1199              )
1200          );
1201  
1202          xprofile_set_field_data( $f1, $u, 'foo' );
1203          $this->assertSame( 'foo', xprofile_get_field_data( $f1, $u ) );
1204  
1205          wp_delete_user( $u );
1206  
1207          $this->assertSame( 'foo', xprofile_get_field_data( $f1, $u ) );
1208      }
1209  
1210      /**
1211       * @ticket BP8568
1212       */
1213      public function test_xprofile_sync_wp_profile_signup_with_wp_first_and_last_name_fields() {
1214          add_filter( 'bp_disable_profile_sync', '__return_true' );
1215  
1216          $u = self::factory()->user->create_and_get(
1217              array(
1218                  'user_login' => 'foobar',
1219                  'user_email' => 'foo@bar.email',
1220              )
1221          );
1222  
1223          $field_fn = self::factory()->xprofile_field->create(
1224              array(
1225                  'field_group_id' => 1,
1226                  'type'           => 'wp-textbox',
1227                  'name'           => 'WP First Name',
1228              )
1229          );
1230  
1231          // Set the WP User Key.
1232          bp_xprofile_update_meta( $field_fn, 'field', 'wp_user_key', 'first_name' );
1233  
1234          $field_ln = self::factory()->xprofile_field->create(
1235              array(
1236                  'field_group_id' => 1,
1237                  'type'           => 'wp-textbox',
1238                  'name'           => 'WP Last Name',
1239              )
1240          );
1241  
1242          // Set the WP User Key.
1243          bp_xprofile_update_meta( $field_ln, 'field', 'wp_user_key', 'last_name' );
1244  
1245          $field_n  = bp_xprofile_fullname_field_id();
1246          $usermeta = array(
1247              'field_' . $field_n  => 'foobar',
1248              'field_' . $field_fn => 'Foo',
1249              'field_' . $field_ln => 'Bar',
1250              'profile_field_ids'  => $field_n . ',' . $field_fn . ',' . $field_ln,
1251          );
1252  
1253          remove_filter( 'bp_disable_profile_sync', '__return_true' );
1254  
1255          // simulates do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
1256          xprofile_sync_wp_profile( $u->ID, $u->user_login, $u->user_pass, $u->user_email, $usermeta );
1257  
1258          $updated_u = get_user_by( 'id', $u->ID );
1259  
1260          $this->assertEquals( 'Foo', $updated_u->first_name );
1261          $this->assertEquals( 'Bar', $updated_u->last_name );
1262      }
1263  
1264      /**
1265       * @ticket BP8568
1266       */
1267      public function test_xprofile_sync_wp_profile_signup_without_wp_first_and_last_name_fields() {
1268          add_filter( 'bp_disable_profile_sync', '__return_true' );
1269  
1270          $u = self::factory()->user->create_and_get(
1271              array(
1272                  'user_login' => 'foobar',
1273                  'user_email' => 'foo@bar.email',
1274              )
1275          );
1276  
1277          $field_n  = bp_xprofile_fullname_field_id();
1278          $usermeta = array(
1279              'field_' . $field_n  => 'foobar',
1280              'profile_field_ids'  => $field_n,
1281          );
1282  
1283          remove_filter( 'bp_disable_profile_sync', '__return_true' );
1284  
1285          // simulates do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
1286          xprofile_sync_wp_profile( $u->ID, $u->user_login, $u->user_pass, $u->user_email, $usermeta );
1287  
1288          $updated_u = get_user_by( 'id', $u->ID );
1289  
1290          $this->assertEquals( 'foobar', $updated_u->first_name );
1291          $this->assertEquals( '', $updated_u->last_name );
1292      }
1293  
1294      /**
1295       * @ticket BP8568
1296       */
1297      public function test_xprofile_sync_wp_profile_activate_signup_with_wp_first_and_last_name_fields() {
1298          add_filter( 'bp_disable_profile_sync', '__return_true' );
1299  
1300          $u = self::factory()->user->create_and_get(
1301              array(
1302                  'user_login' => 'barfoo',
1303                  'user_email' => 'bar@foo.email',
1304              )
1305          );
1306  
1307          $field_fn = self::factory()->xprofile_field->create(
1308              array(
1309                  'field_group_id' => 1,
1310                  'type'           => 'wp-textbox',
1311                  'name'           => 'WP First Name',
1312              )
1313          );
1314  
1315          // Set the WP User Key.
1316          bp_xprofile_update_meta( $field_fn, 'field', 'wp_user_key', 'first_name' );
1317  
1318          $field_ln = self::factory()->xprofile_field->create(
1319              array(
1320                  'field_group_id' => 1,
1321                  'type'           => 'wp-textbox',
1322                  'name'           => 'WP Last Name',
1323              )
1324          );
1325  
1326          // Set the WP User Key.
1327          bp_xprofile_update_meta( $field_ln, 'field', 'wp_user_key', 'last_name' );
1328  
1329          $field_n  = bp_xprofile_fullname_field_id();
1330  
1331          $user = array(
1332              'user_id'  => $u->ID,
1333              'password' => $u->user_pass,
1334              'meta'     => array(
1335                  'field_' . $field_n  => 'barfoo',
1336                  'field_' . $field_fn => 'Bar',
1337                  'field_' . $field_ln => 'Foo',
1338                  'profile_field_ids'  => $field_n . ',' . $field_fn . ',' . $field_ln,
1339              ),
1340          );
1341  
1342          remove_filter( 'bp_disable_profile_sync', '__return_true' );
1343  
1344          // simulates do_action( 'bp_core_activated_user', $user_id, $key, $user );
1345          xprofile_sync_wp_profile( $u->ID, 'randomkey', $user );
1346  
1347          $updated_u = get_user_by( 'id', $u->ID );
1348  
1349          $this->assertEquals( 'Bar', $updated_u->first_name );
1350          $this->assertEquals( 'Foo', $updated_u->last_name );
1351      }
1352  
1353      /**
1354       * @ticket BP8568
1355       */
1356      public function test_xprofile_sync_wp_profile_activate_signup_without_wp_first_and_last_name_fields() {
1357          add_filter( 'bp_disable_profile_sync', '__return_true' );
1358  
1359          $u = self::factory()->user->create_and_get(
1360              array(
1361                  'user_login' => 'barfoo',
1362                  'user_email' => 'bar@foo.email',
1363              )
1364          );
1365  
1366          $field_n  = bp_xprofile_fullname_field_id();
1367  
1368          $user = array(
1369              'user_id'  => $u->ID,
1370              'password' => $u->user_pass,
1371              'meta'     => array(
1372                  'field_' . $field_n  => 'barfoo',
1373                  'profile_field_ids'  => $field_n,
1374              ),
1375          );
1376  
1377          remove_filter( 'bp_disable_profile_sync', '__return_true' );
1378  
1379          // simulates do_action( 'bp_core_activated_user', $user_id, $key, $user );
1380          xprofile_sync_wp_profile( $u->ID, 'randomkey', $user );
1381  
1382          $updated_u = get_user_by( 'id', $u->ID );
1383  
1384          $this->assertEquals( 'barfoo', $updated_u->first_name );
1385          $this->assertEquals( '', $updated_u->last_name );
1386      }
1387  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1