[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> class-bp-component.php (source)

   1  <?php
   2  
   3  include_once BP_TESTS_DIR . '/assets/bp-rest-api-controllers.php';
   4  include_once BP_TESTS_DIR . '/assets/class-bptest-component.php';
   5  
   6  /**
   7   * @group core
   8   * @group BP_Component
   9   */
  10  class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase {
  11  	public function setUp() {
  12          parent::setUp();
  13  
  14          $bp = buddypress();
  15          $bp->unit_test_rest = new stdClass;
  16          $bp->unit_test_rest->controllers = array();
  17      }
  18  
  19  	public function remove_controller( $controllers ) {
  20          return array_diff( $controllers, array( 'BP_REST_Members_Endpoint' ) );
  21      }
  22  
  23  	public function add_controller( $controllers ) {
  24          return array_merge( $controllers, array( 'Foo_Bar' ) );
  25      }
  26  
  27  	public function test_rest_api_init_for_members_component() {
  28          $bp_members = new BP_Members_Component();
  29          $bp         = buddypress();
  30  
  31          $bp_members->rest_api_init();
  32  
  33          $this->assertSame( $bp->unit_test_rest->controllers, array(
  34              'BP_REST_Members_Endpoint',
  35              'BP_REST_Attachments_Member_Avatar_Endpoint',
  36              'BP_REST_Attachments_Member_Cover_Endpoint',
  37          ) );
  38      }
  39  
  40      public function test_rest_api_init_for_members_component_can_remove_controller() {
  41          $bp_members = new BP_Members_Component();
  42          $bp         = buddypress();
  43  
  44          add_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
  45  
  46          $bp_members->rest_api_init();
  47  
  48          remove_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
  49  
  50          $this->assertSame( $bp->unit_test_rest->controllers, array(
  51              'BP_REST_Attachments_Member_Avatar_Endpoint',
  52              'BP_REST_Attachments_Member_Cover_Endpoint',
  53          ) );
  54      }
  55  
  56      public function test_rest_api_init_for_members_component_cannot_add_controller() {
  57          $bp_members = new BP_Members_Component();
  58          $bp         = buddypress();
  59  
  60          add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  61  
  62          $bp_members->rest_api_init();
  63  
  64          remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  65  
  66          $this->assertSame( $bp->unit_test_rest->controllers, array(
  67              'BP_REST_Members_Endpoint',
  68              'BP_REST_Attachments_Member_Avatar_Endpoint',
  69              'BP_REST_Attachments_Member_Cover_Endpoint',
  70          ) );
  71      }
  72  
  73      /**
  74       * @group bp_blocks
  75       */
  76  	public function test_component_block_globals() {
  77          $expected = array(
  78              'dynamic_widget_classname' => 'widget_example_classname',
  79          );
  80  
  81          $example = new BPTest_Component(
  82              array(
  83                  'globals' => array(
  84                      'block_globals' => array(
  85                          'bp/example-block' => $expected,
  86                      )
  87                  ),
  88              )
  89          );
  90  
  91          do_action( 'bp_setup_globals' );
  92  
  93          $this->assertEquals( $expected, $example->block_globals['bp/example-block']->props );
  94      }
  95  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1