forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for wc_get_current_admin_url()
- Loading branch information
1 parent
a464b7a
commit 3c1132e
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Unit tests for the WC_Admin_Functions_Test class | ||
* | ||
* @package WooCommerce\Tests\Admin | ||
*/ | ||
|
||
/** | ||
* Class WC_Admin_Functions_Test_Test | ||
*/ | ||
class WC_Admin_Functions_Test extends \WC_Unit_Test_Case { | ||
|
||
/** | ||
* Load up the importer classes since they aren't loaded by default. | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$bootstrap = \WC_Unit_Tests_Bootstrap::instance(); | ||
require_once $bootstrap->plugin_dir . '/includes/admin/wc-admin-functions.php'; | ||
} | ||
|
||
/** | ||
* Test wc_get_current_admin_url() function. | ||
*/ | ||
public function test_wc_get_current_admin_url() { | ||
// Since REQUEST_URI is empty on unit tests it should return an empty string. | ||
if ( empty( $_SERVER['REQUEST_URI'] ) ) { | ||
$this->assertEquals( '', wc_get_current_admin_url() ); | ||
} | ||
|
||
// Test with REQUEST_URI. | ||
$default_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
$_SERVER['REQUEST_URI'] = '/wp-admin/admin.php?page=wc-admin&foo=bar'; | ||
$this->assertEquals( admin_url( 'admin.php?page=wc-admin&foo=bar' ), wc_get_current_admin_url() ); | ||
|
||
// Test if nonce gets removed. | ||
$_SERVER['REQUEST_URI'] = '/wp-admin/admin.php?page=wc-admin&_wpnonce=xxxxxxxxxxxx'; | ||
$this->assertEquals( admin_url( 'admin.php?page=wc-admin' ), wc_get_current_admin_url() ); | ||
|
||
// Restore REQUEST_URI. | ||
$_SERVER['REQUEST_URI'] = $default_uri; | ||
} | ||
} |