[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/blogs/ -> class-bp-blogs-blog.php (source)

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


Generated: Thu Dec 5 01:01:36 2019 Cross-referenced by PHPXref 0.7.1