[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/activity/functions/ -> bpActivityGetActions.php (source)

   1  <?php
   2  
   3  /**
   4   * @group activity
   5   * @covers ::bp_activity_get_actions
   6   */
   7  class BP_Tests_Activity_Functions_BpActivityGetActions extends BP_UnitTestCase {
   8      protected $reset_actions;
   9      protected $reset_actions_sorted;
  10  
  11  	public function setUp() {
  12          parent::setUp();
  13          $bp = buddypress();
  14  
  15          $this->reset_actions = clone $bp->activity->actions;
  16          $bp->activity->actions = new stdClass();
  17  
  18          $this->reset_actions_sorted = ! empty( $bp->activity->actions_sorted );
  19          unset( $bp->activity->actions_sorted );
  20      }
  21  
  22  	public function tearDown() {
  23          parent::tearDown();
  24          $bp = buddypress();
  25  
  26          $bp->activity->actions = $this->reset_actions;
  27  
  28          if ( $this->reset_actions_sorted ) {
  29              $bp->activity->actions_sorted = true;
  30          } else {
  31              unset( $bp->activity->actions_sorted );
  32          }
  33      }
  34  
  35      /**
  36       * @group activity_action
  37       */
  38      public function test_bp_activity_get_actions_should_sort_by_position() {
  39          register_post_type( 'foo5', array(
  40              'public'      => true,
  41              'supports'    => array( 'buddypress-activity' ),
  42              'bp_activity' => array(
  43                  'component_id' => 'foo',
  44                  'action_id' => 'foo_bar_5',
  45                  'position' => 5,
  46              ),
  47          ) );
  48  
  49          register_post_type( 'foo50', array(
  50              'public'      => true,
  51              'supports'    => array( 'buddypress-activity' ),
  52              'bp_activity' => array(
  53                  'component_id' => 'foo',
  54                  'action_id' => 'foo_bar_50',
  55                  'position' => 50,
  56              ),
  57          ) );
  58  
  59          register_post_type( 'foo25', array(
  60              'public'      => true,
  61              'supports'    => array( 'buddypress-activity' ),
  62              'bp_activity' => array(
  63                  'component_id' => 'foo',
  64                  'action_id' => 'foo_bar_25',
  65                  'position' => 25,
  66              ),
  67          ) );
  68  
  69          $actions = bp_activity_get_actions();
  70  
  71          _unregister_post_type( 'foo5' );
  72          _unregister_post_type( 'foo25' );
  73          _unregister_post_type( 'foo50' );
  74  
  75          $expected = array(
  76              'foo_bar_5',
  77              'foo_bar_25',
  78              'foo_bar_50',
  79          );
  80          $foo_actions = (array) $actions->foo;
  81          $this->assertEquals( $expected, array_values( wp_list_pluck( $foo_actions, 'key' ) ) );
  82      }
  83  
  84      /**
  85       * @ticket BP6865
  86       */
  87  	public function test_bp_activity_get_actions_sort() {
  88          bp_activity_set_action(
  89              'foo',
  90              'new_foo',
  91              'Did a foo',
  92              '',
  93              '',
  94              array(),
  95              10
  96          );
  97  
  98          bp_activity_set_action(
  99              'foo',
 100              'new_bar',
 101              'Did a bar',
 102              '',
 103              '',
 104              array(),
 105              5
 106          );
 107  
 108          $actions = bp_activity_get_actions();
 109  
 110          $expected = array(
 111              'new_bar' => 'new_bar',
 112              'new_foo' => 'new_foo',
 113          );
 114  
 115          $this->assertSame( $expected, wp_list_pluck( (array) $actions->foo, 'key' ) );
 116      }
 117  
 118      /**
 119       * @ticket BP6865
 120       */
 121  	public function test_sort_new_post_type_once() {
 122          register_post_type( 'foo', array(
 123              'label'   => 'foo',
 124              'public'   => true,
 125              'supports' => array( 'buddypress-activity' ),
 126              'bp_activity' => array(
 127                  'component_id' => 'blogs',
 128                  'action_id'    => 'new_foo',
 129                  'position'     => 1,
 130              ),
 131          ) );
 132  
 133          $actions = bp_activity_get_actions();
 134  
 135          _unregister_post_type( 'foo' );
 136  
 137          $expected = array(
 138              'new_foo'          => 'new_foo',
 139              'new_blog_post'    => 'new_blog_post',
 140              'new_blog_comment' => 'new_blog_comment',
 141          );
 142  
 143          $this->assertSame( $expected, wp_list_pluck( (array) $actions->blogs, 'key' ) );
 144      }
 145  
 146      /**
 147       * @ticket BP6865
 148       */
 149  	public function test_sort_new_post_type_twice() {
 150          $reset_activity_track = buddypress()->activity->track;
 151  
 152          $actions = bp_activity_get_actions();
 153          $expected = array(
 154              'new_blog_post'    => 'new_blog_post',
 155              'new_blog_comment' => 'new_blog_comment',
 156          );
 157          $this->assertSame( $expected, wp_list_pluck( (array) $actions->blogs, 'key' ) );
 158  
 159          register_post_type( 'foo', array(
 160              'label'   => 'foo',
 161              'public'   => true,
 162              'supports' => array( 'buddypress-activity' ),
 163              'bp_activity' => array(
 164                  'component_id' => 'blogs',
 165                  'action_id'    => 'new_foo',
 166                  'position'     => 1,
 167              ),
 168          ) );
 169  
 170          /*
 171           * Reset manually as bp_activity_get_actions() -- at the top of this test --
 172           * sets ->track[] for the previously-registered post types.
 173           */
 174          buddypress()->activity->track = bp_activity_get_post_types_tracking_args();
 175  
 176          $actions = bp_activity_get_actions();
 177  
 178          _unregister_post_type( 'foo' );
 179  
 180          $expected = array(
 181              'new_foo'          => 'new_foo',
 182              'new_blog_post'    => 'new_blog_post',
 183              'new_blog_comment' => 'new_blog_comment',
 184          );
 185  
 186          $this->assertSame( $expected, wp_list_pluck( (array) $actions->blogs, 'key' ) );
 187  
 188          buddypress()->activity->track = $reset_activity_track;
 189      }
 190  
 191      /**
 192       * @ticket BP6865
 193       */
 194  	public function test_sort_no_post_type_registered() {
 195          bp_activity_set_action(
 196              'foo',
 197              'new_foo',
 198              'Did a foo',
 199              '',
 200              '',
 201              array(),
 202              10
 203          );
 204  
 205          bp_activity_set_action(
 206              'foo',
 207              'new_bar',
 208              'Did a bar',
 209              '',
 210              '',
 211              array(),
 212              5
 213          );
 214  
 215          remove_post_type_support( 'post', 'buddypress-activity' );
 216  
 217          $actions = bp_activity_get_actions();
 218  
 219          $expected = array(
 220              'new_bar' => 'new_bar',
 221              'new_foo' => 'new_foo',
 222          );
 223  
 224          $this->assertSame( $expected, wp_list_pluck( (array) $actions->foo, 'key' ) );
 225  
 226          // Clean up.
 227          add_post_type_support( 'post', 'buddypress-activity' );
 228      }
 229  }


Generated: Tue Oct 15 01:00:54 2024 Cross-referenced by PHPXref 0.7.1