[ 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( 'active', false, false, 0, 'Foo' ); 27 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 28 29 $this->assertEquals( array( $b ), $blog_ids ); 30 } 31 32 /** 33 * @ticket BP5858 34 */ 35 public function test_get_with_search_terms_should_match_description() { 36 if ( ! is_multisite() ) { 37 $this->markTestSkipped(); 38 } 39 40 $old_user = get_current_user_id(); 41 42 $u = self::factory()->user->create(); 43 $this->set_current_user( $u ); 44 $b = self::factory()->blog->create( array( 45 'title' => 'The Foo Bar Blog', 46 'domain' => __METHOD__, 47 'user_id' => $u, 48 ) ); 49 update_blog_option( $b, 'blogdescription', 'Full of foorificness' ); 50 bp_blogs_record_existing_blogs(); 51 52 // make the blog public or it won't turn up in generic results 53 update_blog_option( $b, 'blog_public', '1' ); 54 55 $blogs = BP_Blogs_Blog::get( 'active', false, false, 0, 'Full' ); 56 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 57 58 $this->assertEquals( array( $b ), $blog_ids ); 59 $this->assertEquals( 1, $blogs['total'] ); 60 } 61 62 public function test_search_blogs() { 63 if ( ! is_multisite() ) { 64 $this->markTestSkipped(); 65 } 66 67 $old_user = get_current_user_id(); 68 69 $u = self::factory()->user->create(); 70 $this->set_current_user( $u ); 71 $b = self::factory()->blog->create( array( 72 'title' => 'The Foo Bar Blog', 73 'user_id' => $u, 74 'path' => '/path' . rand() . time() . '/', 75 ) ); 76 bp_blogs_record_existing_blogs(); 77 78 // make the blog public or it won't turn up in generic results 79 update_blog_option( $b, 'blog_public', '1' ); 80 81 $blogs = BP_Blogs_Blog::search_blogs( 'Foo' ); 82 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 83 84 $this->assertEquals( array( $b ), $blog_ids ); 85 } 86 87 /** 88 * @group get_by_letter 89 */ 90 public function test_get_by_letter() { 91 if ( ! is_multisite() ) { 92 $this->markTestSkipped(); 93 return; 94 } 95 96 $old_user = get_current_user_id(); 97 98 $u = self::factory()->user->create(); 99 $this->set_current_user( $u ); 100 $b = self::factory()->blog->create( array( 101 'title' => 'Foo Bar Blog', 102 'user_id' => $u, 103 'path' => '/path' . rand() . time() . '/', 104 ) ); 105 bp_blogs_record_existing_blogs(); 106 107 // make the blog public or it won't turn up in generic results 108 update_blog_option( $b, 'blog_public', '1' ); 109 110 $blogs = BP_Blogs_Blog::get_by_letter( 'F' ); 111 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 112 113 $this->assertEquals( array( $b ), $blog_ids ); 114 } 115 116 /** 117 * @group get_order_by 118 */ 119 public function test_get_order_by() { 120 if ( ! is_multisite() ) { 121 $this->markTestSkipped(); 122 } 123 124 $old_user = get_current_user_id(); 125 126 $u = self::factory()->user->create(); 127 $this->set_current_user( $u ); 128 $bs = array( 129 'foobar' => self::factory()->blog->create( array( 130 'title' => 'Foo Bar Blog', 131 'user_id' => $u, 132 'path' => '/path' . rand() . time() . '/', 133 ) ), 134 'barfoo' => self::factory()->blog->create( array( 135 'title' => 'Bar foo Blog', 136 'user_id' => $u, 137 'path' => '/path' . rand() . time() . '/', 138 ) ), 139 ); 140 141 bp_blogs_record_existing_blogs(); 142 143 // make the blog public or it won't turn up in generic results 144 foreach ( $bs as $b ) { 145 update_blog_option( $b, 'blog_public', '1' ); 146 } 147 148 // Used to make sure barfoo is older than foobar 149 $b_time = date_i18n( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); 150 151 /* Alphabetical */ 152 $blogs = BP_Blogs_Blog::get( 'alphabetical', false, false, $u ); 153 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 154 $this->assertEquals( array( $bs['barfoo'], $bs['foobar'] ), $blog_ids ); 155 156 /* Newest */ 157 update_blog_details( $bs['barfoo'], array( 'registered' => $b_time ) ); 158 $blogs = BP_Blogs_Blog::get( 'newest', false, false, $u ); 159 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 160 $this->assertEquals( array( $bs['foobar'], $bs['barfoo'] ), $blog_ids ); 161 162 /* Active */ 163 bp_blogs_update_blogmeta( $bs['barfoo'], 'last_activity', $b_time ); 164 $blogs = BP_Blogs_Blog::get( 'active', false, false, $u ); 165 $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); 166 $this->assertEquals( array( $bs['foobar'],$bs['barfoo'] ), $blog_ids ); 167 168 /* Random */ 169 $blogs = BP_Blogs_Blog::get( 'random', false, false, $u ); 170 $this->assertTrue( 2 == count( $blogs['blogs'] ) ); 171 172 $this->set_current_user( $old_user ); 173 } 174 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 19 01:01:32 2021 | Cross-referenced by PHPXref 0.7.1 |