diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..22d0d82f809 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..3eef4f87f7b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +# Travis CI Configuration File + +# Tell Travis CI we're using PHP +language: php + +# whitelist branches for the "push" build check +branches: + only: + - master + +# Run Matrix for these PHP versions +php: +- "5.6" +- "7.0" +- "7.2" +- "7.3" +- "7.4" + +before_script: +- composer --version +- composer install + +script: composer test-includes diff --git a/.wp-env.json b/.wp-env.json new file mode 100644 index 00000000000..7d6841bf5b4 --- /dev/null +++ b/.wp-env.json @@ -0,0 +1,6 @@ +{ + "core": "WordPress/WordPress", + "plugins": [ "." ], + "port": "5555", + "testsPort": "5556" +} diff --git a/composer.json b/composer.json index 9923443dc5b..2fefacacd25 100644 --- a/composer.json +++ b/composer.json @@ -3,5 +3,11 @@ "description": "An authentication framework for WordPress development. Provides a standardized connection and communication framework for talking to web services.", "require": { "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "^5|^6|^7" + }, + "scripts": { + "test-includes": "phpunit includes/oauth-php" } } diff --git a/includes/oauth-php/OAuthTests.xml b/includes/oauth-php/OAuthTests.xml index 39122a1b39e..df24367e37a 100644 --- a/includes/oauth-php/OAuthTests.xml +++ b/includes/oauth-php/OAuthTests.xml @@ -1,4 +1,4 @@ - + tests diff --git a/includes/oauth-php/tests/OAuthConsumerTest.php b/includes/oauth-php/tests/OAuthConsumerTest.php index a7479b9dcce..b99b1d40d08 100644 --- a/includes/oauth-php/tests/OAuthConsumerTest.php +++ b/includes/oauth-php/tests/OAuthConsumerTest.php @@ -2,7 +2,7 @@ require 'common.php'; -class OAuthConsumerTest extends PHPUnit_Framework_TestCase { +class OAuthConsumerTest extends PHPUnit\Framework\TestCase { public function testConvertToString() { $consumer = new OAuthConsumer('key', 'secret'); $this->assertEquals('OAuthConsumer[key=key,secret=secret]', (string) $consumer); diff --git a/includes/oauth-php/tests/OAuthRequestTest.php b/includes/oauth-php/tests/OAuthRequestTest.php index 83e2c5b3cfa..c1beb09c315 100644 --- a/includes/oauth-php/tests/OAuthRequestTest.php +++ b/includes/oauth-php/tests/OAuthRequestTest.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/common.php'; -class OAuthRequestTest extends PHPUnit_Framework_TestCase { +class OAuthRequestTest extends PHPUnit\Framework\TestCase { public function testCanGetSingleParameter() { // Yes, a awesomely boring test.. But if this doesn't work, the other tests is unreliable $request = new OAuthRequest('', '', array('test'=>'foo')); @@ -239,7 +239,7 @@ public function testBuildHeader() { } public function testWontBuildHeaderWithArrayInput() { - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); OAuthTestUtils::build_request('POST', 'http://example.com', 'oauth_foo=bar&oauth_foo=baz'); OAuthRequest::from_request()->to_header(); } diff --git a/includes/oauth-php/tests/OAuthServerTest.php b/includes/oauth-php/tests/OAuthServerTest.php index d4d1192f8e4..00771d75f15 100644 --- a/includes/oauth-php/tests/OAuthServerTest.php +++ b/includes/oauth-php/tests/OAuthServerTest.php @@ -6,7 +6,7 @@ /** * Tests of OAuthUtil */ -class OAuthServerTest extends PHPUnit_Framework_TestCase { +class OAuthServerTest extends PHPUnit\Framework\TestCase { private $consumer; private $request_token; private $access_token; @@ -45,14 +45,14 @@ public function testAcceptRequestWithoutVersion() { $request->unset_parameter('oauth_version'); $request->sign_request( $this->hmac_sha1, $this->consumer, $this->access_token ); - $this->server->verify_request( $request ); + $this->assertInternalType( 'array', $this->server->verify_request( $request ) ); } public function testRejectRequestSignedWithRequestToken() { $request = OAuthRequest::from_consumer_and_token( $this->consumer, $this->request_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, $this->request_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request( $request ); } @@ -72,11 +72,12 @@ public function testRejectRequestWithMissingParameters() { foreach( $required_parameters AS $required ) { $request = OAuthRequest::from_consumer_and_token( $this->consumer, $this->access_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); - try { - $request->unset_parameter( $required ); - $this->server->verify_request($request); - $this->fail('Allowed a request without `' . $required . '`'); - } catch( OAuthException $e ) { /* expected */ } + + $this->expectException('OAuthException'); + + $request->unset_parameter( $required ); + $this->server->verify_request($request); + $this->fail('Allowed a request without `' . $required . '`'); } } @@ -87,7 +88,7 @@ public function testRejectPastTimestamp() { $request->set_parameter( 'oauth_timestamp', $request->get_parameter('oauth_timestamp') - 10*60*60, false); $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request($request); } @@ -98,7 +99,7 @@ public function testRejectFutureTimestamp() { $request->set_parameter( 'oauth_timestamp', $request->get_parameter('oauth_timestamp') + 10*60*60, false); $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request($request); } @@ -110,7 +111,7 @@ public function testRejectUsedNonce() { $request->set_parameter( 'oauth_nonce', 'nonce', false); $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request($request); } @@ -121,7 +122,7 @@ public function testRejectInvalidSignature() { $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); $request->set_parameter( 'oauth_signature', '__whatever__', false); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request($request); } @@ -133,7 +134,7 @@ public function testRejectInvalidConsumer() { $request = OAuthRequest::from_consumer_and_token( $unknown_consumer, $this->access_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $unknown_consumer, $this->access_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request( $request ); } @@ -145,7 +146,7 @@ public function testRejectInvalidToken() { $request = OAuthRequest::from_consumer_and_token( $this->consumer, $unknown_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, $unknown_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request( $request ); } @@ -158,7 +159,7 @@ public function testRejectUnknownSignatureMethod() { $server = new OAuthServer( new Mock_OAuthDataStore() ); $server->add_signature_method( $this->hmac_sha1 ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $server->verify_request( $request ); } @@ -169,7 +170,7 @@ public function testRejectUnknownVersion() { $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); $request->set_parameter('oauth_version', '1.0a', false); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $this->server->verify_request( $request ); } @@ -189,7 +190,7 @@ public function testRejectSignedRequestTokenRequest() { $request = OAuthRequest::from_consumer_and_token( $this->consumer, $this->request_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, $this->request_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $token = $this->server->fetch_request_token($request); } @@ -209,7 +210,7 @@ public function testRejectUnsignedAccessTokenRequest() { $request = OAuthRequest::from_consumer_and_token( $this->consumer, NULL, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, NULL ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $token = $this->server->fetch_access_token($request); } @@ -219,7 +220,7 @@ public function testRejectAccessTokenSignedAccessTokenRequest() { $request = OAuthRequest::from_consumer_and_token( $this->consumer, $this->access_token, 'POST', 'http://example.com'); $request->sign_request( $this->plaintext, $this->consumer, $this->access_token ); - $this->setExpectedException('OAuthException'); + $this->expectException('OAuthException'); $token = $this->server->fetch_access_token($request); } } diff --git a/includes/oauth-php/tests/OAuthSignatureMethodHmacSha1Test.php b/includes/oauth-php/tests/OAuthSignatureMethodHmacSha1Test.php index 3d5cc7524ab..dd8efc0d0ea 100644 --- a/includes/oauth-php/tests/OAuthSignatureMethodHmacSha1Test.php +++ b/includes/oauth-php/tests/OAuthSignatureMethodHmacSha1Test.php @@ -3,7 +3,7 @@ require_once 'common.php'; require_once 'Mock_OAuthBaseStringRequest.php'; -class OAuthSignatureMethodHmacSha1Test extends PHPUnit_Framework_TestCase { +class OAuthSignatureMethodHmacSha1Test extends PHPUnit\Framework\TestCase { private $method; public function setUp() { diff --git a/includes/oauth-php/tests/OAuthSignatureMethodPlaintextTest.php b/includes/oauth-php/tests/OAuthSignatureMethodPlaintextTest.php index d0962433133..154f6debd86 100644 --- a/includes/oauth-php/tests/OAuthSignatureMethodPlaintextTest.php +++ b/includes/oauth-php/tests/OAuthSignatureMethodPlaintextTest.php @@ -3,7 +3,7 @@ require_once 'common.php'; require_once 'Mock_OAuthBaseStringRequest.php'; -class OAuthSignatureMethodPlaintextTest extends PHPUnit_Framework_TestCase { +class OAuthSignatureMethodPlaintextTest extends PHPUnit\Framework\TestCase { private $method; public function setUp() { diff --git a/includes/oauth-php/tests/OAuthSignatureMethodRsaSha1Test.php b/includes/oauth-php/tests/OAuthSignatureMethodRsaSha1Test.php index 74e50377345..fd86f097862 100644 --- a/includes/oauth-php/tests/OAuthSignatureMethodRsaSha1Test.php +++ b/includes/oauth-php/tests/OAuthSignatureMethodRsaSha1Test.php @@ -4,7 +4,7 @@ require_once 'Mock_OAuthBaseStringRequest.php'; require_once 'Mock_OAuthSignatureMethod_RSA_SHA1.php'; -class OAuthSignatureMethodRsaSha1Test extends PHPUnit_Framework_TestCase { +class OAuthSignatureMethodRsaSha1Test extends PHPUnit\Framework\TestCase { private $method; public function setUp() { diff --git a/includes/oauth-php/tests/OAuthTokenTest.php b/includes/oauth-php/tests/OAuthTokenTest.php index 20d8113af76..5f650daf63f 100644 --- a/includes/oauth-php/tests/OAuthTokenTest.php +++ b/includes/oauth-php/tests/OAuthTokenTest.php @@ -2,7 +2,7 @@ require_once 'common.php'; -class OAuthTokenTest extends PHPUnit_Framework_TestCase { +class OAuthTokenTest extends PHPUnit\Framework\TestCase { public function testSerialize() { $token = new OAuthToken('token', 'secret'); $this->assertEquals('oauth_token=token&oauth_token_secret=secret', $token->to_string()); diff --git a/includes/oauth-php/tests/OAuthUtilTest.php b/includes/oauth-php/tests/OAuthUtilTest.php index 072c9facd23..1a85992d919 100644 --- a/includes/oauth-php/tests/OAuthUtilTest.php +++ b/includes/oauth-php/tests/OAuthUtilTest.php @@ -5,7 +5,7 @@ /** * Tests of OAuthUtil */ -class OAuthUtilTest extends PHPUnit_Framework_TestCase { +class OAuthUtilTest extends PHPUnit\Framework\TestCase { public function testUrlencode() { // Tests taken from // http://wiki.oauth.net/TestCases ("Parameter Encoding") diff --git a/includes/oauth-php/tests/common.php b/includes/oauth-php/tests/common.php index 978cc2aba4b..3bae8904abc 100644 --- a/includes/oauth-php/tests/common.php +++ b/includes/oauth-php/tests/common.php @@ -8,7 +8,18 @@ */ class OAuthTestUtils { private static function reset_request_vars() { - $_SERVER = array(); + unset( + $_SERVER['HTTPS'], + $_SERVER['REQUEST_METHOD'], + $_SERVER['HTTP_HOST'], + $_SERVER['SERVER_NAME'], + $_SERVER['SERVER_PORT'], + $_SERVER['SCRIPT_NAME'], + $_SERVER['REQUEST_URI'], + $_SERVER['QUERY_STRING'], + $_SERVER['HTTP_CONTENT_TYPE'], + $_SERVER['HTTP_AUTHORIZATION'] + ); $_POST = array(); $_GET = array(); } @@ -49,7 +60,7 @@ public static function build_request( $method, $uri, $post_data = '', $auth_head if( $method == 'POST' ) { $_SERVER['HTTP_CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; - $_POST = parse_str($post_data); + parse_str( $post_data, $_POST ); OAuthRequest::$POST_INPUT = 'data:application/x-www-form-urlencoded,'.$post_data; }