[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/functions/ -> bpVerifyNonceRequest.php (source)

   1  <?php
   2  
   3  /**
   4   * @group core
   5   * @group functions
   6   * @group bp_verify_nonce_request
   7   */
   8  class BP_Tests_Core_Functions_BPVerifyNonceRequest extends BP_UnitTestCase {
   9      private $http_host = '';
  10      private $server_port = '';
  11      private $request_uri = '';
  12  
  13  	public function setUp() {
  14          parent::setUp();
  15  
  16          if ( isset( $_SERVER['HTTP_HOST'] ) ) {
  17              $this->http_host = $_SERVER['HTTP_HOST'];
  18          }
  19  
  20          if ( isset( $_SERVER['SERVER_PORT'] ) ) {
  21              $this->server_port = $_SERVER['SERVER_PORT'];
  22          }
  23  
  24          if ( isset( $_SERVER['REQUEST_URI'] ) ) {
  25              $this->request_uri = $_SERVER['REQUEST_URI'];
  26          }
  27      }
  28  
  29  	public function tearDown() {
  30          if ( '' !== $this->http_host ) {
  31              $_SERVER['HTTP_HOST'] = $this->http_host;
  32          }
  33  
  34          if ( '' !== $this->server_port ) {
  35              $_SERVER['SERVER_PORT'] = $this->server_port;
  36          }
  37  
  38          if ( '' !== $this->request_uri ) {
  39              $_SERVER['REQUEST_URI'] = $this->request_uri;
  40          }
  41  
  42          parent::tearDown();
  43      }
  44  
  45      public function test_bp_verify_nonce_request_with_port_in_home_url_and_wordpress_installed_in_subdirectory() {
  46          // fake various $_SERVER parameters
  47          $host = explode( ':', $_SERVER['HTTP_HOST'] );
  48          $_SERVER['HTTP_HOST'] = $host[0] . ':80';
  49          $_SERVER['SERVER_PORT'] = 80;
  50          $_SERVER['REQUEST_URI'] = '/wordpress/';
  51  
  52          // add port number and subdirectory to home URL for testing
  53          add_filter( 'home_url', array( $this, 'add_port_and_subdirectory_to_home_url' ), 10, 3 );
  54  
  55          // test bp_verify_nonce_request()
  56          $action = 'verify-this';
  57          $_REQUEST[$action] = wp_create_nonce( $action );
  58          $test = bp_verify_nonce_request( $action, $action );
  59  
  60          // clean up!
  61          remove_filter( 'home_url', array( $this, 'add_port_and_subdirectory_to_home_url' ), 10 );
  62          unset( $_REQUEST[$action] );
  63  
  64          // assert!
  65          $this->assertSame( 1, $test );
  66      }
  67  
  68      /**
  69       * Add port 80 and /wordpress/ subdirectory to home URL.
  70       *
  71       * @param string      $url         The complete home URL including scheme and path.
  72       * @param string      $path        Path relative to the home URL. Blank string if no path is specified.
  73       * @param string|null $orig_scheme Scheme to give the home URL context. Accepts 'http', 'https', 'relative' or null.
  74       * @return string
  75       */
  76  	public function add_port_and_subdirectory_to_home_url( $url, $path, $scheme ) {
  77          $home = parse_url( get_option( 'home' ) );
  78          $home_path = isset( $home['path'] ) ? $home['path'] : '';
  79          return $scheme . '://' . $home['host'] . ':80' . $home_path . '/wordpress' . $path;
  80      }
  81  }


Generated: Sun Nov 24 01:00:53 2024 Cross-referenced by PHPXref 0.7.1