[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group core 4 * @group optouts 5 */ 6 class BP_Tests_Optouts extends BP_UnitTestCase { 7 public function test_bp_optouts_add_optout_vanilla() { 8 $old_current_user = get_current_user_id(); 9 10 $u1 = $this->factory->user->create(); 11 $this->set_current_user( $u1 ); 12 13 // Create a couple of optouts. 14 $args = array( 15 'email_address' => 'one@wp.org', 16 'user_id' => $u1, 17 'email_type' => 'annoyance' 18 ); 19 $i1 = bp_add_optout( $args ); 20 $args['email_address'] = 'two@wp.org'; 21 $i2 = bp_add_optout( $args ); 22 23 $get_args = array( 24 'user_id' => $u1, 25 'fields' => 'ids', 26 ); 27 $optouts = bp_get_optouts( $get_args ); 28 $this->assertEqualSets( array( $i1, $i2 ), $optouts ); 29 30 $this->set_current_user( $old_current_user ); 31 } 32 33 public function test_bp_optouts_add_optout_avoid_duplicates() { 34 $old_current_user = get_current_user_id(); 35 36 $u1 = $this->factory->user->create(); 37 $this->set_current_user( $u1 ); 38 39 // Create an optouts. 40 $args = array( 41 'email_address' => 'one@wp.org', 42 'user_id' => $u1, 43 'email_type' => 'annoyance' 44 ); 45 $i1 = bp_add_optout( $args ); 46 // Attempt to create a duplicate. Should return existing optout id. 47 $i2 = bp_add_optout( $args ); 48 $this->assertEquals( $i1, $i2 ); 49 50 $this->set_current_user( $old_current_user ); 51 } 52 53 public function test_bp_optouts_delete_optout() { 54 $old_current_user = get_current_user_id(); 55 56 $u1 = $this->factory->user->create(); 57 $this->set_current_user( $u1 ); 58 59 $args = array( 60 'email_address' => 'one@wp.org', 61 'user_id' => $u1, 62 'email_type' => 'annoyance' 63 ); 64 $i1 = bp_add_optout( $args ); 65 bp_delete_optout_by_id( $i1 ); 66 67 $get_args = array( 68 'user_id' => $u1, 69 'fields' => 'ids', 70 ); 71 $optouts = bp_get_optouts( $get_args ); 72 $this->assertTrue( empty( $optouts ) ); 73 74 $this->set_current_user( $old_current_user ); 75 } 76 77 public function test_bp_optouts_get_by_search_terms() { 78 $old_current_user = get_current_user_id(); 79 80 $u1 = $this->factory->user->create(); 81 $this->set_current_user( $u1 ); 82 83 // Create a couple of optouts. 84 $args = array( 85 'email_address' => 'one@wpfrost.org', 86 'user_id' => $u1, 87 'email_type' => 'annoyance' 88 ); 89 $i1 = bp_add_optout( $args ); 90 $args['email_address'] = 'two@wp.org'; 91 $i2 = bp_add_optout( $args ); 92 93 $get_args = array( 94 'search_terms' => 'one@wpfrost.org', 95 'fields' => 'ids', 96 ); 97 $optouts = bp_get_optouts( $get_args ); 98 $this->assertEqualSets( array( $i1 ), $optouts ); 99 100 $this->set_current_user( $old_current_user ); 101 } 102 103 public function test_bp_optouts_get_by_email_address_mismatched_case() { 104 $old_current_user = get_current_user_id(); 105 106 $u1 = $this->factory->user->create(); 107 $this->set_current_user( $u1 ); 108 109 // Create a couple of optouts. 110 $args = array( 111 'email_address' => 'ONE@wpfrost.org', 112 'user_id' => $u1, 113 'email_type' => 'annoyance' 114 ); 115 $i1 = bp_add_optout( $args ); 116 $args['email_address'] = 'two@WP.org'; 117 $i2 = bp_add_optout( $args ); 118 119 $get_args = array( 120 'email_address' => 'one@WPfrost.org', 121 'fields' => 'ids', 122 ); 123 $optouts = bp_get_optouts( $get_args ); 124 $this->assertEqualSets( array( $i1 ), $optouts ); 125 126 $this->set_current_user( $old_current_user ); 127 } 128 129 public function test_bp_optouts_get_by_search_terms_mismatched_case() { 130 $old_current_user = get_current_user_id(); 131 132 $u1 = $this->factory->user->create(); 133 $this->set_current_user( $u1 ); 134 135 // Create a couple of optouts. 136 $args = array( 137 'email_address' => 'ONE@wpfrost.org', 138 'user_id' => $u1, 139 'email_type' => 'annoyance' 140 ); 141 $i1 = bp_add_optout( $args ); 142 $args['email_address'] = 'two@WP.org'; 143 $i2 = bp_add_optout( $args ); 144 145 $get_args = array( 146 'search_terms' => 'one@wpfrost.org', 147 'fields' => 'ids', 148 ); 149 $optouts = bp_get_optouts( $get_args ); 150 $this->assertEqualSets( array( $i1 ), $optouts ); 151 152 $this->set_current_user( $old_current_user ); 153 } 154 155 156 public function test_bp_optouts_get_by_email_address_mismatched_case_after_update() { 157 $old_current_user = get_current_user_id(); 158 159 $u1 = $this->factory->user->create(); 160 $this->set_current_user( $u1 ); 161 162 // Create an opt-out. 163 $args = array( 164 'email_address' => 'ONE@wpfrost.org', 165 'user_id' => $u1, 166 'email_type' => 'annoyance' 167 ); 168 $i1 = bp_add_optout( $args ); 169 // Update it. 170 $oo_class = new BP_Optout( $i1 ); 171 $oo_class->email_address = 'One@wpFrost.org'; 172 $oo_class->save(); 173 174 $get_args = array( 175 'email_address' => 'one@WPfrost.org', 176 'fields' => 'ids', 177 ); 178 $optouts = bp_get_optouts( $get_args ); 179 $this->assertEqualSets( array( $i1 ), $optouts ); 180 181 $this->set_current_user( $old_current_user ); 182 } 183 184 public function test_bp_optout_prevents_bp_email_send() { 185 $old_current_user = get_current_user_id(); 186 187 $u1 = $this->factory->user->create(); 188 $this->set_current_user( $u1 ); 189 // Create an opt-out. 190 $args = array( 191 'email_address' => 'test2@example.com', 192 'user_id' => $u1, 193 'email_type' => 'annoyance' 194 ); 195 $i1 = bp_add_optout( $args ); 196 $email = new BP_Email( 'activity-at-message' ); 197 $email->set_from( 'test1@example.com' )->set_to( 'test2@example.com' )->set_subject( 'testing' ); 198 $email->set_content_html( 'testing' )->set_tokens( array( 'poster.name' => 'example' ) ); 199 200 $this->assertTrue( is_wp_error( $email->validate() ) ); 201 $this->set_current_user( $old_current_user ); 202 } 203 204 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 22 01:00:56 2024 | Cross-referenced by PHPXref 0.7.1 |