[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/members/ -> class-bp-signup.php (source)

   1  <?php
   2  
   3  /**
   4   * @group members
   5   * @group signups
   6   * @group BP_Signup
   7   */
   8  class BP_Tests_BP_Signup extends BP_UnitTestCase {
   9      protected $signup_allowed;
  10  
  11  	public function setUp() {
  12  
  13          if ( is_multisite() ) {
  14              $this->signup_allowed = get_site_option( 'registration' );
  15              update_site_option( 'registration', 'all' );
  16          } else {
  17              bp_get_option( 'users_can_register' );
  18              bp_update_option( 'users_can_register', 1 );
  19          }
  20  
  21          parent::setUp();
  22      }
  23  
  24  	public function tearDown() {
  25          if ( is_multisite() ) {
  26              update_site_option( 'registration', $this->signup_allowed );
  27          } else {
  28              bp_update_option( 'users_can_register', $this->signup_allowed );
  29          }
  30  
  31          parent::tearDown();
  32      }
  33  
  34      /**
  35       * @group add
  36       */
  37  	public function test_add() {
  38          $time = bp_core_current_time();
  39          $args = array(
  40              'domain' => 'foo',
  41              'path' => 'bar',
  42              'title' => 'Foo bar',
  43              'user_login' => 'user1',
  44              'user_email' => 'user1@example.com',
  45              'registered' => $time,
  46              'activation_key' => '12345',
  47              'meta' => array(
  48                  'field_1' => 'Foo Bar',
  49                  'meta1' => 'meta2',
  50              ),
  51          );
  52  
  53          $signup = BP_Signup::add( $args );
  54          $this->assertNotEmpty( $signup );
  55  
  56          $s = new BP_Signup( $signup );
  57  
  58          // spot check
  59          $this->assertSame( $signup, $s->id );
  60          $this->assertSame( 'user1', $s->user_login );
  61          $this->assertSame( '12345', $s->activation_key );
  62      }
  63  
  64      /**
  65       * @group add
  66       */
  67      public function test_add_no_visibility_level_set_should_use_default_visiblity_level() {
  68          // Update field_1's default visibility to 'adminsonly'.
  69          bp_xprofile_update_field_meta( 1, 'default_visibility', 'adminsonly' );
  70  
  71          // Add new signup without a custom field visibility set for field_1.
  72          $signup = BP_Signup::add( array(
  73              'title' => 'Foo bar',
  74              'user_login' => 'user1',
  75              'user_email' => 'user1@example.com',
  76              'registered' => bp_core_current_time(),
  77              'activation_key' => '12345',
  78              'meta' => array(
  79                  'field_1' => 'Foo Bar',
  80                  'meta1' => 'meta2',
  81                  'password' => 'password',
  82  
  83                  /*
  84                   * Ensure we pass the field ID.
  85                   *
  86                   * See bp_core_activate_signup() and BP_Signup::add_backcompat().
  87                   */
  88                  'profile_field_ids' => '1'
  89              ),
  90          ) );
  91  
  92          // Activate the signup.
  93          $activate = BP_Signup::activate( (array) $signup );
  94  
  95          // Assert that field 1's visibility for the signup is still 'adminsonly'
  96          $vis = xprofile_get_field_visibility_level( 1, $activate['activated'][0] );
  97          $this->assertSame( 'adminsonly', $vis );
  98      }
  99  
 100      /**
 101       * @group get
 102       */
 103  	public function test_get_with_offset() {
 104          $s1 = self::factory()->signup->create();
 105          $s2 = self::factory()->signup->create();
 106          $s3 = self::factory()->signup->create();
 107  
 108          $ss = BP_Signup::get( array(
 109              'offset' => 1,
 110              'fields' => 'ids',
 111          ) );
 112  
 113          $this->assertEquals( array( $s2 ), $ss['signups'] );
 114      }
 115  
 116      /**
 117       * @group get
 118       */
 119  	public function test_get_with_number() {
 120          $s1 = self::factory()->signup->create();
 121          $s2 = self::factory()->signup->create();
 122          $s3 = self::factory()->signup->create();
 123  
 124          $ss = BP_Signup::get( array(
 125              'number' => 2,
 126              'fields' => 'ids',
 127          ) );
 128  
 129          $this->assertEquals( array( $s3, $s2 ), $ss['signups'] );
 130      }
 131  
 132      /**
 133       * @group get
 134       */
 135  	public function test_get_with_usersearch() {
 136          $s1 = self::factory()->signup->create( array(
 137              'user_email' => 'fghij@example.com',
 138          ) );
 139          $s2 = self::factory()->signup->create();
 140          $s3 = self::factory()->signup->create();
 141  
 142          $ss = BP_Signup::get( array(
 143              'usersearch' => 'ghi',
 144              'fields' => 'ids',
 145          ) );
 146  
 147          $this->assertEquals( array( $s1 ), $ss['signups'] );
 148      }
 149  
 150      /**
 151       * @group get
 152       */
 153  	public function test_get_with_orderby_email() {
 154          $s1 = self::factory()->signup->create( array(
 155              'user_email' => 'fghij@example.com',
 156          ) );
 157          $s2 = self::factory()->signup->create( array(
 158              'user_email' => 'abcde@example.com',
 159          ) );
 160          $s3 = self::factory()->signup->create( array(
 161              'user_email' => 'zzzzz@example.com',
 162          ) );
 163  
 164          $ss = BP_Signup::get( array(
 165              'orderby' => 'email',
 166              'number' => 3,
 167              'fields' => 'ids',
 168          ) );
 169  
 170          // default order is DESC.
 171          $this->assertEquals( array( $s3, $s1, $s2 ), $ss['signups'] );
 172      }
 173  
 174      /**
 175       * @group get
 176       */
 177  	public function test_get_with_orderby_email_asc() {
 178          $s1 = self::factory()->signup->create( array(
 179              'user_email' => 'fghij@example.com',
 180          ) );
 181          $s2 = self::factory()->signup->create( array(
 182              'user_email' => 'abcde@example.com',
 183          ) );
 184          $s3 = self::factory()->signup->create( array(
 185              'user_email' => 'zzzzz@example.com',
 186          ) );
 187  
 188          $ss = BP_Signup::get( array(
 189              'orderby' => 'email',
 190              'number' => 3,
 191              'order' => 'ASC',
 192              'fields' => 'ids',
 193          ) );
 194  
 195          $this->assertEquals( array( $s2, $s1, $s3 ), $ss['signups'] );
 196      }
 197  
 198      /**
 199       * @group get
 200       */
 201  	public function test_get_with_orderby_login_asc() {
 202          $s1 = self::factory()->signup->create( array(
 203              'user_login' => 'fghij',
 204          ) );
 205          $s2 = self::factory()->signup->create( array(
 206              'user_login' => 'abcde',
 207          ) );
 208          $s3 = self::factory()->signup->create( array(
 209              'user_login' => 'zzzzz',
 210          ) );
 211  
 212          $ss = BP_Signup::get( array(
 213              'orderby' => 'login',
 214              'number' => 3,
 215              'order' => 'ASC',
 216              'fields' => 'ids',
 217          ) );
 218  
 219          $this->assertEquals( array( $s2, $s1, $s3 ), $ss['signups'] );
 220      }
 221  
 222      /**
 223       * @group get
 224       */
 225  	public function test_get_with_orderby_registered_asc() {
 226          $now = time();
 227  
 228          $s1 = self::factory()->signup->create( array(
 229              'registered' => date( 'Y-m-d H:i:s', $now - 50 ),
 230          ) );
 231          $s2 = self::factory()->signup->create( array(
 232              'registered' => date( 'Y-m-d H:i:s', $now - 100 ),
 233          ) );
 234          $s3 = self::factory()->signup->create( array(
 235              'registered' => date( 'Y-m-d H:i:s', $now - 10 ),
 236          ) );
 237  
 238          $ss = BP_Signup::get( array(
 239              'orderby' => 'registered',
 240              'number' => 3,
 241              'order' => 'ASC',
 242              'fields' => 'ids',
 243          ) );
 244  
 245          $this->assertEquals( array( $s2, $s1, $s3 ), $ss['signups'] );
 246      }
 247  
 248      /**
 249       * @group get
 250       */
 251  	public function test_get_with_include() {
 252          $s1 = self::factory()->signup->create();
 253          $s2 = self::factory()->signup->create();
 254          $s3 = self::factory()->signup->create();
 255  
 256          $ss = BP_Signup::get( array(
 257              'include' => array( $s1, $s3 ),
 258              'fields' => 'ids',
 259          ) );
 260  
 261          $this->assertEquals( array( $s1, $s3 ), $ss['signups'] );
 262      }
 263  
 264      /**
 265       * @group get
 266       */
 267  	public function test_get_with_activation_key() {
 268          $s1 = self::factory()->signup->create( array(
 269              'activation_key' => 'foo',
 270          ) );
 271          $s2 = self::factory()->signup->create( array(
 272              'activation_key' => 'bar',
 273          ) );
 274          $s3 = self::factory()->signup->create( array(
 275              'activation_key' => 'baz',
 276          ) );
 277  
 278          $ss = BP_Signup::get( array(
 279              'activation_key' => 'bar',
 280              'fields' => 'ids',
 281          ) );
 282  
 283          $this->assertEquals( array( $s2 ), $ss['signups'] );
 284      }
 285  
 286      /**
 287       * @group get
 288       */
 289  	public function test_get_with_user_login() {
 290          $s1 = self::factory()->signup->create( array(
 291              'user_login' => 'aaaafoo',
 292          ) );
 293          $s2 = self::factory()->signup->create( array(
 294              'user_login' => 'zzzzfoo',
 295          ) );
 296          $s3 = self::factory()->signup->create( array(
 297              'user_login' => 'jjjjfoo',
 298          ) );
 299  
 300          $ss = BP_Signup::get( array(
 301              'user_login' => 'zzzzfoo',
 302              'fields' => 'ids',
 303          ) );
 304  
 305          $this->assertEquals( array( $s2 ), $ss['signups'] );
 306      }
 307  
 308      /**
 309       * @group activate
 310       */
 311  	public function test_activate_user_accounts() {
 312          $signups = array();
 313  
 314          $signups['accountone'] = self::factory()->signup->create( array(
 315              'user_login'     => 'accountone',
 316              'user_email'     => 'accountone@example.com',
 317              'activation_key' => 'activationkeyone',
 318          ) );
 319  
 320          $signups['accounttwo'] = self::factory()->signup->create( array(
 321              'user_login'     => 'accounttwo',
 322              'user_email'     => 'accounttwo@example.com',
 323              'activation_key' => 'activationkeytwo',
 324          ) );
 325  
 326          $signups['accountthree'] = self::factory()->signup->create( array(
 327              'user_login'     => 'accountthree',
 328              'user_email'     => 'accountthree@example.com',
 329              'activation_key' => 'activationkeythree',
 330          ) );
 331  
 332          $results = BP_Signup::activate( $signups );
 333          $this->assertNotEmpty( $results['activated'] );
 334  
 335          $users = array();
 336  
 337          foreach ( $signups as $login => $signup_id  ) {
 338              $users[ $login ] = get_user_by( 'login', $login );
 339          }
 340  
 341          $this->assertEqualSets( $results['activated'], wp_list_pluck( $users, 'ID' ) );
 342      }
 343  
 344      /**
 345       * @group get
 346       */
 347  	public function test_get_signup_ids_only() {
 348          $s1 = self::factory()->signup->create();
 349          $s2 = self::factory()->signup->create();
 350          $s3 = self::factory()->signup->create();
 351  
 352          $ss = BP_Signup::get( array(
 353              'number' => 3,
 354              'fields' => 'ids',
 355          ) );
 356  
 357          $this->assertEquals( array( $s3, $s2, $s1 ), $ss['signups'] );
 358      }
 359  }


Generated: Thu Sep 24 01:03:44 2020 Cross-referenced by PHPXref 0.7.1