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/activity/functions.php

    r11583 r11737  
    2828
    2929        // create an activity update
    30         $activity = $this->factory->activity->create( array(
     30        $activity = self::factory()->activity->create( array(
    3131            'type' => 'activity_update'
    3232        ) );
     
    5757
    5858        // create an activity update
    59         $this->factory->activity->create( $criteria );
    60         $this->factory->activity->create( $criteria );
    61         $this->factory->activity->create( $criteria );
    62         $this->factory->activity->create( $criteria );
     59        self::factory()->activity->create( $criteria );
     60        self::factory()->activity->create( $criteria );
     61        self::factory()->activity->create( $criteria );
     62        self::factory()->activity->create( $criteria );
    6363
    6464        // now delete the activity items
     
    8383
    8484        // create an activity update
    85         $this->factory->activity->create( $criteria );
    86         $this->factory->activity->create( $criteria );
    87         $this->factory->activity->create( $criteria );
    88         $this->factory->activity->create( $criteria );
     85        self::factory()->activity->create( $criteria );
     86        self::factory()->activity->create( $criteria );
     87        self::factory()->activity->create( $criteria );
     88        self::factory()->activity->create( $criteria );
    8989
    9090        // now delete the activity items
     
    109109
    110110        // create an activity update
    111         $this->factory->activity->create( $criteria );
    112         $this->factory->activity->create( $criteria );
    113         $this->factory->activity->create( $criteria );
    114         $this->factory->activity->create( $criteria );
     111        self::factory()->activity->create( $criteria );
     112        self::factory()->activity->create( $criteria );
     113        self::factory()->activity->create( $criteria );
     114        self::factory()->activity->create( $criteria );
    115115
    116116        // now delete the activity items
     
    130130
    131131        // create an activity update
    132         $activity = $this->factory->activity->create( array(
     132        $activity = self::factory()->activity->create( array(
    133133            'type' => 'activity_update'
    134134        ) );
     
    153153
    154154        // create an activity update
    155         $activity = $this->factory->activity->create( array(
     155        $activity = self::factory()->activity->create( array(
    156156            'type' => 'activity_update'
    157157        ) );
     
    188188
    189189        // create an activity update
    190         $parent_activity = $this->factory->activity->create( array(
     190        $parent_activity = self::factory()->activity->create( array(
    191191            'type' => 'activity_update',
    192192        ) );
    193193
    194194        // create some activity comments
    195         $comment_one = $this->factory->activity->create( array(
     195        $comment_one = self::factory()->activity->create( array(
    196196            'type'              => 'activity_comment',
    197197            'item_id'           => $parent_activity,
     
    199199        ) );
    200200
    201         $comment_two = $this->factory->activity->create( array(
     201        $comment_two = self::factory()->activity->create( array(
    202202            'type'              => 'activity_comment',
    203203            'item_id'           => $parent_activity,
     
    227227
    228228        // create an activity update
    229         $parent_activity = $this->factory->activity->create( array(
     229        $parent_activity = self::factory()->activity->create( array(
    230230            'type' => 'activity_update',
    231231        ) );
    232232
    233233        // create some activity comments
    234         $comment_one = $this->factory->activity->create( array(
     234        $comment_one = self::factory()->activity->create( array(
    235235            'type'              => 'activity_comment',
    236236            'item_id'           => $parent_activity,
     
    238238        ) );
    239239
    240         $comment_two = $this->factory->activity->create( array(
     240        $comment_two = self::factory()->activity->create( array(
    241241            'type'              => 'activity_comment',
    242242            'item_id'           => $parent_activity,
     
    271271     */
    272272    public function test_bp_activity_update_meta_with_line_breaks() {
    273         $a = $this->factory->activity->create();
     273        $a = self::factory()->activity->create();
    274274        $meta_value = 'Foo!
    275275
     
    285285     */
    286286    public function test_bp_activity_update_meta_with_0() {
    287         $a = $this->factory->activity->create();
     287        $a = self::factory()->activity->create();
    288288        $meta_value = 0;
    289289
     
    307307     */
    308308    public function test_bp_activity_update_meta_with_illegal_key_characters() {
    309         $a = $this->factory->activity->create();
     309        $a = self::factory()->activity->create();
    310310        $krazy_key = ' f!@#$%^o *(){}o?+';
    311311        bp_activity_update_meta( $a, $krazy_key, 'bar' );
     
    319319     */
    320320    public function test_bp_activity_update_meta_stripslashes() {
    321         $a = $this->factory->activity->create();
     321        $a = self::factory()->activity->create();
    322322        $value = "This string is totally slashin\'!";
    323323        bp_activity_update_meta( $a, 'foo', $value );
     
    331331     */
    332332    public function test_bp_activity_update_meta_false_value_deletes() {
    333         $a = $this->factory->activity->create();
     333        $a = self::factory()->activity->create();
    334334        bp_activity_update_meta( $a, 'foo', false );
    335335        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
     
    341341     */
    342342    public function test_bp_activity_update_meta_new() {
    343         $a = $this->factory->activity->create();
     343        $a = self::factory()->activity->create();
    344344        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ), '"foo" meta should be empty for this activity item.' );
    345345        $this->assertNotEmpty( bp_activity_update_meta( $a, 'foo', 'bar' ) );
     
    352352     */
    353353    public function test_bp_activity_update_meta_existing() {
    354         $a = $this->factory->activity->create();
     354        $a = self::factory()->activity->create();
    355355        bp_activity_update_meta( $a, 'foo', 'bar' );
    356356        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) );
     
    364364     */
    365365    public function test_bp_activity_update_meta_same_value() {
    366         $a = $this->factory->activity->create();
     366        $a = self::factory()->activity->create();
    367367        bp_activity_update_meta( $a, 'foo', 'bar' );
    368368        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) );
     
    376376     */
    377377    public function test_bp_activity_update_meta_prev_value() {
    378         $a = $this->factory->activity->create();
     378        $a = self::factory()->activity->create();
    379379        bp_activity_add_meta( $a, 'foo', 'bar' );
    380380
     
    413413     */
    414414    public function test_bp_activity_get_meta_with_illegal_characters() {
    415         $a = $this->factory->activity->create();
     415        $a = self::factory()->activity->create();
    416416        bp_activity_update_meta( $a, 'foo', 'bar' );
    417417
     
    425425     */
    426426    public function test_bp_activity_get_meta_multiple() {
    427         $a = $this->factory->activity->create();
     427        $a = self::factory()->activity->create();
    428428        bp_activity_update_meta( $a, 'foo', 'bar' );
    429429        bp_activity_update_meta( $a, 'foo1', 'bar1' );
     
    447447     */
    448448    public function test_bp_activity_get_meta_no_results_returns_false() {
    449         $a = $this->factory->activity->create();
     449        $a = self::factory()->activity->create();
    450450
    451451        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ) );
     
    457457     */
    458458    public function test_bp_activity_get_meta_single_true() {
    459         $a = $this->factory->activity->create();
     459        $a = self::factory()->activity->create();
    460460        bp_activity_add_meta( $a, 'foo', 'bar' );
    461461        bp_activity_add_meta( $a, 'foo', 'baz' );
     
    469469     */
    470470    public function test_bp_activity_get_meta_single_false() {
    471         $a = $this->factory->activity->create();
     471        $a = self::factory()->activity->create();
    472472        bp_activity_add_meta( $a, 'foo', 'bar' );
    473473        bp_activity_add_meta( $a, 'foo', 'baz' );
     
    481481     */
    482482    public function test_bp_activity_get_meta_cache_all_on_get() {
    483         $a = $this->factory->activity->create();
     483        $a = self::factory()->activity->create();
    484484        bp_activity_add_meta( $a, 'foo', 'bar' );
    485485        bp_activity_add_meta( $a, 'foo1', 'baz' );
     
    507507     */
    508508    public function test_bp_activity_delete_meta_trim_meta_value() {
    509         $a = $this->factory->activity->create();
     509        $a = self::factory()->activity->create();
    510510        bp_activity_update_meta( $a, 'foo', 'bar' );
    511511        bp_activity_delete_meta( $a, 'foo', ' bar ' );
     
    518518     */
    519519    public function test_bp_activity_delete_meta_single() {
    520         $a = $this->factory->activity->create();
     520        $a = self::factory()->activity->create();
    521521        bp_activity_update_meta( $a, 'foo', 'bar' );
    522522        $this->assertTrue( bp_activity_delete_meta( $a, 'foo', 'bar' ) );
     
    529529     */
    530530    public function test_bp_activity_delete_meta_all_for_activity() {
    531         $a = $this->factory->activity->create();
     531        $a = self::factory()->activity->create();
    532532        bp_activity_update_meta( $a, 'foo', 'bar' );
    533533        bp_activity_update_meta( $a, 'foo1', 'bar1' );
     
    542542     */
    543543    public function test_bp_activity_delete_meta_with_meta_value() {
    544         $a = $this->factory->activity->create();
     544        $a = self::factory()->activity->create();
    545545        bp_activity_update_meta( $a, 'foo', 'bar' );
    546546        $this->assertTrue( bp_activity_delete_meta( $a, 'foo', 'bar' ) );
     
    555555        // With no meta key, don't delete for all items - just delete
    556556        // all for a single item
    557         $a1 = $this->factory->activity->create();
    558         $a2 = $this->factory->activity->create();
     557        $a1 = self::factory()->activity->create();
     558        $a2 = self::factory()->activity->create();
    559559        bp_activity_update_meta( $a1, 'foo', 'bar' );
    560560        bp_activity_update_meta( $a1, 'foo1', 'bar1' );
     
    575575        // With no meta key, don't delete for all items - just delete
    576576        // all for a single item
    577         $a1 = $this->factory->activity->create();
    578         $a2 = $this->factory->activity->create();
     577        $a1 = self::factory()->activity->create();
     578        $a2 = self::factory()->activity->create();
    579579        bp_activity_update_meta( $a1, 'foo', 'bar' );
    580580        bp_activity_update_meta( $a1, 'foo1', 'bar1' );
     
    610610     */
    611611    public function test_bp_activity_add_meta_existing_unique() {
    612         $a = $this->factory->activity->create();
     612        $a = self::factory()->activity->create();
    613613        bp_activity_add_meta( $a, 'foo', 'bar' );
    614614        $this->assertFalse( bp_activity_add_meta( $a, 'foo', 'baz', true ) );
     
    620620     */
    621621    public function test_bp_activity_add_meta_existing_not_unique() {
    622         $a = $this->factory->activity->create();
     622        $a = self::factory()->activity->create();
    623623        bp_activity_add_meta( $a, 'foo', 'bar' );
    624624        $this->assertNotEmpty( bp_activity_add_meta( $a, 'foo', 'baz' ) );
     
    631631        add_filter( 'bp_is_username_compatibility_mode', '__return_false' );
    632632
    633         $u = $this->factory->user->create( array(
     633        $u = self::factory()->user->create( array(
    634634            'user_login' => 'foo bar baz',
    635635            'user_nicename' => 'foo-bar-baz',
     
    647647        add_filter( 'bp_is_username_compatibility_mode', '__return_true' );
    648648
    649         $u1 = $this->factory->user->create( array(
     649        $u1 = self::factory()->user->create( array(
    650650            'user_login' => 'foo bar baz',
    651651            'user_nicename' => 'foo-bar-baz',
    652652        ) );
    653653
    654         $u2 = $this->factory->user->create( array(
     654        $u2 = self::factory()->user->create( array(
    655655            'user_login' => 'foo.bar.baz',
    656656            'user_nicename' => 'foo-bar-baz',
     
    669669        add_filter( 'bp_is_username_compatibility_mode', '__return_false' );
    670670
    671         $u = $this->factory->user->create( array(
     671        $u = self::factory()->user->create( array(
    672672            'user_login' => 'foo bar baz',
    673673            'user_nicename' => 'foo-bar-baz',
     
    686686
    687687        // all spaces are hyphens
    688         $u1 = $this->factory->user->create( array(
     688        $u1 = self::factory()->user->create( array(
    689689            'user_login' => 'foo bar baz',
    690690            'user_nicename' => 'foobarbaz',
     
    692692
    693693        // no spaces are hyphens
    694         $u2 = $this->factory->user->create( array(
     694        $u2 = self::factory()->user->create( array(
    695695            'user_login' => 'foo-bar-baz-1',
    696696            'user_nicename' => 'foobarbaz-1',
     
    698698
    699699        // some spaces are hyphens
    700         $u3 = $this->factory->user->create( array(
     700        $u3 = self::factory()->user->create( array(
    701701            'user_login' => 'foo bar-baz 2',
    702702            'user_nicename' => 'foobarbaz-2',
    703703        ) );
    704704
    705         $u4 = $this->factory->user->create( array(
     705        $u4 = self::factory()->user->create( array(
    706706            'user_login' => 'foo.bar.baz',
    707707            'user_nicename' => 'foo-bar-baz',
     
    721721     */
    722722    public function test_bp_activity_format_activity_action_activity_update() {
    723         $u = $this->factory->user->create();
    724         $a = $this->factory->activity->create( array(
     723        $u = self::factory()->user->create();
     724        $a = self::factory()->activity->create( array(
    725725            'component' => buddypress()->activity->id,
    726726            'type' => 'activity_update',
     
    740740     */
    741741    public function test_bp_activity_format_activity_action_activity_comment() {
    742         $u = $this->factory->user->create();
    743         $a = $this->factory->activity->create( array(
     742        $u = self::factory()->user->create();
     743        $a = self::factory()->activity->create( array(
    744744            'component' => buddypress()->activity->id,
    745745            'type' => 'activity_comment',
     
    773773        bp_activity_get_actions();
    774774
    775         $u = $this->factory->user->create();
    776         $p = $this->factory->post->create( array(
     775        $u = self::factory()->user->create();
     776        $p = self::factory()->post->create( array(
    777777            'post_author' => $u,
    778778            'post_type'   => 'foo',
    779779        ) );
    780780
    781         $a = $this->factory->activity->create( array(
     781        $a = self::factory()->activity->create( array(
    782782            'component'         => 'activity',
    783783            'type'              => 'new_foo',
     
    811811        }
    812812
    813         $b = $this->factory->blog->create();
    814         $u = $this->factory->user->create();
     813        $b = self::factory()->blog->create();
     814        $u = self::factory()->user->create();
    815815
    816816        switch_to_blog( $b );
     
    825825        bp_activity_get_actions();
    826826
    827         $p = $this->factory->post->create( array(
     827        $p = self::factory()->post->create( array(
    828828            'post_author' => $u,
    829829            'post_type'   => 'foo',
     
    843843        restore_current_blog();
    844844
    845         $a = $this->factory->activity->create( $activity_args );
     845        $a = self::factory()->activity->create( $activity_args );
    846846
    847847        $a_obj = new BP_Activity_Activity( $a );
     
    886886        bp_activity_get_actions();
    887887
    888         $u = $this->factory->user->create();
    889         $p = $this->factory->post->create( array(
     888        $u = self::factory()->user->create();
     889        $p = self::factory()->post->create( array(
    890890            'post_author' => $u,
    891891            'post_type'   => 'foo',
    892892        ) );
    893893
    894         $a = $this->factory->activity->create( array(
     894        $a = self::factory()->activity->create( array(
    895895            'component'         => 'activity',
    896896            'type'              => 'foo_bar',
     
    923923        }
    924924
    925         $b = $this->factory->blog->create();
    926         $u = $this->factory->user->create();
     925        $b = self::factory()->blog->create();
     926        $u = self::factory()->user->create();
    927927
    928928        switch_to_blog( $b );
     
    943943        bp_activity_get_actions();
    944944
    945         $p = $this->factory->post->create( array(
     945        $p = self::factory()->post->create( array(
    946946            'post_author' => $u,
    947947            'post_type'   => 'foo',
     
    960960        restore_current_blog();
    961961
    962         $a = $this->factory->activity->create( $activity_args );
     962        $a = self::factory()->activity->create( $activity_args );
    963963
    964964        $a_obj = new BP_Activity_Activity( $a );
     
    990990        bp_activity_get_actions();
    991991
    992         $u = $this->factory->user->create();
    993 
    994         $post_id = $this->factory->post->create( array(
     992        $u = self::factory()->user->create();
     993
     994        $post_id = self::factory()->post->create( array(
    995995            'post_author' => $u,
    996996            'post_status' => 'publish',
     
    10541054    public function test_bp_activity_format_activity_action_custom_post_type_comment() {
    10551055        if ( is_multisite() ) {
    1056             $b = $this->factory->blog->create();
     1056            $b = self::factory()->blog->create();
    10571057            switch_to_blog( $b );
    10581058            add_filter( 'comment_flood_filter', '__return_false' );
     
    10611061        }
    10621062
    1063         $u = $this->factory->user->create();
     1063        $u = self::factory()->user->create();
    10641064        $userdata = get_userdata( $u );
    10651065
     
    10841084        bp_activity_get_actions();
    10851085
    1086         $p = $this->factory->post->create( array(
     1086        $p = self::factory()->post->create( array(
    10871087            'post_author' => $u,
    10881088            'post_type'   => 'foo',
     
    11271127     */
    11281128    public function test_bp_activity_new_comment_clear_comment_caches() {
    1129         $u = $this->factory->user->create();
    1130         $a1 = $this->factory->activity->create( array(
     1129        $u = self::factory()->user->create();
     1130        $a1 = self::factory()->activity->create( array(
    11311131            'user_id' => $u,
    11321132        ) );
     
    11811181     */
    11821182    public function test_bp_activity_new_comment_clear_activity_caches() {
    1183         $u = $this->factory->user->create();
    1184         $a1 = $this->factory->activity->create( array(
     1183        $u = self::factory()->user->create();
     1184        $a1 = self::factory()->activity->create( array(
    11851185            'user_id' => $u,
    11861186        ) );
     
    12531253     */
    12541254    public function test_bp_activity_delete_comment_clear_cache() {
    1255         $u = $this->factory->user->create();
     1255        $u = self::factory()->user->create();
    12561256        // add new activity update and comment to this update
    1257         $a1 = $this->factory->activity->create( array(
     1257        $a1 = self::factory()->activity->create( array(
    12581258            'user_id' => $u,
    12591259        ) );
     
    12831283     */
    12841284    public function test_bp_activity_delete_comment_shouldnt_delete_all_comments_when_parameters_are_empty() {
    1285         $u = $this->factory->user->create();
     1285        $u = self::factory()->user->create();
    12861286
    12871287        // create an activity update
    1288         $parent_activity = $this->factory->activity->create( array(
     1288        $parent_activity = self::factory()->activity->create( array(
    12891289            'type'    => 'activity_update',
    12901290            'user_id' => $u
     
    13301330     */
    13311331    public function test_bp_activity_comment_on_deleted_activity() {
    1332         $u = $this->factory->user->create();
    1333         $a = $this->factory->activity->create();
     1332        $u = self::factory()->user->create();
     1333        $a = self::factory()->activity->create();
    13341334
    13351335        bp_activity_delete_by_activity_id( $a );
     
    13501350     */
    13511351    public function test_add_user_favorite_already_favorited() {
    1352         $u = $this->factory->user->create();
    1353         $a = $this->factory->activity->create();
     1352        $u = self::factory()->user->create();
     1353        $a = self::factory()->activity->create();
    13541354
    13551355        // bp_activity_add_user_favorite() requires a logged-in user.
     
    13711371     */
    13721372    public function test_add_user_favorite_not_yet_favorited() {
    1373         $u = $this->factory->user->create();
    1374         $a = $this->factory->activity->create();
     1373        $u = self::factory()->user->create();
     1374        $a = self::factory()->activity->create();
    13751375
    13761376        // bp_activity_add_user_favorite() requires a logged-in user.
     
    13871387     */
    13881388    public function test_remove_user_favorite_bad_activity_id() {
    1389         $u1 = $this->factory->user->create();
    1390         $u2 = $this->factory->user->create();
    1391         $a = $this->factory->activity->create();
     1389        $u1 = self::factory()->user->create();
     1390        $u2 = self::factory()->user->create();
     1391        $a = self::factory()->activity->create();
    13921392
    13931393        // bp_activity_add_user_favorite() requires a logged-in user.
     
    14261426     */
    14271427    public function test_bp_activity_post_update_success() {
    1428         $u = $this->factory->user->create();
     1428        $u = self::factory()->user->create();
    14291429
    14301430        $a = bp_activity_post_update( array(
     
    14481448        );
    14491449
    1450         $a = $this->factory->activity->create( $args );
     1450        $a = self::factory()->activity->create( $args );
    14511451
    14521452        $this->assertEquals( $a, bp_activity_get_activity_id( $args ) );
     
    14651465        );
    14661466
    1467         $a = $this->factory->activity->create( $args );
     1467        $a = self::factory()->activity->create( $args );
    14681468
    14691469        $this->assertTrue( bp_activity_delete_by_item_id( $args ) );
Note: See TracChangeset for help on using the changeset viewer.