[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @group xprofile
   4   * @group BP_XProfile_Field_Type
   5   */
   6  class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase {
   7  	public function test_unregistered_field_type_returns_textbox() {
   8          $field = bp_xprofile_create_field_type( 'fakeyfield' );
   9          $this->assertEquals( get_class( $field ), 'BP_XProfile_Field_Type_Placeholder' );
  10      }
  11  
  12  	public function test_textbox_validate_empty_string() {
  13          $field = bp_xprofile_create_field_type( 'textbox' );
  14          $this->assertTrue( $field->is_valid( '' ) );
  15      }
  16  
  17  	public function test_textbox_validate_string() {
  18          $field = bp_xprofile_create_field_type( 'textbox' );
  19          $this->assertTrue( $field->is_valid( 'my 117th input string!' ) );
  20      }
  21  
  22  	public function test_textbox_validate_integer() {
  23          $field = bp_xprofile_create_field_type( 'textbox' );
  24          $this->assertTrue( $field->is_valid( 123 ) );
  25      }
  26  
  27  	public function test_textbox_validate_whitelisted_string() {
  28          $field = bp_xprofile_create_field_type( 'textbox' );
  29  
  30          $this->assertTrue( $field->is_valid( 'a string' ) );
  31          $this->assertFalse( $field->set_whitelist_values( 'pizza' )->is_valid( 'pasta' ) );
  32          $this->assertTrue( $field->is_valid( 'pizza' ) );
  33      }
  34  
  35      public function test_multiselectbox_validate_whitelisted_array() {
  36          $field = bp_xprofile_create_field_type( 'multiselectbox' );
  37          $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
  38  
  39          $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
  40          $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
  41          $this->assertFalse( $field->is_valid( array( 'cheese', 'pinapple', 'pepporoni' ) ) );
  42          $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
  43      }
  44  
  45  	public function test_multiselectbox_validate_null_value() {
  46          $field = bp_xprofile_create_field_type( 'multiselectbox' );
  47          $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
  48  
  49          $this->assertFalse( $field->is_valid( array( '' ) ) );
  50          $this->assertFalse( $field->is_valid( '' ) );
  51          $this->assertTrue( $field->is_valid( array() ) );
  52      }
  53  
  54  	public function test_datebox_do_not_validate_string() {
  55          $field = bp_xprofile_create_field_type( 'datebox' );
  56          $this->assertFalse( $field->is_valid( 'datebox fields only accept strings in: Y-m-d 00:00:00' ) );
  57          $this->assertFalse( $field->is_valid( '' ) );
  58      }
  59  
  60  	public function test_datebox_do_not_validate_integer() {
  61          $field = bp_xprofile_create_field_type( 'datebox' );
  62          $this->assertFalse( $field->is_valid( 221213 ) );
  63      }
  64  
  65  	public function test_datebox_validate_date() {
  66          $field = bp_xprofile_create_field_type( 'datebox' );
  67          $this->assertTrue( $field->is_valid( '2013-12-22 00:00:00' ) );
  68      }
  69  
  70      public function test_datebox_do_not_validate_date_with_timestamp() {
  71          $field = bp_xprofile_create_field_type( 'datebox' );
  72          $this->assertFalse( $field->is_valid( '2013-12-22 19:11:30' ) );
  73          $this->assertFalse( $field->is_valid( '2013-12-22' ) );
  74      }
  75  
  76  	public function test_number_do_not_validate_string() {
  77          $field = bp_xprofile_create_field_type( 'number' );
  78          $this->assertFalse( $field->is_valid( 'number fields only accept integers' ) );
  79          $this->assertFalse( $field->is_valid( '' ) );
  80      }
  81  
  82  	public function test_number_validate_positive_integer() {
  83          $field = bp_xprofile_create_field_type( 'number' );
  84          $this->assertTrue( $field->is_valid( 12345678901 ) );
  85          $this->assertTrue( $field->is_valid( '12345678901' ) );
  86      }
  87  
  88  	public function test_number_validate_negative_integer() {
  89          $field = bp_xprofile_create_field_type( 'number' );
  90          $this->assertTrue( $field->is_valid( -987654321 ) );
  91          $this->assertTrue( $field->is_valid( '-987654321' ) );
  92      }
  93  
  94  	public function test_number_validate_null_value() {
  95          $field = bp_xprofile_create_field_type( 'number' );
  96          $this->assertTrue( $field->is_valid( '0' ) );
  97          $this->assertFalse( $field->is_valid( '-' ) );
  98          $this->assertFalse( $field->is_valid( '' ) );
  99      }
 100  
 101  	public function test_number_validate_whitelisted_array() {
 102          $field = bp_xprofile_create_field_type( 'number' );
 103          $field->set_whitelist_values( array( 123, 456 ) );
 104  
 105          $this->assertTrue( $field->is_valid( array( 123 ) ) );
 106          $this->assertTrue( $field->is_valid( array( 456 ) ) );
 107          $this->assertFalse( $field->is_valid( array( 789, 456, 123 ) ) );
 108          $this->assertFalse( $field->is_valid( array( 789 ) ) );
 109      }
 110  
 111  	public function test_radiobutton_validate_whitelisted_array() {
 112          $field = bp_xprofile_create_field_type( 'radio' );
 113          $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
 114  
 115          $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
 116          $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
 117          $this->assertFalse( $field->is_valid( array(  'pinapple', 'cheese', 'pepporoni' ) ) );
 118          $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
 119          $this->assertFalse( $field->is_valid( '' ) );
 120      }
 121  
 122      public function test_radiobutton_do_not_validate_empty_items_in_whitelist() {
 123          $field = bp_xprofile_create_field_type( 'radio' );
 124          $field->set_whitelist_values( array( '' ) );
 125  
 126          $this->assertFalse( $field->is_valid( array( '' ) ) );
 127      }
 128  
 129  	public function test_checkbox_validate_whitelisted_array() {
 130          $field = bp_xprofile_create_field_type( 'checkbox' );
 131          $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
 132  
 133          $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
 134          $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
 135          $this->assertFalse( $field->is_valid( array( 'pepporoni', 'cheese', 'pinapple' ) ) );
 136          $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
 137          $this->assertFalse( $field->is_valid( '' ) );
 138      }
 139  
 140  	public function test_checkbox_validate_null_value() {
 141          $field = bp_xprofile_create_field_type( 'checkbox' );
 142          $field->set_whitelist_values( array( 'cheese', 'pepporoni' ) );
 143  
 144          $this->assertFalse( $field->is_valid( array( '' ) ) );
 145          $this->assertFalse( $field->is_valid( '' ) );
 146          $this->assertTrue( $field->is_valid( array() ) );
 147      }
 148  
 149      /**
 150       * @group url
 151       */
 152  	public function test_url_validate_url() {
 153          $field = bp_xprofile_create_field_type( 'url' );
 154  
 155          $this->assertTrue( $field->is_valid( 'http://foo.com' ) );
 156          $this->assertTrue( $field->is_valid( 'https://foo.com' ) );
 157          $this->assertTrue( $field->is_valid( 'http://foo.bar.com' ) );
 158          $this->assertTrue( $field->is_valid( 'http://foo.bar.com/' ) );
 159          $this->assertTrue( $field->is_valid( 'http://foo.com/bar' ) );
 160          $this->assertTrue( $field->is_valid( 'http://foo.com/index.php' ) );
 161          $this->assertTrue( $field->is_valid( 'http://foo.com/?bar=baz' ) );
 162  
 163          $this->assertFalse( $field->is_valid( 'htp://foo.com' ) );
 164          $this->assertFalse( $field->is_valid( 'http:/foo.com' ) );
 165          $this->assertFalse( $field->is_valid( 'http//foo.com' ) );
 166          $this->assertFalse( $field->is_valid( 'http://foo' ) );
 167          $this->assertFalse( $field->is_valid( 'foo.com' ) );
 168      }
 169  
 170      /**
 171       * @group BP_XProfile_Field_Group_Type_Placeholder
 172       */
 173  	public function test_placeholder_validate_any_value() {
 174          $field = bp_xprofile_create_field_type( 'foo' );
 175          $this->assertTrue( $field->is_valid( '' ) );
 176          $this->assertTrue( $field->is_valid( 'bar' ) );
 177          $this->assertTrue( $field->is_valid( array( 'bar' ) ) );
 178      }
 179  
 180  	public function test_telephone_validate_number_formats() {
 181          $field = bp_xprofile_create_field_type( 'telephone' );
 182          $this->assertTrue( $field->is_valid( '07700 900461' ) );
 183          $this->assertTrue( $field->is_valid( '555-2368' ) );
 184          $this->assertTrue( $field->is_valid( '(212) 664-7665' ) );
 185      }
 186  }


Generated: Tue Sep 17 01:01:39 2019 Cross-referenced by PHPXref 0.7.1