diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-08-14 09:18:28 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-08-14 09:18:28 +0000 |
commit | 207284675ef4314c9d6d442696624289865d8b26 (patch) | |
tree | a977c03525b0b1d50df03153429af06e76aed6e9 /includes/tests | |
parent | ab4e39da832da4929df3c0a327dffb657f24b544 (diff) | |
download | brdo-207284675ef4314c9d6d442696624289865d8b26.tar.gz brdo-207284675ef4314c9d6d442696624289865d8b26.tar.bz2 |
- Patch #268063: move tests from includes/tests to modules/simpletests/tests.
Diffstat (limited to 'includes/tests')
-rw-r--r-- | includes/tests/actions.test | 66 | ||||
-rw-r--r-- | includes/tests/bootstrap.test | 110 | ||||
-rw-r--r-- | includes/tests/cache.test | 236 | ||||
-rw-r--r-- | includes/tests/database.test | 182 | ||||
-rw-r--r-- | includes/tests/form.test | 74 | ||||
-rw-r--r-- | includes/tests/registry.test | 153 | ||||
-rw-r--r-- | includes/tests/xmlrpc.test | 126 |
7 files changed, 0 insertions, 947 deletions
diff --git a/includes/tests/actions.test b/includes/tests/actions.test deleted file mode 100644 index 68b7a1b98..000000000 --- a/includes/tests/actions.test +++ /dev/null @@ -1,66 +0,0 @@ -<?php -// $Id$ - -class ActionsConfigurationTestCase extends DrupalWebTestCase { - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Actions configuration'), - 'description' => t('Tests complex actions configuration by adding, editing, and deleting a complex action.'), - 'group' => t('System'), - ); - } - - /** - * Test the configuration of advanced actions through the administration - * interface. - */ - function testActionConfiguration() { - // Create a user with permission to view the actions administration pages. - $user = $this->drupalCreateUser(array('administer actions')); - $this->drupalLogin($user); - - // Make a POST request to admin/settings/actions/manage. - $edit = array(); - $edit['action'] = md5('system_goto_action'); - $this->drupalPost('admin/settings/actions/manage', $edit, t('Create')); - - // Make a POST request to the individual action configuration page. - $edit = array(); - $action_description = $this->randomName(); - $edit['actions_description'] = $action_description; - $edit['url'] = 'admin'; - $this->drupalPost('admin/settings/actions/configure/' . md5('system_goto_action'), $edit, t('Save')); - - // Make sure that the new complex action was saved properly. - $this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action.")); - $this->assertText($action_description, t("Make sure the action description appears on the configuration page after we've saved the complex action.")); - - // Make another POST request to the action edit page. - $this->clickLink(t('configure')); - $edit = array(); - $new_action_description = $this->randomName(); - $edit['actions_description'] = $new_action_description; - $edit['url'] = 'admin'; - $this->drupalPost('admin/settings/actions/configure/1', $edit, t('Save')); - - // Make sure that the action updated properly. - $this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully updated the complex action.")); - $this->assertNoText($action_description, t("Make sure the old action description does NOT appear on the configuration page after we've updated the complex action.")); - $this->assertText($new_action_description, t("Make sure the action description appears on the configuration page after we've updated the complex action.")); - - // Make sure that deletions work properly. - $this->clickLink(t('delete')); - $edit = array(); - $this->drupalPost('admin/settings/actions/delete/1', $edit, t('Delete')); - - // Make sure that the action was actually deleted. - $this->assertRaw(t('Action %action was deleted', array('%action' => $new_action_description)), t('Make sure that we get a delete confirmation message.')); - $this->drupalGet('admin/settings/actions/manage'); - $this->assertNoText($new_action_description, t("Make sure the action description does not appear on the overview page after we've deleted the action.")); - $exists = db_result(db_query("SELECT aid FROM {actions} WHERE callback = 'drupal_goto_action'")); - $this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.')); - } -} diff --git a/includes/tests/bootstrap.test b/includes/tests/bootstrap.test deleted file mode 100644 index de833f117..000000000 --- a/includes/tests/bootstrap.test +++ /dev/null @@ -1,110 +0,0 @@ -<?php -// $Id$ - -class BootstrapIPAddressTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('IP address test'), - 'description' => t('Get the IP address from the current visitor from the server variables.'), - 'group' => t('Bootstrap') - ); - } - - /** - * Implementation of setUp(). - */ - function setUp() { - $this->oldserver = $_SERVER; - - $this->remote_ip = '127.0.0.1'; - $this->proxy_ip = '127.0.0.2'; - $this->forwarded_ip = '127.0.0.3'; - $this->cluster_ip = '127.0.0.4'; - $this->untrusted_ip = '0.0.0.0'; - - $_SERVER['REMOTE_ADDR'] = $this->remote_ip; - unset($_SERVER['HTTP_X_FORWARDED_FOR']); - unset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']); - - parent::setUp(); - } - - /** - * Implementation of tearDown(). - */ - function tearDown() { - $_SERVER = $this->oldserver; - parent::tearDown(); - } - - /** - * testIPAddress - */ - function testIPAddress() { - // Test the normal IP address. - $this->assertTrue( - ip_address(true) == $this->remote_ip, - t('Got remote IP address') - ); - - // Proxy forwarding on but no proxy addresses defined. - variable_set('reverse_proxy', 1); - $this->assertTrue( - ip_address(true) == $this->remote_ip, - t('Proxy forwarding without trusted proxies got remote IP address') - ); - - // Proxy forwarding on and proxy address not trusted. - variable_set('reverse_proxy_addresses', array($this->proxy_ip)); - $_SERVER['REMOTE_ADDR'] = $this->untrusted_ip; - $this->assertTrue( - ip_address(true) == $this->untrusted_ip, - t('Proxy forwarding with untrusted proxy got remote IP address') - ); - - // Proxy forwarding on and proxy address trusted. - $_SERVER['REMOTE_ADDR'] = $this->proxy_ip; - $_SERVER['HTTP_X_FORWARDED_FOR'] = $this->forwarded_ip; - $this->assertTrue( - ip_address(true) == $this->forwarded_ip, - t('Proxy forwarding with trusted proxy got forwarded IP address') - ); - - // Cluster environment. - $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip; - $this->assertTrue( - ip_address(true) == $this->cluster_ip, - t('Cluster environment got cluster client IP') - ); - } -} - -class BootstrapPageCacheTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Page cache test'), - 'description' => t('Enable the page cache, submit a HEAD request and examine headers.'), - 'group' => t('Bootstrap') - ); - } - - /** - * Enable cache and examine HTTP headers. - */ - function testPageCache() { - global $base_url; - variable_set('cache', 1); - // Retrieve the front page, which has already been cached by $this->curlConnect(); - $this->drupalHead($base_url); - $this->assertText('ETag: ', t('Verify presence of ETag header indicating that page caching is enabled.')); - } - -} diff --git a/includes/tests/cache.test b/includes/tests/cache.test deleted file mode 100644 index e082da3fd..000000000 --- a/includes/tests/cache.test +++ /dev/null @@ -1,236 +0,0 @@ -<?php -// $Id$ - -class CacheTestCase extends DrupalWebTestCase { - protected $default_table = 'cache'; - protected $default_cid = 'test_temporary'; - protected $default_value = 'CacheTest'; - - /** - * Check whether or not a cache entry exists. - * - * @param $cid - * The cache id. - * @param $var - * The variable the cache should contain. - * @param $table - * The table the cache item was stored in. - * @return - * TRUE on pass, FALSE on fail. - */ - protected function checkCacheExists($cid, $var, $table = null) { - if ($table == null) { - $table = $this->default_table; - } - - $cache = cache_get($cid, $table); - - return isset($cache->data) && $cache->data == $var; - } - - /** - * Assert or a cache entry exists. - * - * @param $message - * Message to display. - * @param $var - * The variable the cache should contain. - * @param $cid - * The cache id. - * @param $table - * The table the cache item was stored in. - */ - protected function assertCacheExists($message, $var = NULL, $cid = NULL, $table = NULL) { - if ($table == NULL) { - $table = $this->default_table; - } - if ($cid == NULL) { - $cid = $this->default_cid; - } - if ($var == NULL) { - $var = $this->default_value; - } - - $this->assertTrue($this->checkCacheExists($cid, $var, $table), $message); - } - - /** - * Assert or a cache entry has been removed. - * - * @param $message - * Message to display. - * @param $cid - * The cache id. - * @param $table - * The table the cache item was stored in. - */ - function assertCacheRemoved($message, $cid = NULL, $table = NULL) { - if ($table == NULL) { - $table = $this->default_table; - } - if ($cid == NULL) { - $cid = $this->default_cid; - } - - $cache = cache_get($cid, $table); - $this->assertFalse($cache, $message); - } - - /** - * Perform the general wipe. - * @param $table - * The table to perform the wipe on. - */ - protected function generalWipe($table = NULL) { - if ($table == NULL) { - $table = $this->default_table; - } - - cache_clear_all(NULL, $table); - } - - /** - * Setup the lifetime settings for caching. - * - * @param $time - * The time in seconds the cache should minimal live. - */ - protected function setupLifetime($time) { - variable_set('cache_lifetime', $time); - variable_set('cache_flush', 0); - } -} - -class CacheSavingCase extends CacheTestCase { - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Cache saving test'), - 'description' => t('Check our variables are saved and restored the right way.'), - 'group' => t('Cache') - ); - } - - /** - * Test the saving and restoring of a string. - */ - function testString() { - $this->checkVariable($this->randomName('100')); - } - - /** - * Test the saving and restoring of an integer. - */ - function testInteger() { - $this->checkVariable(100); - } - - /** - * Test the saving and restoring of a double. - */ - function testDouble() { - $this->checkVariable(1.29); - } - - /** - * Test the saving and restoring of an array. - */ - function testArray() { - $this->checkVariable(array('drupal1', 'drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6'))); - } - - /** - * Test the saving and restoring of an object. - */ - function testObject() { - $test_object = new StdClass(); - $test_object->test1 = $this->randomName('100'); - $test_object->test2 = 100; - $test_object->test3 = array('drupal1', 'drupal2' => 'drupal3', 'drupal4' => array('drupal5', 'drupal6')); - - cache_set('test_object', $test_object, 'cache'); - $cache = cache_get('test_object', 'cache'); - $this->assertTrue(isset($cache->data) && $cache->data == $test_object, t('Object is saved and restored properly.')); - } - - /* - * Check or a variable is stored and restored properly. - **/ - function checkVariable($var) { - cache_set('test_var', $var, 'cache'); - $cache = cache_get('test_var', 'cache'); - $this->assertTrue(isset($cache->data) && $cache->data === $var, t('@type is saved and restored properly.', array('@type' => ucfirst(gettype($var))))); - } -} - -class CacheClearCase extends CacheTestCase { - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Cache clear test'), - 'description' => t('Check our clearing is done the proper way.'), - 'group' => t('Cache') - ); - } - - /** - * Implementation of setUp(). - */ - function setUp() { - $this->default_table = 'cache_page'; - $this->default_value = $this->randomName(10); - - parent::setUp(); - } - - /** - * Test clearing using a cid. - */ - function testClearCid() { - cache_set('test_cid_clear', $this->default_value, $this->default_table); - - $this->assertCacheExists(t('Cache was set for clearing cid.'), $this->default_value, 'test_cid_clear'); - cache_clear_all('test_cid_clear', $this->default_table); - - $this->assertCacheRemoved(t('Cache was removed after clearing cid.'), 'test_cid_clear'); - - cache_set('test_cid_clear1', $this->default_value, $this->default_table); - cache_set('test_cid_clear2', $this->default_value, $this->default_table); - $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches were created for checking cid "*" with wildcard false.')); - cache_clear_all('*', $this->default_table); - $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches still exists after clearing cid "*" with wildcard false.')); - } - - /** - * Test clearing using wildcard. - */ - function testClearWildcard() { - cache_set('test_cid_clear1', $this->default_value, $this->default_table); - cache_set('test_cid_clear2', $this->default_value, $this->default_table); - $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches were created for checking cid "*" with wildcard true.')); - cache_clear_all('*', $this->default_table, TRUE); - $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) - || $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches removed after clearing cid "*" with wildcard true.')); - - cache_set('test_cid_clear1', $this->default_value, $this->default_table); - cache_set('test_cid_clear2', $this->default_value, $this->default_table); - $this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value) - && $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches were created for checking cid substring with wildcard true.')); - cache_clear_all('test_', $this->default_table, TRUE); - $this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value) - || $this->checkCacheExists('test_cid_clear2', $this->default_value), - t('Two caches removed after clearing cid substring with wildcard true.')); - } -}
\ No newline at end of file diff --git a/includes/tests/database.test b/includes/tests/database.test deleted file mode 100644 index 83bb3a123..000000000 --- a/includes/tests/database.test +++ /dev/null @@ -1,182 +0,0 @@ -<?php -// $Id$ - -class DatabaseSecurityTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Database placeholders'), - 'description' => t('Make sure that invalid values do not get passed through the %n, %d, or %f placeholders.'), - 'group' => t('System') - ); - } - - function testPlaceholders() { - // First test the numeric type - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.46, - '+0.1e3' => 0.1e3, - ); - $not_valid = array( - '1x' => 0, - '4.4 OR 1=1' => 0, - '9 9' => 0, - '0xff' => 0, - 'XXX' => 0, - '0Xaa' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 0, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'numeric', - 'precision' => 5, - 'scale' => 2, - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_numeric', $schema); - $insert_query = 'INSERT INTO {test_numeric} (n) VALUES (' . db_type_placeholder('numeric') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual($select, $test, "[numeric] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_numeric}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_numeric}')); - $this->assertEqual(1, $count, "[numeric] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_numeric}')); - $this->assertEqual(0, $test, "[numeric] Got $select ($test) after inserting invalid value $insert"); - } - - // Test ints - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543, - '123.456' => 123, - '22' => 22, - ); - $not_valid = array( - '+0.1e3' => 0, - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'int', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_int', $schema); - $insert_query = 'INSERT INTO {test_int} (n) VALUES (' . db_type_placeholder('int') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_int}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_int}')); - $this->assertEqual(1, $count, "[int] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_int}')); - $this->assertEqual($select, $test, "[int] Got $select ($test) after inserting invalid value $insert"); - } - - // Test floats - $valid = array( - '0' => 0, - '1' => 1, - '543.21' => 543.21, - '123.456' => 123.456, - '22' => 22, - '+0.1e3' => 100, - ); - $not_valid = array( - '0xff' => 0, - '0Xaa' => 0, - '1x' => 1, - '4.4 OR 1=1' => 4.4, - '9 9' => 9, - 'XXX' => 0, - 'e' => 0, - '--1' => 0, - 'DROP TABLE' => 0, - '44-66' => 44, - '' => 0, - '.' => 0, - '%88' => 0, - ); - - $schema = array( - 'fields' => array( - 'n' => array( - 'type' => 'float', - 'not null' => TRUE, - ), - ) - ); - - $ret = array(); - db_create_table($ret, 'test_float', $schema); - $insert_query = 'INSERT INTO {test_float} (n) VALUES (' . db_type_placeholder('float') . ')'; - foreach ($valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting valid value $insert"); - } - foreach ($not_valid as $insert => $select) { - db_query('DELETE FROM {test_float}'); - db_query($insert_query, $insert); - $count = db_result(db_query('SELECT COUNT(*) FROM {test_float}')); - $this->assertEqual(1, $count, "[float] One row ($count) after inserting $insert"); - $test = db_result(db_query('SELECT n FROM {test_float}')); - $this->assertEqual($select, $test, "[float] Got $select ($test) after inserting invalid value $insert"); - } - - } -} diff --git a/includes/tests/form.test b/includes/tests/form.test deleted file mode 100644 index 70cb131cb..000000000 --- a/includes/tests/form.test +++ /dev/null @@ -1,74 +0,0 @@ -<?php -// $Id$ - -/** - * @file - * Unit tests for the Drupal Form API. - */ - -class FormsTestCase extends DrupalWebTestCase { - - function getInfo() { - return array( - 'name' => t('Required field validation'), - 'description' => t('Carriage returns, tabs, and spaces are not valid content for a required field.'), - 'group' => t('Form API'), - ); - } - - /** - * Check several empty values for required forms elements. - * - * If the form field is found in form_get_errors() then the test pass. - */ - function testRequiredFields() { - // Originates from http://drupal.org/node/117748 - // Sets of empty strings and arrays - $empty_strings = array('""' => "", '"\n"' => "\n", '" "' => " ", '"\t"' => "\t", '" \n\t "' => " \n\t ", '"\n\n\n\n\n"' => "\n\n\n\n\n"); - $empty_arrays = array('array()' => array()); - - $elements['textfield']['element'] = array('#title' => $this->randomName(), '#type' => 'textfield', '#required' => TRUE); - $elements['textfield']['empty_values'] = $empty_strings; - - $elements['password']['element'] = array('#title' => $this->randomName(), '#type' => 'password', '#required' => TRUE); - $elements['password']['empty_values'] = $empty_strings; - - $elements['password_confirm']['element'] = array('#title' => $this->randomName(), '#type' => 'password_confirm', '#required' => TRUE); - $elements['password_confirm']['empty_values'] = $empty_strings; - - $elements['textarea']['element'] = array('#title' => $this->randomName(), '#type' => 'textarea', '#required' => TRUE); - $elements['textarea']['empty_values'] = $empty_strings; - - $elements['radios']['element'] = array('#title' => $this->randomName(), '#type' => 'radios', '#required' => TRUE, '#options' => array($this->randomName(), $this->randomName(), $this->randomName())); - $elements['radios']['empty_values'] = $empty_arrays; - - $elements['checkboxes']['element'] = array('#title' => $this->randomName(), '#type' => 'checkboxes', '#required' => TRUE,'#options' => array($this->randomName(), $this->randomName(), $this->randomName())); - $elements['checkboxes']['empty_values'] = $empty_arrays; - - $elements['select']['element'] = array('#title' => $this->randomName(), '#type' => 'select', '#required' => TRUE, '#options' => array($this->randomName(), $this->randomName(), $this->randomName())); - $elements['select']['empty_values'] = $empty_strings; - - $elements['file']['element'] = array('#title' => $this->randomName(), '#type' => 'file', '#required' => TRUE); - $elements['file']['empty_values'] = $empty_strings; - - // Go through all the elements and all the empty values for them - foreach ($elements as $type => $data) { - foreach ($data['empty_values'] as $key => $empty) { - $form_id = $this->randomName(); - $form = $form_state = array(); - $form['op'] = array('#type' => 'submit', '#value' => t('Submit')); - $element = $data['element']['#title']; - $form[$element] = $data['element']; - $form_state['values'][$element] = $empty; - $form['#post'] = $form_state['values']; - $form['#post']['form_id'] = $form_id; - drupal_prepare_form($form_id, $form, $form_state); - drupal_process_form($form_id, $form, $form_state); - $errors = form_get_errors(); - $this->assertTrue(isset($errors[$element]), "Check empty($key) '$type' field '$element'"); - } - } - // Clear the expected form error messages so they don't appear as exceptions. - drupal_get_messages(); - } -} diff --git a/includes/tests/registry.test b/includes/tests/registry.test deleted file mode 100644 index 13bfa9074..000000000 --- a/includes/tests/registry.test +++ /dev/null @@ -1,153 +0,0 @@ -<?php -// $Id$ - -class RegistryParseFileTestCase extends DrupalWebTestCase { - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Registry parse file test'), - 'description' => t('Parse a simple file and check that its resources are saved to the database.'), - 'group' => t('System') - ); - } - - /** - * Implementation of setUp(). - */ - function setUp() { - $this->fileName = 'registry_test_' . md5(rand()); - $this->functionName = 'registry_test_function' . md5(rand()); - $this->className = 'registry_test_class' . md5(rand()); - $this->interfaceName = 'registry_test_interface' . md5(rand()); - parent::setUp(); - } - - /** - * testRegistryParseFile - */ - function testRegistryParseFile() { - _registry_parse_file($this->fileName, $this->getFileContents()); - foreach (array('functionName', 'className', 'interfaceName') as $resource) { - $foundName = db_result(db_query("SELECT name FROM {registry} WHERE name = '%s'", $this->$resource)); - $this->assertTrue($this->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$resource))); - } - } - - /** - * getFileContents - */ - function getFileContents() { - $file_contents = <<<CONTENTS -<?php - -function {$this->functionName}() {} - -class {$this->className} {} - -interface {$this->interfaceName} {} - -CONTENTS; - return $file_contents; - } - -} - -class RegistryParseFilesTestCase extends DrupalWebTestCase { - - protected $fileTypes = array('new', 'existing_changed'); - - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('Registry parse files test'), - 'description' => t('Read two a simple files from disc, and check that their resources are saved to the database.'), - 'group' => t('System') - ); - } - - /** - * Implementation of setUp(). - */ - function setUp() { - parent::setUp(); - // Create files with some php to parse - one 'new', one 'existing' so - // we test all the important code paths in _registry_parse_files. - foreach ($this->fileTypes as $fileType) { - $this->$fileType = new StdClass(); - $this->$fileType->fileName = file_directory_path() . '/registry_test_' . md5(rand()); - $this->$fileType->functionName = 'registry_test_function' . md5(rand()); - $this->$fileType->className = 'registry_test_class' . md5(rand()); - $this->$fileType->interfaceName = 'registry_test_interface' . md5(rand()); - $this->$fileType->contents = $this->getFileContents($fileType); - file_save_data($this->$fileType->contents, $this->$fileType->fileName); - - if ($fileType == 'existing_changed') { - // Insert a record with a dodgy md5. - $this->$fileType->fakeMD5 = md5($this->$fileType->contents . rand()); - db_query("INSERT INTO {registry_file} (md5, filename) VALUES ('%s', '%s')", $this->$fileType->fakeMD5, './' . $this->$fileType->fileName); - - // Insert some fake resource records. - foreach (array('function', 'class', 'interface') as $type) { - db_query("INSERT INTO {registry} (name, type, filename) VALUES ('%s', '%s', '%s')", $type . md5(rand()), $type, './' . $this->$fileType->fileName); - } - } - } - } - - /** - * testRegistryParseFiles - */ - function testRegistryParseFiles() { - _registry_parse_files($this->getFiles()); - foreach ($this->fileTypes as $fileType) { - // Test that we have all the right resources. - foreach (array('functionName', 'className', 'interfaceName') as $resource) { - $foundName = db_result(db_query("SELECT name FROM {registry} WHERE name = '%s'", $this->$fileType->$resource)); - $this->assertTrue($this->$fileType->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$fileType->$resource))); - } - // Test that we have the right md5. - $md5 = db_result(db_query("SELECT md5 FROM {registry_file} WHERE filename = '%s'", './' . $this->$fileType->fileName)); - $this->assertTrue(md5($this->$fileType->contents) == $md5, t('MD5 for "@filename" matched.' . $fileType . $md5, array('@filename' => $this->$fileType->fileName))); - } - } - - /** - * getFiles - */ - function getFiles() { - $files = array(); - foreach ($this->fileTypes as $fileType) { - if ($fileType == 'existing_changed') { - $files['./' . $this->$fileType->fileName] = array('md5' => $this->$fileType->fakeMD5); - } - else { - $files['./' . $this->$fileType->fileName] = array(); - } - } - return $files; - } - - /** - * getFileContents - */ - function getFileContents($fileType) { - $file_contents = <<<CONTENTS -<?php - -function {$this->$fileType->functionName}() {} - -class {$this->$fileType->className} {} - -interface {$this->$fileType->interfaceName} {} - -CONTENTS; - return $file_contents; - } - -} - diff --git a/includes/tests/xmlrpc.test b/includes/tests/xmlrpc.test deleted file mode 100644 index 72a230e43..000000000 --- a/includes/tests/xmlrpc.test +++ /dev/null @@ -1,126 +0,0 @@ -<?php -// $Id$ - -class XMLRPCValidator1Test extends DrupalWebTestCase { - /** - * Implementation of getInfo(). - */ - function getInfo() { - return array( - 'name' => t('XML-RPC validator'), - 'description' => t('See !validator-link. note: simpletest_xmlrpc.module must be enabled', array('!validator-link' => l('the xmlrpc validator1 specification', 'http://www.xmlrpc.com/validator1Docs'))), - 'group' => t('XML-RPC') - ); - } - - function setUp() { - parent::setUp('simpletest_xmlrpc'); - } - - function test_run_all_tests() { - if (!module_exists('simpletest_xmlrpc')) { - return FALSE; - } - $xml_url = url(NULL, array('absolute' => TRUE)) . 'xmlrpc.php'; - srand(); - mt_srand(); - - - $array_1 = array(array('curly' => mt_rand(-100,100)), - array('curly' => mt_rand(-100,100)), - array('larry' => mt_rand(-100,100)), - array('larry' => mt_rand(-100,100)), - array('moe' => mt_rand(-100,100)), - array('moe' => mt_rand(-100,100)), - array('larry' => mt_rand(-100,100))); - shuffle($array_1); - $l_res_1 = simpletest_xmlrpc_arrayOfStructsTest($array_1); - $r_res_1 = xmlrpc($xml_url, 'validator1.arrayOfStructsTest', $array_1); - $this->assertIdentical($l_res_1, $r_res_1, 'array of structs test: %s'); - - - $string_2 = 't\'&>>zf"md>yr>xlcev<h<"k&j<og"w&&>">>uai"np&s>>q\'&b<>"&&&'; - $l_res_2 = simpletest_xmlrpc_countTheEntities($string_2); - $r_res_2 = xmlrpc($xml_url, 'validator1.countTheEntities', $string_2); - $this->assertIdentical($l_res_2, $r_res_2, 'count the entities test: %s'); - - - $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 = simpletest_xmlrpc_easyStructTest($struct_3); - $r_res_3 = xmlrpc($xml_url, 'validator1.easyStructTest', $struct_3); - $this->assertIdentical($l_res_3, $r_res_3, 'easy struct test: %s'); - - - $struct_4 = array('sub1' => array('bar' => 13), - 'sub2' => 14, - 'sub3' => array('foo' => 1, 'baz' => 2), - 'sub4' => array('ss' => array('sss' => array('ssss' => 'sssss')))); - $l_res_4 = simpletest_xmlrpc_echoStructTest($struct_4); - $r_res_4 = xmlrpc($xml_url, 'validator1.echoStructTest', $struct_4); - $this->assertIdentical($l_res_4, $r_res_4, 'echo struct test: %s'); - - $int_5 = mt_rand(-100,100); - $bool_5 = (($int_5 % 2) == 0); - $string_5 = $this->randomName(); - $double_5 = (double)(mt_rand(-1000,1000) / 100); - $time_5 = time(); - $base64_5 = $this->randomName(100); - $l_res_5 = simpletest_xmlrpc_manyTypesTest($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), $base64_5); - $l_res_5[5] = $l_res_5[5]->data; /* override warpping */ - $r_res_5 = xmlrpc($xml_url, 'validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5)); - /* Contains objects, objects are not equal */ - // See http://drupal.org/node/37766 why this currnetly fails - $this->assertEqual($l_res_5, $r_res_5, 'many types test: %s'); - - - $size = mt_rand(100,200); - $array_6 = array(); - for ($i = 0; $i < $size; $i++) { - $array_6[] = $this->randomName(mt_rand(8,12)); - } - - $l_res_6 = simpletest_xmlrpc_moderateSizeArrayCheck($array_6); - $r_res_6 = xmlrpc($xml_url, 'validator1.moderateSizeArrayCheck', $array_6); - $this->assertIdentical($l_res_6, $r_res_6, 'moderate size array check: %s'); - - - $struct_7 = array(); - for ($y = 2000; $y < 2002; $y++) { - for ($m = 3; $m < 5; $m++) { - for ($d = 1; $d < 6; $d++) { - $ys = (string)$y; - $ms = sprintf('%02d', $m); - $ds = sprintf('%02d', $d); - $struct_7[$ys][$ms][$ds]['moe'] = mt_rand(-100,100); - $struct_7[$ys][$ms][$ds]['larry'] = mt_rand(-100,100); - $struct_7[$ys][$ms][$ds]['curly'] = mt_rand(-100,100); - } - } - } - $l_res_7 = simpletest_xmlrpc_nestedStructTest($struct_7); - $r_res_7 = xmlrpc($xml_url, 'validator1.nestedStructTest', $struct_7); - $this->assertIdentical($l_res_7, $r_res_7, 'nested struct test: %s'); - - - $int_8 = mt_rand(-100,100); - $l_res_8 = simpletest_xmlrpc_simpleStructReturnTest($int_8); - $r_res_8 = xmlrpc($xml_url, 'validator1.simpleStructReturnTest', $int_8); - $this->assertIdentical($l_res_8, $r_res_8, 'nested struct test: %s'); - - /* Now test multicall */ - $x = array(); - $x[] = array('validator1.arrayOfStructsTest', $array_1); - $x[] = array('validator1.countTheEntities', $string_2); - $x[] = array('validator1.easyStructTest', $struct_3); - $x[] = array('validator1.echoStructTest', $struct_4); - $x[] = array('validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5)); - $x[] = array('validator1.moderateSizeArrayCheck', $array_6); - $x[] = array('validator1.nestedStructTest', $struct_7); - $x[] = array('validator1.simpleStructReturnTest', $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); - $this->assertEqual($a_l_res, $a_r_res, 'multicall equals result'); - } -} -?> |