| | 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 | } |