-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66e743b
commit 06aaf18
Showing
1 changed file
with
57 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,57 @@ | ||
<?php | ||
/** | ||
* Class file for Test_Disable_Dashboard_Widgets | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package wp-alleyvate | ||
*/ | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Alley\WP\Alleyvate\Features; | ||
|
||
use Mantle\Testkit\Test_Case; | ||
|
||
/** | ||
* Tests for disabling selected unpopular dashboard widgets. | ||
*/ | ||
final class DisableXMLRPCTest extends Test_Case { | ||
|
||
/** | ||
* Test that widgets have been removed. | ||
*/ | ||
public function test_disable_xmlrpc(): void { | ||
// Get a list of IPs from Jetpack. | ||
$this->fake_request( 'https://jetpack.com/ips-v4.json' ) | ||
->with_response_code( 200 ) | ||
->with_body( '["192.0.80.5","192.0.80.6","192.0.80.7"]' ); | ||
|
||
// Make XMLRPC Request. | ||
// Use the XML-RPC "sayHello" method. | ||
$request = '<?xml version="1.0"?>' . | ||
'<methodCall>' . | ||
'<methodName>demo.sayHello</methodName>' . | ||
'</methodCall>'; | ||
|
||
// Make the XML-RPC request with HTTP_X_FORWARDED_FOR header. | ||
$response = wp_remote_post( site_url( '/xmlrpc.php' ), [ | ||
'headers' => [ | ||
'Content-Type' => 'application/xml', | ||
'HTTP_X_FORWARDED_FOR' => '192.0.80.5', | ||
], | ||
'body' => $request, | ||
] ); | ||
|
||
// Assert that the response is valid. | ||
$this->assertNotWPError( $response ); | ||
$this->assertEquals( 200, wp_remote_retrieve_response_code( $response ) ); | ||
|
||
// Check that the response body includes the expected output from "sayHello". | ||
$responseBody = wp_remote_retrieve_body( $response ); | ||
$this->assertStringContainsString( 'Hello', $responseBody ); | ||
} | ||
} |