diff --git a/src/Tests/XmlRpcBasicTest.php b/src/Tests/XmlRpcBasicTest.php index fa184b9..55244d9 100644 --- a/src/Tests/XmlRpcBasicTest.php +++ b/src/Tests/XmlRpcBasicTest.php @@ -17,6 +17,8 @@ use GuzzleHttp\Exception\ClientException; */ class XmlRpcBasicTest extends WebTestBase { + use XmlRpcTestTrait; + /** * Modules to enable. * @@ -38,8 +40,7 @@ class XmlRpcBasicTest extends WebTestBase { ); // Invoke XML-RPC call to get list of methods. - $url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); - $methods = xmlrpc($url, ['system.listMethods' => []]); + $methods = $this->xmlRpcGet(['system.listMethods' => []]); // Ensure that the minimum methods were found. $count = 0; @@ -56,8 +57,7 @@ class XmlRpcBasicTest extends WebTestBase { * Ensure that system.methodSignature returns an array of signatures. */ public function testMethodSignature() { - $url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); - $signature = xmlrpc($url, ['system.methodSignature' => ['system.listMethods']]); + $signature = $this->xmlRpcGet(['system.methodSignature' => ['system.listMethods']]); $this->assert(is_array($signature) && !empty($signature) && is_array($signature[0]), 'system.methodSignature returns an array of signature arrays.'); } @@ -94,8 +94,6 @@ class XmlRpcBasicTest extends WebTestBase { * Ensure that XML-RPC correctly handles XML Accept headers. */ public function testAcceptHeaders() { - $url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); - $request_header_sets = array( // Default. 'implicit' => array(), @@ -109,7 +107,7 @@ class XmlRpcBasicTest extends WebTestBase { foreach ($request_header_sets as $accept => $headers) { try { - $methods = xmlrpc($url, ['system.listMethods' => []], $headers); + $methods = $this->xmlRpcGet(['system.listMethods' => []], $headers); $this->assertTrue(is_array($methods), strtr('@accept accept header is accepted', array('@accept' => $accept))); } catch (ClientException $e) { diff --git a/src/Tests/XmlRpcMessagesTest.php b/src/Tests/XmlRpcMessagesTest.php index 8108b3d..644cae4 100644 --- a/src/Tests/XmlRpcMessagesTest.php +++ b/src/Tests/XmlRpcMessagesTest.php @@ -16,6 +16,8 @@ use Drupal\simpletest\WebTestBase; */ class XmlRpcMessagesTest extends WebTestBase { + use XmlRpcTestTrait; + /** * Modules to enable. * @@ -27,11 +29,10 @@ class XmlRpcMessagesTest extends WebTestBase { * Make sure that XML-RPC can transfer large messages. */ public function testSizedMessages() { - $xml_url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); $sizes = [8, 80, 160]; foreach ($sizes as $size) { $xml_message_l = xmlrpc_test_message_sized_in_kb($size); - $xml_message_r = xmlrpc($xml_url, ['messages.messageSizedInKB' => [$size]]); + $xml_message_r = $this->xmlRpcGet(['messages.messageSizedInKB' => [$size]]); $this->assertEqual($xml_message_l, $xml_message_r, format_string('XML-RPC messages.messageSizedInKB of %s Kb size received', ['%s' => $size])); } @@ -43,12 +44,11 @@ class XmlRpcMessagesTest extends WebTestBase { public function testAlterListMethods() { // Ensure xmlrpc_test.alter() is disabled and retrieve regular list of methods. \Drupal::state()->set('xmlrpc_test.alter', FALSE); - $url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); - $methods1 = xmlrpc($url, ['system.listMethods' => []]); + $methods1 = $this->xmlRpcGet(['system.listMethods' => []]); // Enable the alter hook and retrieve the list of methods again. \Drupal::state()->set('xmlrpc_test.alter', TRUE); - $methods2 = xmlrpc($url, ['system.listMethods' => []]); + $methods2 = $this->xmlRpcGet(['system.listMethods' => []]); $diff = array_diff($methods1, $methods2); $this->assertTrue(is_array($diff) && !empty($diff), 'Method list is altered by hook_xmlrpc_alter'); diff --git a/src/Tests/XmlRpcTestTrait.php b/src/Tests/XmlRpcTestTrait.php new file mode 100644 index 0000000..6dfda55 --- /dev/null +++ b/src/Tests/XmlRpcTestTrait.php @@ -0,0 +1,36 @@ + TRUE]); + + return xmlrpc($url, $args, $headers); + } + +} diff --git a/src/Tests/XmlRpcValidatorTest.php b/src/Tests/XmlRpcValidatorTest.php index 64ca540..d219d83 100644 --- a/src/Tests/XmlRpcValidatorTest.php +++ b/src/Tests/XmlRpcValidatorTest.php @@ -17,6 +17,8 @@ use Drupal\simpletest\WebTestBase; */ class XmlRpcValidatorTest extends WebTestBase { + use XmlRpcTestTrait; + /** * Modules to enable. * @@ -28,7 +30,6 @@ class XmlRpcValidatorTest extends WebTestBase { * Run validator1 tests. */ public function testValidator() { - $xml_url = \Drupal::url('xmlrpc.php', [], ['absolute' => TRUE]); srand(); mt_srand(); @@ -41,17 +42,17 @@ class XmlRpcValidatorTest extends WebTestBase { array('larry' => mt_rand(-100, 100))); shuffle($array_1); $l_res_1 = xmlrpc_test_arrayOfStructsTest($array_1); - $r_res_1 = xmlrpc($xml_url, array('validator1.arrayOfStructsTest' => array($array_1))); + $r_res_1 = $this->xmlRpcGet(array('validator1.arrayOfStructsTest' => array($array_1))); $this->assertIdentical($l_res_1, $r_res_1); $string_2 = 't\'&>>zf"md>yr>xlcev">>uai"np&s>>q\'&b<>"&&&'; $l_res_2 = xmlrpc_test_countTheEntities($string_2); - $r_res_2 = xmlrpc($xml_url, array('validator1.countTheEntities' => array($string_2))); + $r_res_2 = $this->xmlRpcGet(array('validator1.countTheEntities' => array($string_2))); $this->assertIdentical($l_res_2, $r_res_2); $struct_3 = array('moe' => mt_rand(-100, 100), 'larry' => mt_rand(-100, 100), 'curly' => mt_rand(-100, 100), 'homer' => mt_rand(-100, 100)); $l_res_3 = xmlrpc_test_easyStructTest($struct_3); - $r_res_3 = xmlrpc($xml_url, array('validator1.easyStructTest' => array($struct_3))); + $r_res_3 = $this->xmlRpcGet(array('validator1.easyStructTest' => array($struct_3))); $this->assertIdentical($l_res_3, $r_res_3); $struct_4 = array('sub1' => array('bar' => 13), @@ -59,7 +60,7 @@ class XmlRpcValidatorTest extends WebTestBase { 'sub3' => array('foo' => 1, 'baz' => 2), 'sub4' => array('ss' => array('sss' => array('ssss' => 'sssss')))); $l_res_4 = xmlrpc_test_echoStructTest($struct_4); - $r_res_4 = xmlrpc($xml_url, array('validator1.echoStructTest' => array($struct_4))); + $r_res_4 = $this->xmlRpcGet(array('validator1.echoStructTest' => array($struct_4))); $this->assertIdentical($l_res_4, $r_res_4); $int_5 = mt_rand(-100, 100); @@ -71,7 +72,7 @@ class XmlRpcValidatorTest extends WebTestBase { $l_res_5 = xmlrpc_test_manyTypesTest($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), $base64_5); // See http://drupal.org/node/37766 why this currently fails $l_res_5[5] = $l_res_5[5]->data; - $r_res_5 = xmlrpc($xml_url, array('validator1.manyTypesTest' => array($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5)))); + $r_res_5 = $this->xmlRpcGet(array('validator1.manyTypesTest' => array($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5)))); // @todo Contains objects, objects are not equal. $this->assertEqual($l_res_5, $r_res_5); @@ -82,7 +83,7 @@ class XmlRpcValidatorTest extends WebTestBase { } $l_res_6 = xmlrpc_test_moderateSizeArrayCheck($array_6); - $r_res_6 = xmlrpc($xml_url, array('validator1.moderateSizeArrayCheck' => array($array_6))); + $r_res_6 = $this->xmlRpcGet(array('validator1.moderateSizeArrayCheck' => array($array_6))); $this->assertIdentical($l_res_6, $r_res_6); $struct_7 = array(); @@ -99,13 +100,13 @@ class XmlRpcValidatorTest extends WebTestBase { } } $l_res_7 = xmlrpc_test_nestedStructTest($struct_7); - $r_res_7 = xmlrpc($xml_url, array('validator1.nestedStructTest' => array($struct_7))); + $r_res_7 = $this->xmlRpcGet(array('validator1.nestedStructTest' => array($struct_7))); $this->assertIdentical($l_res_7, $r_res_7); $int_8 = mt_rand(-100, 100); $l_res_8 = xmlrpc_test_simpleStructReturnTest($int_8); - $r_res_8 = xmlrpc($xml_url, array('validator1.simpleStructReturnTest' => array($int_8))); + $r_res_8 = $this->xmlRpcGet(array('validator1.simpleStructReturnTest' => array($int_8))); $this->assertIdentical($l_res_8, $r_res_8); /* Now test multicall */ @@ -120,7 +121,7 @@ class XmlRpcValidatorTest extends WebTestBase { $x['validator1.simpleStructReturnTest'] = array($int_8); $a_l_res = array($l_res_1, $l_res_2, $l_res_3, $l_res_4, $l_res_5, $l_res_6, $l_res_7, $l_res_8); - $a_r_res = xmlrpc($xml_url, $x); + $a_r_res = $this->xmlRpcGet($x); $this->assertEqual($a_l_res, $a_r_res); } }