[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/tests/phpunit/testcases/common/ -> verify-nonce.php (source)

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


Generated: Tue Mar 19 01:01:02 2024 Cross-referenced by PHPXref 0.7.1