[ 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 visiblity 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_include() {
 202          $s1 = self::factory()->signup->create();
 203          $s2 = self::factory()->signup->create();
 204          $s3 = self::factory()->signup->create();
 205  
 206          $ss = BP_Signup::get( array(
 207              'include' => array( $s1, $s3 ),
 208              'fields' => 'ids',
 209          ) );
 210  
 211          $this->assertEquals( array( $s1, $s3 ), $ss['signups'] );
 212      }
 213  
 214      /**
 215       * @group get
 216       */
 217  	public function test_get_with_activation_key() {
 218          $s1 = self::factory()->signup->create( array(
 219              'activation_key' => 'foo',
 220          ) );
 221          $s2 = self::factory()->signup->create( array(
 222              'activation_key' => 'bar',
 223          ) );
 224          $s3 = self::factory()->signup->create( array(
 225              'activation_key' => 'baz',
 226          ) );
 227  
 228          $ss = BP_Signup::get( array(
 229              'activation_key' => 'bar',
 230              'fields' => 'ids',
 231          ) );
 232  
 233          $this->assertEquals( array( $s2 ), $ss['signups'] );
 234      }
 235  
 236      /**
 237       * @group get
 238       */
 239  	public function test_get_with_user_login() {
 240          $s1 = self::factory()->signup->create( array(
 241              'user_login' => 'aaaafoo',
 242          ) );
 243          $s2 = self::factory()->signup->create( array(
 244              'user_login' => 'zzzzfoo',
 245          ) );
 246          $s3 = self::factory()->signup->create( array(
 247              'user_login' => 'jjjjfoo',
 248          ) );
 249  
 250          $ss = BP_Signup::get( array(
 251              'user_login' => 'zzzzfoo',
 252              'fields' => 'ids',
 253          ) );
 254  
 255          $this->assertEquals( array( $s2 ), $ss['signups'] );
 256      }
 257  
 258      /**
 259       * @group activate
 260       */
 261  	public function test_activate_user_accounts() {
 262          $signups = array();
 263  
 264          $signups['accountone'] = self::factory()->signup->create( array(
 265              'user_login'     => 'accountone',
 266              'user_email'     => 'accountone@example.com',
 267              'activation_key' => 'activationkeyone',
 268          ) );
 269  
 270          $signups['accounttwo'] = self::factory()->signup->create( array(
 271              'user_login'     => 'accounttwo',
 272              'user_email'     => 'accounttwo@example.com',
 273              'activation_key' => 'activationkeytwo',
 274          ) );
 275  
 276          $signups['accountthree'] = self::factory()->signup->create( array(
 277              'user_login'     => 'accountthree',
 278              'user_email'     => 'accountthree@example.com',
 279              'activation_key' => 'activationkeythree',
 280          ) );
 281  
 282          $results = BP_Signup::activate( $signups );
 283          $this->assertNotEmpty( $results['activated'] );
 284  
 285          $users = array();
 286  
 287          foreach ( $signups as $login => $signup_id  ) {
 288              $users[ $login ] = get_user_by( 'login', $login );
 289          }
 290  
 291          $this->assertEqualSets( $results['activated'], wp_list_pluck( $users, 'ID' ) );
 292      }
 293  
 294      /**
 295       * @group get
 296       */
 297  	public function test_get_signup_ids_only() {
 298          $s1 = self::factory()->signup->create();
 299          $s2 = self::factory()->signup->create();
 300          $s3 = self::factory()->signup->create();
 301  
 302          $ss = BP_Signup::get( array(
 303              'number' => 3,
 304              'fields' => 'ids',
 305          ) );
 306  
 307          $this->assertEquals( array( $s3, $s2, $s1 ), $ss['signups'] );
 308      }
 309  }


Generated: Mon Sep 16 01:01:39 2019 Cross-referenced by PHPXref 0.7.1