Index: modules/system/system.test =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/modules/system/system.test,v retrieving revision 1.146 diff -u -p -r1.146 system.test --- modules/system/system.test 5 Oct 2010 00:22:24 -0000 1.146 +++ modules/system/system.test 6 Oct 2010 12:10:12 -0000 @@ -2055,3 +2055,59 @@ class SystemAdminTestCase extends Drupal $this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode persists on new requests.')); } } + +/** + * Tests authorize.php and related hooks. + */ +class SystemAuthorizeCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Authorize API', + 'description' => 'Tests the authorize.php script and related API.', + 'group' => 'System', + ); + } + + function setUp() { + parent::setUp(array('system_test')); + + variable_set('allow_authorize_operations', TRUE); + + // Create an administrator user. + $this->admin_user = $this->drupalCreateUser(array('administer software updates')); + $this->drupalLogin($this->admin_user); + } + + /** + * Helper function to initialize authorize.php and load it via drupalGet(). + * + * Initializing authorize.php needs to happen in the child Drupal + * installation, not the parent. So, we visit a menu callback provided by + * system_test.module which calls system_authorized_init() to initialize the + * $_SESSION inside the test site, not the framework site. This callback + * redirects to authorize.php when it's done initializing. + * + * @see system_authorized_init(). + */ + function drupalGetAuthorizePHP($page_title = 'system-test-auth') { + $this->drupalGet('system-test/authorize-init/' . $page_title); + } + + /** + * Tests the FileTransfer hooks + */ + function testFileTransferHooks() { + $page_title = $this->randomName(16); + $this->drupalGetAuthorizePHP($page_title); + $this->assertTitle(strtr('@title | Drupal', array('@title' => $page_title)), 'authorize.php page title is correct.'); + $this->assertNoText('It appears you have reached this page in error.'); + $this->assertText('To continue, provide your server connection details'); + // Make sure we see the new connection method added by system_test. + $this->assertRaw('System Test FileTransfer'); + // Make sure the settings form callback works. + $this->assertText('System Test Username'); + // Make sure hook_filetransfer_info_alter() works and we removed the + // hidden choice. + $this->assertNoText('System Test Hidden FileTransfer'); + } +} cvs diff: Diffing modules/simpletest/tests Index: modules/simpletest/tests/system_test.module =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/modules/simpletest/tests/system_test.module,v retrieving revision 1.32 diff -u -p -r1.32 system_test.module --- modules/simpletest/tests/system_test.module 1 Aug 2010 23:35:01 -0000 1.32 +++ modules/simpletest/tests/system_test.module 6 Oct 2010 12:10:26 -0000 @@ -16,6 +16,12 @@ function system_test_menu() { 'access callback' => TRUE, 'type' => MENU_CALLBACK, ); + $items['system-test/authorize-init/%'] = array( + 'page callback' => 'system_test_authorize_init_page', + 'page arguments' => array(2), + 'access arguments' => array('administer software updates'), + 'type' => MENU_CALLBACK, + ); $items['system-test/redirect/%'] = array( 'title' => 'Redirect', 'page callback' => 'system_test_redirect', @@ -311,3 +317,56 @@ function _system_test_second_shutdown_fu throw new Exception('Drupal is awesome.'); } +/** + * Implements hook_filestransfer_info(). + */ +function system_test_filetransfer_info() { + return array( + 'system_test' => array( + 'title' => t('System Test FileTransfer'), + 'file' => 'system_test.module', // Should be a .inc, but for test, ok. + 'factory' => 'system_test_filetransfer_factory', + 'settings form' => 'system_test_filetransfer_settings_form', + 'weight' => -10, + ), + 'system_test_hidden' => array( + 'title' => t('System Test Hidden FileTransfer'), + 'file' => 'system_test.module', // Should be a .inc, but for test, ok. + 'factory' => 'system_test_filetransfer_factory', + 'factory arguments' => array('hidden'), + 'settings form' => 'system_test_filetransfer_settings_form', + 'settings form arguments' => array('hidden'), + 'weight' => -12, + ), + ); +} + +/** + * Settings form callback for system_test_filetransfer. + */ +function system_test_filetransfer_settings_form() { + $form = array(); + $form['system_test_username'] = array( + '#type' => 'textfield', + '#title' => t('System Test Username'), + ); + return $form; +} + +/** + * Implements hook_filetransfer_info_alter(). + */ +function system_test_filetransfer_info_alter(&$filetransfer_info) { + unset($filetransfer_info['system_test_hidden']); +} + +/** + * Page callback to initialize authorize.php during testing. + * + * @see system_authorized_init(). + */ +function system_test_authorize_init_page($page_title) { + $authorize_url = $GLOBALS['base_url'] . '/authorize.php'; + system_authorized_init('system_test_authorize_run', drupal_get_path('module', 'system_test') . '/system_test.module', array(), $page_title); + drupal_goto($authorize_url); +} cvs diff: Diffing modules/simpletest/tests/upgrade