protected function XmlRpcMessagesTest::testAlterListMethods

Ensure that hook_xmlrpc_alter() can hide even builtin methods.

File

drupal/core/modules/xmlrpc/lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php, line 49
Definition of Drupal\xmlrpc\Tests\XmlRpcMessagesTest.

Class

XmlRpcMessagesTest
XML-RPC message and alteration tests.

Namespace

Drupal\xmlrpc\Tests

Code

protected function testAlterListMethods() {

  // Ensure xmlrpc_test.alter() is disabled and retrieve regular list of methods.
  \Drupal::state()
    ->set('xmlrpc_test.alter', FALSE);
  $url = url('xmlrpc.php', array(
    'absolute' => TRUE,
  ));
  $methods1 = xmlrpc($url, array(
    'system.listMethods' => array(),
  ));

  // Enable the alter hook and retrieve the list of methods again.
  \Drupal::state()
    ->set('xmlrpc_test.alter', TRUE);
  $methods2 = xmlrpc($url, array(
    'system.listMethods' => array(),
  ));
  $diff = array_diff($methods1, $methods2);
  $this
    ->assertTrue(is_array($diff) && !empty($diff), 'Method list is altered by hook_xmlrpc_alter');
  $removed = reset($diff);
  $this
    ->assertEqual($removed, 'system.methodSignature', 'Hiding builting system.methodSignature with hook_xmlrpc_alter works');
}