1
0
Fork 0
mirror of https://github.com/buddypress/buddypress.git synced 2026-07-22 20:56:55 +08:00
buddypress/tests/phpunit/testcases/core/functions/bpGetRefererPath.php
Mathieu Viet 89a6666dc6 Fully enjoy Yoast’s PHPUnit polyfills
Using these polyfills let us use PHPUnit v9.x for our tests and add PHP 8.1 to our testing matrix. Some additional edits to our PHP unit tests suite were needed:

- Stop using PHPunit deprecated functions.
- Rename some `BP_UnitTestCase` methods to use Yoast's polyfills.
- Edit the PHP Unit test GH action and also run this action on pull requests.
- Update some composer dependencies, remove the one about `phpunit/phpunit:^7.5` and add a new composer script to use PHPUnit v9.x. 

Props renatonascalves, rafiahmedd

Closes https://github.com/buddypress/buddypress/pull/13
Fixes #8649


git-svn-id: https://buddypress.svn.wordpress.org/trunk@13314 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
2022-08-13 08:58:51 +00:00

79 lines
2.1 KiB
PHP

<?php
/**
* @group core
* @group functions
* @group bp_get_referer_path
*/
class BP_Tests_Core_Functions_BPGetRefererPath extends BP_UnitTestCase {
private $_wp_http_referer = '';
private $http_referer = '';
public function set_up() {
parent::set_up();
$this->_wp_http_referer = '';
$this->http_referer = '';
if ( isset( $_REQUEST['_wp_http_referer'] ) ) {
$this->_wp_http_referer = $_REQUEST['_wp_http_referer'];
}
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
$this->http_referer = $_SERVER['HTTP_REFERER'];
}
}
public function tear_down() {
if ( isset( $_REQUEST['_wp_http_referer'] ) ) {
unset( $_REQUEST['_wp_http_referer'] );
}
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
unset( $_SERVER['HTTP_REFERER'] );
}
if ( $this->_wp_http_referer ) {
$_REQUEST['_wp_http_referer'] = $this->_wp_http_referer;
}
if ( $this->http_referer ) {
$_SERVER['HTTP_REFERER'] = $this->http_referer;
}
parent::tear_down();
}
public function test_from__wp_http_referer_fully_qualified_uri() {
$home = get_option( 'home' );
$_REQUEST['_wp_http_referer'] = trailingslashit( $home ) . 'foo/';
$found = bp_get_referer_path();
$this->assertSame( '/foo/', bp_get_referer_path() );
}
public function test_from__wp_http_referer_absolute_path() {
$_REQUEST['_wp_http_referer'] = '/foo/';
$found = bp_get_referer_path();
$this->assertSame( '/foo/', bp_get_referer_path() );
}
public function test_from_server_request_uri_fully_qualified_uri() {
$home = get_option( 'home' );
$_SERVER['HTTP_REFERER'] = trailingslashit( $home ) . 'foo/';
$found = bp_get_referer_path();
$this->assertSame( '/foo/', bp_get_referer_path() );
}
public function test_from_server_request_uri_absolute_path() {
$_SERVER['HTTP_REFERER'] = '/foo/';
$found = bp_get_referer_path();
$this->assertSame( '/foo/', bp_get_referer_path() );
}
public function test__wp_http_referer_should_take_precedence_over_server_superglobal() {
$_SERVER['HTTP_REFERER'] = '/foo/';
$_REQUEST['_wp_http_referer'] = '/bar/';
$found = bp_get_referer_path();
$this->assertSame( '/bar/', bp_get_referer_path() );
}
}