[ 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  
   5  /**
   6   * @group core
   7   * @group BP_Component
   8   */
   9  class BP_Tests_BP_Component_TestCases extends BP_UnitTestCase {
  10  	public function setUp() {
  11          parent::setUp();
  12  
  13          $bp = buddypress();
  14          $bp->unit_test_rest = new stdClass;
  15          $bp->unit_test_rest->controllers = array();
  16      }
  17  
  18  	public function remove_controller( $controllers ) {
  19          return array_diff( $controllers, array( 'BP_REST_Members_Endpoint' ) );
  20      }
  21  
  22  	public function add_controller( $controllers ) {
  23          return array_merge( $controllers, array( 'Foo_Bar' ) );
  24      }
  25  
  26  	public function test_rest_api_init_for_members_component() {
  27          $bp_members = new BP_Members_Component();
  28          $bp         = buddypress();
  29  
  30          $bp_members->rest_api_init();
  31  
  32          $this->assertSame( $bp->unit_test_rest->controllers, array(
  33              'BP_REST_Components_Endpoint',
  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_Components_Endpoint',
  52              'BP_REST_Attachments_Member_Avatar_Endpoint',
  53              'BP_REST_Attachments_Member_Cover_Endpoint',
  54          ) );
  55      }
  56  
  57      public function test_rest_api_init_for_members_component_cannot_add_controller() {
  58          $bp_members = new BP_Members_Component();
  59          $bp         = buddypress();
  60  
  61          add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  62  
  63          $bp_members->rest_api_init();
  64  
  65          remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  66  
  67          $this->assertSame( $bp->unit_test_rest->controllers, array(
  68              'BP_REST_Components_Endpoint',
  69              'BP_REST_Members_Endpoint',
  70              'BP_REST_Attachments_Member_Avatar_Endpoint',
  71              'BP_REST_Attachments_Member_Cover_Endpoint',
  72          ) );
  73      }
  74  }


Generated: Tue Dec 1 01:01:37 2020 Cross-referenced by PHPXref 0.7.1