[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @group blogs 5 * @group BP_Blogs_Blog 6 */ 7 class BP_Tests_BP_Blogs_Blog_TestCases extends BP_UnitTestCase { 8 public function test_get_with_search_terms() { 9 if ( ! is_multisite() ) { 10 $this->markTestSkipped(); 11 } 12 13 $old_user = get_current_user_id(); 14 15 $u = self::factory()->user->create(); 16 $this->set_current_user( $u ); 17 $b = self::factory()->blog->create( array( 18 'title' => 'The Foo Bar Blog', 19 'user_id' => $u, 20 ) ); 21 bp_blogs_record_existing_blogs(); 22 23 // make the blog public or it won't turn up in generic results 24 update_blog_option( $b, 'blog_public', '1' ); 25 26 $blogs = BP_Blogs_Blog::get( [ 27 'type' => 'active', 28 'search_terms' => 'Foo' 29 ] ); 30 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 31 32 $this->assertEquals( array( $b ), $blog_ids ); 33 } 34 35 /** 36 * @ticket BP5858 37 */ 38 public function test_get_with_search_terms_should_match_description() { 39 if ( ! is_multisite() ) { 40 $this->markTestSkipped(); 41 } 42 43 $old_user = get_current_user_id(); 44 45 $u = self::factory()->user->create(); 46 $this->set_current_user( $u ); 47 $b = self::factory()->blog->create( array( 48 'title' => 'The Foo Bar Blog', 49 'domain' => __METHOD__, 50 'user_id' => $u, 51 ) ); 52 update_blog_option( $b, 'blogdescription', 'Full of foorificness' ); 53 bp_blogs_record_existing_blogs(); 54 55 // make the blog public or it won't turn up in generic results 56 update_blog_option( $b, 'blog_public', '1' ); 57 58 $blogs = BP_Blogs_Blog::get( [ 59 'type' => 'active', 60 'search_terms' => 'Full' 61 ] ); 62 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 63 64 $this->assertEquals( array( $b ), $blog_ids ); 65 $this->assertEquals( 1, $blogs['total'] ); 66 } 67 68 public function test_search_blogs() { 69 if ( ! is_multisite() ) { 70 $this->markTestSkipped(); 71 } 72 73 $old_user = get_current_user_id(); 74 75 $u = self::factory()->user->create(); 76 $this->set_current_user( $u ); 77 $b = self::factory()->blog->create( array( 78 'title' => 'The Foo Bar Blog', 79 'user_id' => $u, 80 'path' => '/path' . rand() . time() . '/', 81 ) ); 82 bp_blogs_record_existing_blogs(); 83 84 // make the blog public or it won't turn up in generic results 85 update_blog_option( $b, 'blog_public', '1' ); 86 87 $blogs = BP_Blogs_Blog::search_blogs( 'Foo' ); 88 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 89 90 $this->assertEquals( array( $b ), $blog_ids ); 91 } 92 93 /** 94 * @group get_by_letter 95 */ 96 public function test_get_by_letter() { 97 if ( ! is_multisite() ) { 98 $this->markTestSkipped(); 99 return; 100 } 101 102 $old_user = get_current_user_id(); 103 104 $u = self::factory()->user->create(); 105 $this->set_current_user( $u ); 106 $b = self::factory()->blog->create( array( 107 'title' => 'Foo Bar Blog', 108 'user_id' => $u, 109 'path' => '/path' . rand() . time() . '/', 110 ) ); 111 bp_blogs_record_existing_blogs(); 112 113 // make the blog public or it won't turn up in generic results 114 update_blog_option( $b, 'blog_public', '1' ); 115 116 $blogs = BP_Blogs_Blog::get_by_letter( 'F' ); 117 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 118 119 $this->assertEquals( array( $b ), $blog_ids ); 120 } 121 122 /** 123 * @group get_order_by 124 */ 125 public function test_get_order_by() { 126 if ( ! is_multisite() ) { 127 $this->markTestSkipped(); 128 } 129 130 $old_user = get_current_user_id(); 131 132 $u = self::factory()->user->create(); 133 $this->set_current_user( $u ); 134 $bs = array( 135 'foobar' => self::factory()->blog->create( array( 136 'title' => 'Foo Bar Blog', 137 'user_id' => $u, 138 'path' => '/path' . rand() . time() . '/', 139 ) ), 140 'barfoo' => self::factory()->blog->create( array( 141 'title' => 'Bar foo Blog', 142 'user_id' => $u, 143 'path' => '/path' . rand() . time() . '/', 144 ) ), 145 ); 146 147 bp_blogs_record_existing_blogs(); 148 149 // make the blog public or it won't turn up in generic results 150 foreach ( $bs as $b ) { 151 update_blog_option( $b, 'blog_public', '1' ); 152 } 153 154 // Used to make sure barfoo is older than foobar 155 $b_time = date_i18n( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); 156 157 /* Alphabetical */ 158 $blogs = BP_Blogs_Blog::get( [ 'type' => 'alphabetical', 'user_id' => $u ] ); 159 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 160 $this->assertEquals( array( $bs['barfoo'], $bs['foobar'] ), $blog_ids ); 161 162 /* Newest */ 163 update_blog_details( $bs['barfoo'], array( 'registered' => $b_time ) ); 164 $blogs = BP_Blogs_Blog::get( [ 'type' => 'newest', 'user_id' => $u ] ); 165 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 166 $this->assertEquals( array( $bs['foobar'], $bs['barfoo'] ), $blog_ids ); 167 168 /* Active */ 169 bp_blogs_update_blogmeta( $bs['barfoo'], 'last_activity', $b_time ); 170 $blogs = BP_Blogs_Blog::get( [ 'type' => 'active', 'user_id' => $u ] ); 171 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 172 $this->assertEquals( array( $bs['foobar'],$bs['barfoo'] ), $blog_ids ); 173 174 /* Random */ 175 $blogs = BP_Blogs_Blog::get( [ 'type' => 'random', 'user_id' => $u ] ); 176 $this->assertTrue( 2 == count( $blogs['blogs'] ) ); 177 178 $this->set_current_user( $old_user ); 179 } 180 181 /** 182 * @group date_query 183 */ 184 public function test_get_with_date_query_before() { 185 if ( ! is_multisite() ) { 186 $this->markTestSkipped(); 187 } 188 189 $old_user = get_current_user_id(); 190 $u = self::factory()->user->create(); 191 $this->set_current_user( $u ); 192 193 $r = [ 194 'user_id' => $u 195 ]; 196 197 $b1 = self::factory()->blog->create( $r ); 198 $b2 = self::factory()->blog->create( $r ); 199 $b3 = self::factory()->blog->create( $r ); 200 201 bp_blogs_record_existing_blogs(); 202 203 // Set last activity for each site. 204 bp_blogs_update_blogmeta( $b1, 'last_activity', date( 'Y-m-d H:i:s', time() ) ); 205 bp_blogs_update_blogmeta( $b2, 'last_activity', '2008-03-25 17:13:55' ); 206 bp_blogs_update_blogmeta( $b3, 'last_activity', '2010-01-01 12:00' ); 207 208 // 'date_query' before test 209 $sites = BP_Blogs_Blog::get( array( 210 'date_query' => array( array( 211 'before' => array( 212 'year' => 2010, 213 'month' => 1, 214 'day' => 1, 215 ), 216 ) ) 217 ) ); 218 219 $this->assertEquals( [ $b2 ], wp_list_pluck( $sites['blogs'], 'blog_id' ) ); 220 } 221 222 /** 223 * @group date_query 224 */ 225 public function test_get_with_date_query_range() { 226 if ( ! is_multisite() ) { 227 $this->markTestSkipped(); 228 } 229 230 $old_user = get_current_user_id(); 231 $u = self::factory()->user->create(); 232 $this->set_current_user( $u ); 233 234 $r = [ 235 'user_id' => $u 236 ]; 237 238 $b1 = self::factory()->blog->create( $r ); 239 $b2 = self::factory()->blog->create( $r ); 240 $b3 = self::factory()->blog->create( $r ); 241 242 bp_blogs_record_existing_blogs(); 243 244 // Set last activity for each site. 245 bp_blogs_update_blogmeta( $b1, 'last_activity', date( 'Y-m-d H:i:s', time() ) ); 246 bp_blogs_update_blogmeta( $b2, 'last_activity', '2008-03-25 17:13:55' ); 247 bp_blogs_update_blogmeta( $b3, 'last_activity', '2001-01-01 12:00' ); 248 249 // 'date_query' range test 250 $sites = BP_Blogs_Blog::get( array( 251 'date_query' => array( array( 252 'after' => 'January 2nd, 2001', 253 'before' => array( 254 'year' => 2010, 255 'month' => 1, 256 'day' => 1, 257 ), 258 'inclusive' => true, 259 ) ) 260 ) ); 261 262 $this->assertEquals( [ $b2 ], wp_list_pluck( $sites['blogs'], 'blog_id' ) ); 263 } 264 265 /** 266 * @group date_query 267 */ 268 public function test_get_with_date_query_after() { 269 if ( ! is_multisite() ) { 270 $this->markTestSkipped(); 271 } 272 273 $old_user = get_current_user_id(); 274 $u = self::factory()->user->create(); 275 $this->set_current_user( $u ); 276 277 $r = [ 278 'user_id' => $u 279 ]; 280 281 $b1 = self::factory()->blog->create( $r ); 282 $b2 = self::factory()->blog->create( $r ); 283 $b3 = self::factory()->blog->create( $r ); 284 285 bp_blogs_record_existing_blogs(); 286 287 // Set last activity for each site. 288 bp_blogs_update_blogmeta( $b1, 'last_activity', date( 'Y-m-d H:i:s', time() ) ); 289 bp_blogs_update_blogmeta( $b2, 'last_activity', '2008-03-25 17:13:55' ); 290 bp_blogs_update_blogmeta( $b3, 'last_activity', '2001-01-01 12:00' ); 291 292 /* 293 * Set initial site's last activity to two days ago so our expected site 294 * is the only match. 295 */ 296 bp_blogs_update_blogmeta( 1, 'last_activity', date( 'Y-m-d H:i:s', strtotime( '-2 days' ) ) ); 297 298 // 'date_query' after and relative test 299 $sites = BP_Blogs_Blog::get( array( 300 'date_query' => array( array( 301 'after' => '1 day ago' 302 ) ) 303 ) ); 304 305 $this->assertEquals( [ $b1 ], wp_list_pluck( $sites['blogs'], 'blog_id' ) ); 306 } 307 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |