summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/actions.test66
-rw-r--r--modules/simpletest/tests/bootstrap.test110
-rw-r--r--modules/simpletest/tests/cache.test236
-rw-r--r--modules/simpletest/tests/database.test182
-rw-r--r--modules/simpletest/tests/form.test74
-rw-r--r--modules/simpletest/tests/registry.test153
6 files changed, 821 insertions, 0 deletions
diff --git a/modules/simpletest/tests/actions.test b/modules/simpletest/tests/actions.test
new file mode 100644
index 000000000..68b7a1b98
--- /dev/null
+++ b/modules/simpletest/tests/actions.test
@@ -0,0 +1,66 @@
+<?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/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
new file mode 100644
index 000000000..de833f117
--- /dev/null
+++ b/modules/simpletest/tests/bootstrap.test
@@ -0,0 +1,110 @@
+<?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/modules/simpletest/tests/cache.test b/modules/simpletest/tests/cache.test
new file mode 100644
index 000000000..e082da3fd
--- /dev/null
+++ b/modules/simpletest/tests/cache.test
@@ -0,0 +1,236 @@
+<?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/modules/simpletest/tests/database.test b/modules/simpletest/tests/database.test
new file mode 100644
index 000000000..83bb3a123
--- /dev/null
+++ b/modules/simpletest/tests/database.test
@@ -0,0 +1,182 @@
+<?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/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
new file mode 100644
index 000000000..70cb131cb
--- /dev/null
+++ b/modules/simpletest/tests/form.test
@@ -0,0 +1,74 @@
+<?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/modules/simpletest/tests/registry.test b/modules/simpletest/tests/registry.test
new file mode 100644
index 000000000..13bfa9074
--- /dev/null
+++ b/modules/simpletest/tests/registry.test
@@ -0,0 +1,153 @@
+<?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;
+ }
+
+}
+