| 134 | |
| 135 | /** |
| 136 | * @group get_order_by |
| 137 | */ |
| 138 | public function test_get_order_by() { |
| 139 | if ( ! is_multisite() ) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | $old_user = get_current_user_id(); |
| 144 | |
| 145 | $u = $this->factory->user->create(); |
| 146 | $this->set_current_user( $u ); |
| 147 | $bs = array( |
| 148 | 'foobar' => $this->factory->blog->create( array( |
| 149 | 'title' => 'Foo Bar Blog', |
| 150 | 'user_id' => $u, |
| 151 | 'path' => '/path' . rand() . time() . '/', |
| 152 | ) ), |
| 153 | 'barfoo' => $this->factory->blog->create( array( |
| 154 | 'title' => 'Bar foo Blog', |
| 155 | 'user_id' => $u, |
| 156 | 'path' => '/path' . rand() . time() . '/', |
| 157 | ) ), |
| 158 | ); |
| 159 | |
| 160 | bp_blogs_record_existing_blogs(); |
| 161 | |
| 162 | // make the blog public or it won't turn up in generic results |
| 163 | foreach ( $bs as $b ) { |
| 164 | update_blog_option( $b, 'blog_public', '1' ); |
| 165 | } |
| 166 | |
| 167 | // Used to make sure barfoo is older than foobar |
| 168 | $b_time = date_i18n( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ); |
| 169 | |
| 170 | /* Alphabetical */ |
| 171 | $blogs = BP_Blogs_Blog::get( 'alphabetical', false, false, $u ); |
| 172 | $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); |
| 173 | $this->assertEquals( array( $bs['barfoo'], $bs['foobar'] ), $blog_ids ); |
| 174 | |
| 175 | /* Newest */ |
| 176 | update_blog_details( $bs['barfoo'], array( 'registered' => $b_time ) ); |
| 177 | $blogs = BP_Blogs_Blog::get( 'newest', false, false, $u ); |
| 178 | $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); |
| 179 | $this->assertEquals( array( $bs['foobar'], $bs['barfoo'] ), $blog_ids ); |
| 180 | |
| 181 | /* Active */ |
| 182 | bp_blogs_update_blogmeta( $bs['barfoo'], 'last_activity', $b_time ); |
| 183 | $blogs = BP_Blogs_Blog::get( 'active', false, false, $u ); |
| 184 | $blog_ids = wp_list_pluck( $blogs['blogs'], 'blog_id' ); |
| 185 | $this->assertEquals( array( $bs['foobar'],$bs['barfoo'] ), $blog_ids ); |
| 186 | |
| 187 | /* Random */ |
| 188 | $blogs = BP_Blogs_Blog::get( 'random', false, false, $u ); |
| 189 | $this->assertTrue( 2 == count( $blogs['blogs'] ) ); |
| 190 | |
| 191 | $this->set_current_user( $old_user ); |
| 192 | |
| 193 | foreach ( $bs as $d ) { |
| 194 | wpmu_delete_blog( $d, true ); |
| 195 | } |
| 196 | } |