Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/03/2017 07:44:10 PM (7 years ago)
Author:
boonebgorges
Message:

Use static factory method throughout PHPUnit tests.

See #7620.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/xprofile/functions.php

    r11288 r11737  
    77class BP_Tests_XProfile_Functions extends BP_UnitTestCase {
    88    public function test_get_hidden_field_types_for_user_loggedout() {
    9         $duser = $this->factory->user->create();
     9        $duser = self::factory()->user->create();
    1010
    1111        $old_current_user = bp_loggedin_user_id();
     
    1818
    1919    public function test_get_hidden_field_types_for_user_loggedin() {
    20         $duser = $this->factory->user->create();
    21         $cuser = $this->factory->user->create();
     20        $duser = self::factory()->user->create();
     21        $cuser = self::factory()->user->create();
    2222
    2323        $old_current_user = bp_loggedin_user_id();
     
    3030
    3131    public function test_get_hidden_field_types_for_user_friends() {
    32         $duser = $this->factory->user->create();
    33         $cuser = $this->factory->user->create();
     32        $duser = self::factory()->user->create();
     33        $cuser = self::factory()->user->create();
    3434        friends_add_friend( $duser, $cuser, true );
    3535
     
    4343
    4444    public function test_get_hidden_field_types_for_user_admin() {
    45         $duser = $this->factory->user->create();
    46         $cuser = $this->factory->user->create();
     45        $duser = self::factory()->user->create();
     46        $cuser = self::factory()->user->create();
    4747        $this->grant_bp_moderate( $cuser );
    4848
     
    6161     */
    6262    public function test_bp_xprofile_update_meta_with_line_breaks() {
    63         $g = $this->factory->xprofile_group->create();
    64         $f = $this->factory->xprofile_field->create( array(
     63        $g = self::factory()->xprofile_group->create();
     64        $f = self::factory()->xprofile_field->create( array(
    6565            'field_group_id' => $g,
    6666        ) );
     
    9898     */
    9999    public function test_bp_xprofile_get_field_visibility_level_user_set() {
    100         $u = $this->factory->user->create();
    101         $g = $this->factory->xprofile_group->create();
    102         $f = $this->factory->xprofile_field->create( array(
     100        $u = self::factory()->user->create();
     101        $g = self::factory()->xprofile_group->create();
     102        $f = self::factory()->xprofile_field->create( array(
    103103            'field_group_id' => $g,
    104104        ) );
     
    116116     */
    117117    public function test_bp_xprofile_get_field_visibility_level_user_unset() {
    118         $u = $this->factory->user->create();
    119         $g = $this->factory->xprofile_group->create();
    120         $f = $this->factory->xprofile_field->create( array(
     118        $u = self::factory()->user->create();
     119        $g = self::factory()->xprofile_group->create();
     120        $f = self::factory()->xprofile_field->create( array(
    121121            'field_group_id' => $g,
    122122        ) );
     
    133133     */
    134134    public function test_bp_xprofile_get_field_visibility_level_admin_override() {
    135         $u = $this->factory->user->create();
    136         $g = $this->factory->xprofile_group->create();
    137         $f = $this->factory->xprofile_field->create( array(
     135        $u = self::factory()->user->create();
     136        $g = self::factory()->xprofile_group->create();
     137        $f = self::factory()->xprofile_field->create( array(
    138138            'field_group_id' => $g,
    139139        ) );
     
    177177     */
    178178    public function test_bp_xprofile_delete_meta_illegal_characters() {
    179         $g = $this->factory->xprofile_group->create();
     179        $g = self::factory()->xprofile_group->create();
    180180        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    181181        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     
    192192     */
    193193    public function test_bp_xprofile_delete_meta_trim_meta_value() {
    194         $g = $this->factory->xprofile_group->create();
     194        $g = self::factory()->xprofile_group->create();
    195195        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    196196        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     
    205205     */
    206206    public function test_bp_xprofile_delete_meta_meta_value_match() {
    207         $g = $this->factory->xprofile_group->create();
     207        $g = self::factory()->xprofile_group->create();
    208208        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    209209        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     
    217217     */
    218218    public function test_bp_xprofile_delete_meta_delete_all() {
    219         $g = $this->factory->xprofile_group->create();
     219        $g = self::factory()->xprofile_group->create();
    220220        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    221221        bp_xprofile_update_meta( $g, 'group', 'foo2', 'bar' );
     
    236236        // With no meta key, don't delete for all items - just delete
    237237        // all for a single item
    238         $g1 = $this->factory->xprofile_group->create();
    239         $g2 = $this->factory->xprofile_group->create();
     238        $g1 = self::factory()->xprofile_group->create();
     239        $g2 = self::factory()->xprofile_group->create();
    240240        bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
    241241        bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
     
    256256        // With no meta key, don't delete for all items - just delete
    257257        // all for a single item
    258         $g1 = $this->factory->xprofile_group->create();
    259         $g2 = $this->factory->xprofile_group->create();
     258        $g1 = self::factory()->xprofile_group->create();
     259        $g2 = self::factory()->xprofile_group->create();
    260260        bp_xprofile_add_meta( $g1, 'group', 'foo', 'bar' );
    261261        bp_xprofile_add_meta( $g1, 'group', 'foo1', 'bar1' );
     
    299299     */
    300300    public function test_bp_xprofile_get_meta_no_meta_key() {
    301         $g = $this->factory->xprofile_group->create();
     301        $g = self::factory()->xprofile_group->create();
    302302        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    303303        bp_xprofile_update_meta( $g, 'group', 'foo2', 'bar' );
     
    319319     */
    320320    public function test_bp_xprofile_get_meta_single_true() {
    321         $g = $this->factory->xprofile_group->create();
     321        $g = self::factory()->xprofile_group->create();
    322322        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
    323323        bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
     
    331331     */
    332332    public function test_bp_xprofile_get_meta_single_false() {
    333         $g = $this->factory->xprofile_group->create();
     333        $g = self::factory()->xprofile_group->create();
    334334        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
    335335        bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' );
     
    342342     */
    343343    public function test_bp_xprofile_get_meta_no_meta_key_no_results() {
    344         $g = $this->factory->xprofile_group->create();
     344        $g = self::factory()->xprofile_group->create();
    345345
    346346        $expected = array();
     
    378378     */
    379379    public function test_bp_xprofile_update_meta_illegal_characters() {
    380         $g = $this->factory->xprofile_group->create();
     380        $g = self::factory()->xprofile_group->create();
    381381        $krazy_key = ' f!@#$%^o *(){}o?+';
    382382        bp_xprofile_update_meta( $g, 'group', $krazy_key, 'bar' );
     
    389389     */
    390390    public function test_bp_xprofile_update_meta_stripslashes() {
    391         $g = $this->factory->xprofile_group->create();
     391        $g = self::factory()->xprofile_group->create();
    392392        $v = "Totally \'tubular\'";
    393393        bp_xprofile_update_meta( $g, 'group', 'foo', $v );
     
    400400     */
    401401    public function test_bp_xprofile_update_meta_empty_value_delete() {
    402         $g = $this->factory->xprofile_group->create();
     402        $g = self::factory()->xprofile_group->create();
    403403        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    404404        bp_xprofile_update_meta( $g, 'group', 'foo', '' );
     
    411411     */
    412412    public function test_bp_xprofile_update_meta_new() {
    413         $g = $this->factory->xprofile_group->create();
     413        $g = self::factory()->xprofile_group->create();
    414414        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    415415        $this->assertNotEmpty( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' ) );
     
    422422     */
    423423    public function test_bp_xprofile_update_meta_existing() {
    424         $g = $this->factory->xprofile_group->create();
     424        $g = self::factory()->xprofile_group->create();
    425425        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    426426        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     
    434434     */
    435435    public function test_bp_xprofile_update_meta_same_value() {
    436         $g = $this->factory->xprofile_group->create();
     436        $g = self::factory()->xprofile_group->create();
    437437        bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' );
    438438        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
     
    445445     */
    446446    public function test_bp_xprofile_update_meta_prev_value() {
    447         $g = $this->factory->xprofile_group->create();
     447        $g = self::factory()->xprofile_group->create();
    448448        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
    449449
     
    466466     */
    467467    public function test_bp_xprofile_update_meta_where_sql_filter_keywords_are_in_quoted_value() {
    468         $g = $this->factory->xprofile_group->create();
     468        $g = self::factory()->xprofile_group->create();
    469469        $value = "SELECT object_id FROM wp_bp_xprofile_groups WHERE \"foo\" VALUES (foo = 'bar'";
    470470        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     
    479479     */
    480480    public function test_bp_xprofile_update_meta_where_meta_id_is_in_quoted_value() {
    481         $g = $this->factory->xprofile_group->create();
     481        $g = self::factory()->xprofile_group->create();
    482482        $value = "foo meta_id bar";
    483483        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
     
    507507     */
    508508    public function test_bp_xprofile_add_meta_existing_unique() {
    509         $g = $this->factory->xprofile_group->create();
     509        $g = self::factory()->xprofile_group->create();
    510510        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
    511511        $this->assertFalse( bp_xprofile_add_meta( $g, 'group', 'foo', 'baz', true ) );
     
    517517     */
    518518    public function test_bp_xprofile_add_meta_existing_not_unique() {
    519         $g = $this->factory->xprofile_group->create();
     519        $g = self::factory()->xprofile_group->create();
    520520        bp_xprofile_add_meta( $g, 'group', 'foo', 'bar' );
    521521        $this->assertNotEmpty( bp_xprofile_add_meta( $g, 'group', 'foo', 'baz' ) );
     
    526526     */
    527527    public function test_bp_get_member_profile_data_inside_loop() {
    528         $u = $this->factory->user->create();
    529         $g = $this->factory->xprofile_group->create();
    530         $f = $this->factory->xprofile_field->create( array(
     528        $u = self::factory()->user->create();
     529        $g = self::factory()->xprofile_group->create();
     530        $f = self::factory()->xprofile_field->create( array(
    531531            'field_group_id' => $g,
    532532            'name' => 'Neato',
     
    550550     */
    551551    public function test_bp_get_member_profile_data_outside_of_loop() {
    552         $u = $this->factory->user->create();
    553         $g = $this->factory->xprofile_group->create();
    554         $f = $this->factory->xprofile_field->create( array(
     552        $u = self::factory()->user->create();
     553        $g = self::factory()->xprofile_group->create();
     554        $f = self::factory()->xprofile_field->create( array(
    555555            'field_group_id' => $g,
    556556            'name' => 'Kewl',
     
    570570     */
    571571    public function test_get_field_data_integer_zero() {
    572         $u = $this->factory->user->create();
    573         $g = $this->factory->xprofile_group->create();
    574         $f = $this->factory->xprofile_field->create( array(
     572        $u = self::factory()->user->create();
     573        $g = self::factory()->xprofile_group->create();
     574        $f = self::factory()->xprofile_field->create( array(
    575575            'field_group_id' => $g,
    576576            'type' => 'number',
     
    621621     */
    622622    public function test_xprofile_insert_field_type_option() {
    623         $g = $this->factory->xprofile_group->create();
    624         $parent = $this->factory->xprofile_field->create( array(
     623        $g = self::factory()->xprofile_group->create();
     624        $parent = self::factory()->xprofile_field->create( array(
    625625            'field_group_id' => $g,
    626626            'type' => 'selectbox',
     
    644644     */
    645645    public function test_xprofile_insert_field_should_process_falsey_values_for_boolean_params_on_existing_fields() {
    646         $g = $this->factory->xprofile_group->create();
     646        $g = self::factory()->xprofile_group->create();
    647647        $f = xprofile_insert_field( array(
    648648            'field_group_id' => $g,
     
    702702     */
    703703    public function test_xprofile_insert_field_type_option_option_order() {
    704         $g = $this->factory->xprofile_group->create();
    705         $parent = $this->factory->xprofile_field->create( array(
     704        $g = self::factory()->xprofile_group->create();
     705        $parent = self::factory()->xprofile_field->create( array(
    706706            'field_group_id' => $g,
    707707            'type' => 'selectbox',
     
    727727     */
    728728    public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_new_option() {
    729         $g = $this->factory->xprofile_group->create();
    730         $parent = $this->factory->xprofile_field->create( array(
     729        $g = self::factory()->xprofile_group->create();
     730        $parent = self::factory()->xprofile_field->create( array(
    731731            'field_group_id' => $g,
    732732            'type' => 'selectbox',
     
    753753     */
    754754    public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_new_option() {
    755         $g = $this->factory->xprofile_group->create();
    756         $parent = $this->factory->xprofile_field->create( array(
     755        $g = self::factory()->xprofile_group->create();
     756        $parent = self::factory()->xprofile_field->create( array(
    757757            'field_group_id' => $g,
    758758            'type' => 'selectbox',
     
    779779     */
    780780    public function test_xprofile_insert_field_should_set_is_default_option_to_false_for_existing_option() {
    781         $g = $this->factory->xprofile_group->create();
    782         $parent = $this->factory->xprofile_field->create( array(
     781        $g = self::factory()->xprofile_group->create();
     782        $parent = self::factory()->xprofile_field->create( array(
    783783            'field_group_id' => $g,
    784784            'type' => 'selectbox',
     
    815815     */
    816816    public function test_xprofile_insert_field_should_set_is_default_option_to_true_for_existing_option() {
    817         $g = $this->factory->xprofile_group->create();
    818         $parent = $this->factory->xprofile_field->create( array(
     817        $g = self::factory()->xprofile_group->create();
     818        $parent = self::factory()->xprofile_field->create( array(
    819819            'field_group_id' => $g,
    820820            'type' => 'selectbox',
     
    852852     */
    853853    public function test_bp_profile_get_field_groups_update_position() {
    854         $g1 = $this->factory->xprofile_group->create();
    855         $g2 = $this->factory->xprofile_group->create();
    856         $g3 = $this->factory->xprofile_group->create();
     854        $g1 = self::factory()->xprofile_group->create();
     855        $g2 = self::factory()->xprofile_group->create();
     856        $g3 = self::factory()->xprofile_group->create();
    857857
    858858        // prime the cache
     
    876876        global $wpdb;
    877877
    878         $g = $this->factory->xprofile_group->create();
    879         $f = $this->factory->xprofile_field->create( array(
     878        $g = self::factory()->xprofile_group->create();
     879        $f = self::factory()->xprofile_field->create( array(
    880880            'field_group_id' => $g,
    881881            'type' => 'selectbox',
     
    895895        global $wpdb;
    896896
    897         $g = $this->factory->xprofile_group->create();
    898         $f = $this->factory->xprofile_field->create( array(
     897        $g = self::factory()->xprofile_group->create();
     898        $f = self::factory()->xprofile_field->create( array(
    899899            'field_group_id' => $g,
    900900            'type' => 'selectbox',
     
    919919     */
    920920    public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_true_for_textareas() {
    921         $g = $this->factory->xprofile_group->create();
    922         $f = $this->factory->xprofile_field->create( array(
     921        $g = self::factory()->xprofile_group->create();
     922        $f = self::factory()->xprofile_field->create( array(
    923923            'field_group_id' => $g,
    924924            'type' => 'textarea',
     
    932932     */
    933933    public function test_bp_xprofie_is_richtext_enabled_for_field_should_default_to_false_for_non_textareas() {
    934         $g = $this->factory->xprofile_group->create();
    935         $f = $this->factory->xprofile_field->create( array(
     934        $g = self::factory()->xprofile_group->create();
     935        $f = self::factory()->xprofile_field->create( array(
    936936            'field_group_id' => $g,
    937937            'type' => 'radio',
     
    10481048     */
    10491049    public function test_field_comma_seperated_values_are_autolinked() {
    1050         $field_group_id = $this->factory->xprofile_group->create();
    1051         $field_id = $this->factory->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
     1050        $field_group_id = self::factory()->xprofile_group->create();
     1051        $field_id = self::factory()->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
    10521052        $GLOBALS['field'] = new BP_XProfile_Field( $field_id );
    10531053        $GLOBALS['field']->do_autolink = true;
     
    10641064     */
    10651065    public function test_field_semicolon_seperated_values_are_autolinked() {
    1066         $field_group_id = $this->factory->xprofile_group->create();
    1067         $field_id = $this->factory->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
     1066        $field_group_id = self::factory()->xprofile_group->create();
     1067        $field_id = self::factory()->xprofile_field->create( array( 'field_group_id' => $field_group_id ) );
    10681068        $GLOBALS['field'] = new BP_XProfile_Field( $field_id );
    10691069        $GLOBALS['field']->do_autolink = true;
Note: See TracChangeset for help on using the changeset viewer.