[ 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          ) );
  36      }
  37  
  38      public function test_rest_api_init_for_members_component_can_remove_controller() {
  39          $bp_members = new BP_Members_Component();
  40          $bp         = buddypress();
  41  
  42          add_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
  43  
  44          $bp_members->rest_api_init();
  45  
  46          remove_filter( 'bp_members_rest_api_controllers', array( $this, 'remove_controller' ) );
  47  
  48          $this->assertSame( $bp->unit_test_rest->controllers, array(
  49              'BP_REST_Components_Endpoint',
  50          ) );
  51      }
  52  
  53      public function test_rest_api_init_for_members_component_cannot_add_controller() {
  54          $bp_members = new BP_Members_Component();
  55          $bp         = buddypress();
  56  
  57          add_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  58  
  59          $bp_members->rest_api_init();
  60  
  61          remove_filter( 'bp_members_rest_api_controllers', array( $this, 'add_controller' ) );
  62  
  63          $this->assertSame( $bp->unit_test_rest->controllers, array(
  64              'BP_REST_Components_Endpoint',
  65              'BP_REST_Members_Endpoint',
  66          ) );
  67      }
  68  }


Generated: Wed Feb 26 01:01:33 2020 Cross-referenced by PHPXref 0.7.1