### Eclipse Workspace Patch 1.0
#P simpletest
Index: tests/user_module.test
===================================================================
RCS file: tests/user_module.test
diff -N tests/user_module.test
--- tests/user_module.test 28 Jan 2008 08:48:37 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,260 +0,0 @@
- t('User registration'), 'desc' => t('Registers a user, fails login, resets password, successfully logs in with the one time password, changes password, logs out, successfully logs in with the new password, visits profile page.') , 'group' => 'User tests');
- }
-
- function testUserRegistration() {
- /* We first allow every user to login instantly. */
- $this->drupalVariableSet('user_register', 1);
-
- /* make sure the profile module is disabled to avoid conflicts */
- $this->drupalModuleDisable('profile');
-
- $name = $this->randomName();
- $mail = "$name@example.com";
- $edit = array('name' => $name,
- 'mail' => $mail);
- $this->drupalPost('user/register', $edit, 'Create new account');
-
- $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), 'Your password and further instructions ... found');
- $this->assertNoText(t('The name %name has been denied access.', array('%name' => $name)), 'not denied access');
-
- // now we check database fields
- // we can use an 'edit' array to load user variable
- $user = user_load($edit);
-
- $this->assertTrue(isset($user->uid), 'user->uid set');
- $this->assertTrue(($user->uid > 0), 'uid > 0');
- if (!isset($user->uid) || ($user->uid == 0)) {
- return FALSE;
- }
-
- $this->assertEqual($user->name, $name, 'Checking name of user');
- $this->assertEqual($user->mail, $mail, 'Checking e-mail address');
- $this->assertEqual($user->mode, 0, 'Checking mode field');
- $this->assertEqual($user->sort, 0, 'Checking sort field');
- $this->assertEqual($user->threshold, 0,'Checking treshold field');
- $this->assertEqual($user->theme, '','Checking theme field');
- $this->assertEqual($user->signature, '','Checking signature field');
- $this->assertTrue(($user->created > time() - 20 ), 0,'Checking creation time.');
- $this->assertEqual($user->status, variable_get('user_register', 1) == 1 ? 1 : 0,'Checking status field');
- $this->assertEqual($user->timezone, variable_get('date_default_timezone', NULL), 'Checking timezone field');
- $this->assertEqual($user->language, '', 'Checking language field');
- $this->assertEqual($user->picture, '', 'Check picture field');
- $this->assertEqual($user->init, $mail, 'Check init field');
-
- /* We try to login with a wrong password */
- $login_edit = array('name' => $name, 'pass' => 'foo');
- $this->drupalPost('user', $login_edit, 'Log in');
- $this->assertText(t('Sorry, unrecognized username or password. Have you forgotten your password?'), 'Test for failed Login');
- $url = user_pass_reset_url($user);
- /* TODO: find a better way, we currently have to do it that way, see user.module line 1041. */
- sleep(1);
- $this->_browser->get($url);
-
- // Will proabaly not work localised as the text is sent to tranlate wrapped in
usually
-
- $this->assertText(t('This login can be used only once.'), "Check for 'used only once' notice");
-
- $this->_browser->clickSubmit(t('Log in'));
- $this->assertText(t('You have just used your one-time login link. It is no longer necessary to use this link to login. Please change your password.'), "Check for one time login notice after clicking Login button.");
-
- /* now lets change our password */
- $new_pass = user_password();
- $this->assertTrue($this->_browser->setField('pass[pass1]', $new_pass), 'Pass1 field set.');
- $this->assertTrue($this->_browser->setField('pass[pass2]', $new_pass), 'Pass2 field set.');
- $this->_browser->clickSubmit(t('Save'));
- $this->assertText(t('The changes have been saved.'), "Changed password to '$new_pass'");
-
- /* Check if the password changes are present in db */
- $user = user_load(array('uid' => $user->uid));
- $this->assertEqual($user->pass, md5($new_pass), 'Correct password in database');
-
- /* logout */
- $this->clickLink('Log out');
- $this->assertNoText($user->name, 'Logged out');
-
- /* login again */
- $login_edit['pass'] = $new_pass;
- $this->drupalPost('user', $login_edit, 'Log in');
-
- $pname = $user->name;
-
- $this->assertText($pname, 'Logged in (name found)');
- $this->assertNoText(t('Sorry. Unrecognized username or password.'), 'Logged in (no message for unrecognized username or password)');
- $this->assertNoText(t('User login'), 'Logged in (no user login form present)');
- // I can't find this in Drupal anywhere, but I left it in for now.
- $this->assertNoUnwantedRaw(t('The username %name has been blocked.', array('%name' => $pname)), 'Not blocked');
- $this->assertNoUnwantedRaw(t('The name %name is a reserved username.', array('%name' => $pname)), 'Access granted');
-
- $this->_browser->get(url('user'), array('absolute' => TRUE));
- $this->assertText($pname, 'user as auth lands on the user profile');
- $this->assertText(t('View'), 'View tab on the profile page');
- $this->assertText(t('Edit'), 'Edit tab on the profile page');
-
- /* delete test user, roles and maybe authmap */
- db_query('DELETE FROM {users} WHERE uid = %d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- db_query('DELETE FROM {authmap} WHERE uid = %d', $user->uid);
- }
-}
-
-/**
- * This class is based on the original Simpletest Module by Moshe Weitzman
- */
-class UserValidationTest extends DrupalTestCase {
- function get_info() {
- return array('name' => 'Username/email validation', 'desc' => 'Verify that username/email validity checks behave as designed.' , 'group' => 'User tests');
- }
-
- // username validation
- function testMinLengthName() {
- $name = '';
- $result = user_validate_name($name);
- $this->assertNotNull($result, 'Excessively short username');
- }
- function testValidCharsName() {
- $name = 'ab/';
- $result = user_validate_name($name);
- $this->assertNotNull($result, 'Invalid chars in username');
- }
- function testMaxLengthName() {
- $name = str_repeat('a', 61);
- $result = user_validate_name($name);
- $this->assertNotNull($result, 'Excessively long username');
- }
- function testValidName() {
- $name = 'abc';
- $result = user_validate_name($name);
- $this->assertNull($result, 'Valid username');
- }
-
- // mail validation
- function testMinLengthMail() {
- $name = '';
- $result = user_validate_mail($name);
- $this->assertNotNull($result, 'Empty mail');
- }
- function testInValidMail() {
- $name = 'abc';
- $result = user_validate_mail($name);
- $this->assertNotNull($result, 'Invalid mail');
- }
- function testValidMail() {
- $name = 'absdsdsdc@dsdsde.com';
- $result = user_validate_mail($name);
- $this->assertNull($result, 'Valid mail');
- }
-}
-
-class UserAccessTest extends DrupalTestCase {
- var $_cleanup_masks = array();
-
- function get_info() {
- return array('name' => t('User access rules'),
- 'desc' => t('Assure that negative and positive access rules behave as designed.') ,
- 'group' => 'User tests'
- );
- }
-
- function _addMask($mask, $type, $status = 0) {
- db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $mask, $type, $status);
- $aid = db_last_insert_id('access', 'aid');
- $str_status = ($status == 0) ? 'deny' : 'allow';
- $this->assertTrue(db_affected_rows() > 0, "$str_status Mask added for $type '$mask'");
- $this->_cleanup_masks[] = $aid;
- }
-
- function tearDown() {
- while (sizeof($this->_cleanup_masks) > 0) {
- $aid = array_pop($this->_cleanup_masks);
- db_query("DELETE FROM {access} WHERE aid = %d", $aid);
- }
- }
-
- function testAccess() {
- /* To avoid conflicts with non allowed account creations */
- $this->drupalVariableSet('user_register', 1);
-
- $this->_addMask('simpletest_block%', 'user');
- $this->_addMask('simpletest_block_allow%', 'user', 1);
-
- /* first try blocked user */
- $name = $this->randomName(2, 'simpletest_block_');
- $mail = "$name@example.com";
- $edit = array('name' => $name,
- 'mail' => $mail);
-
- $this->drupalPost('user/register', $edit, 'Create new account');
-
- $this->assertNoUnWantedText(t('Your password and further instructions have been sent to your e-mail address.'), 'blocked user: Your password and further instructions - not found');
- $this->assertText(t('The name @name has been denied access.', array('@name' => $name)), 'blocked user: denied access - found');
-
- /* Lets make a new browser for new cookies */
- $this->setBrowser($this->createBrowser());
-
- /* now try allowed user */
- $name = $this->randomName(2, 'simpletest_block_allow_');
- $mail = "$name@example.com";
- $edit = array('name' => $name,
- 'mail' => $mail);
-
- $this->drupalPost('user/register', $edit, 'Create new account');
-
- $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), 'access user: Your password and further instructions - found');
- $this->assertNoText(t('The name @name has been denied access.', array('@name' => $name)), 'access user: denied access - not found');
-
- $user = user_load($edit);
-
- $this->assertTrue(isset($user->uid), 'user->uid set');
- $this->assertTrue(($user->uid > 0), 'uid > 0');
- if (isset($user->uid) && ($user->uid > 0)) {
- /* delete test user, roles and maybe authmap */
- db_query('DELETE FROM {users} WHERE uid = %d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- db_query('DELETE FROM {authmap} WHERE uid = %d', $user->uid);
- }
- }
-}
-
-class UserDeleteTest extends DrupalTestCase {
- function get_info() {
- return array('name' => t('User delete'), 'desc' => t('Registers a user and deletes it.') , 'group' => 'User tests');
- }
-
- function tearDown() {
- parent::tearDown();
- }
-
- function testUserRegistration() {
- /* We first allow every user to login instantly. */
- $this->drupalVariableSet('user_register', 1);
-
- /* make sure the profile module is disabled to avoid conflicts */
- $this->drupalModuleDisable('profile');
-
- $name = $this->randomName();
- $pname = theme('placeholder', $name);
- $mail = "$name@example.com";
- $edit = array('name' => $name,
- 'mail' => $mail);
- $this->drupalPost('user/register', $edit, 'Create new account');
- $user_to_delete = user_load($edit);
- $uid = $user_to_delete->uid;
- $web_user = $this->drupalCreateUserRolePerm(array('administer users'));
- $this->drupalLoginUser($web_user);
- $this->_browser->get(url('user/'. $uid .'/edit', array('absolute' => TRUE)));
- $this->_browser->clickSubmit(t('Delete'));
- $this->assertWantedRaw(t('Are you sure you want to delete the account %name?', array('%name' => $name)), 'Confirm title');
- $this->assertText(t('All submissions made by this user will be attributed to the anonymous account. This action cannot be undone.'), 'Confirm text');
- $this->_browser->clickSubmit(t('Delete'));
- $this->assertWantedRaw(t('%name has been deleted.', array('%name' => $name)), 'User deleted');
- $this->assertFalse(user_load($edit), 'User is not found in the database');
- }
-}
Index: tests/modules_system.test
===================================================================
RCS file: tests/modules_system.test
diff -N tests/modules_system.test
--- tests/modules_system.test 28 Jan 2008 08:48:37 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,233 +0,0 @@
- t('Enable core modules'), 'desc' => 'Enables all core modules by POST - looks for error messages, confirms table creation, etc.', 'group' => 'Modules');
- }
-
- function testEnableCoreModules () {
- // Get a list of the modules to enable
- $modules_to_enable = array (
- 'aggregator',
- 'blog',
- 'blogapi',
- 'book',
- 'color',
- 'comment',
- 'contact',
- 'dblog',
- 'forum',
- 'help',
- 'locale',
- 'menu',
- 'openid',
- 'path',
- 'php',
- 'ping',
- 'poll',
- 'profile',
- 'search',
- 'statistics',
- 'syslog',
- 'taxonomy',
- 'throttle',
- 'tracker',
- 'translation',
- 'trigger',
- 'update',
- 'upload',
- );
-
- // Get a list of the currently enabled modules
- $enabled_modules = module_list(true, false);
-
- $web_user = $this->drupalCreateUserRolePerm(array (
- 'access administration pages',
- 'administer site configuration',
- ));
- $this->drupalLoginUser($web_user);
-
- $edit = array();
- // We temporarily disable any modules we're testing so that we can re-enable them for testing
- foreach ($modules_to_enable as $module) {
- if (module_exists($module))
- $this->drupalModuleDisable($module);
-
- $edit['status['. $module .']'] = $module;
- }
-
- $this->drupalPost('admin/build/modules/list/confirm', $edit, 'Save configuration');
- $this->assertWantedRaw(t('The configuration options have been saved.'), t('Ensure that the module status has been updated'));
-
- // Now, we check the tables for each module
- // We also refresh the module list and make sure the modules are enabled
- module_list(true, false);
- foreach ($modules_to_enable as $module) {
- $cur_schema = drupal_get_schema_unprocessed($module);
-
- $tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
- foreach ($tables as $table)
- $this->assertTrue(db_table_exists($table), t('Make sure that the database table for the module exists'));
-
- $this->assertTrue(module_exists($module), t('Check to see that the module is actually enabled'));
- }
-
- // Disable/uninstall all the modules that have been installed by this process
- // We first need to refresh the module list
- include_once './includes/install.inc';
-
- foreach ($modules_to_enable as $module) {
- // We uninstall the modules that weren't already enabled
- if (!in_array($module, $enabled_modules)) {
- module_disable(array($module));
- drupal_uninstall_module($module);
- }
- }
-
- drupal_clear_css_cache();
- drupal_clear_js_cache();
- }
-}
-
-class EnableModuleWithoutDependencyTest extends DrupalTestCase {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Enable module without required dependencies'), 'desc' => 'Attempts to enable the forum module without enabling dependencies.', 'group' => 'Modules');
- }
-
- function testEnableWithoutDependency () {
- // Disable all modules for this test
- $current_modules = module_list(true, false);
- foreach ($current_modules as $module) {
- // We don't disable core modules
- if (!in_array($module, drupal_required_modules()))
- $this->drupalModuleDisable($module);
- }
-
- // Attempt to enable forum module, which should fail because comment and taxonomy are not enabled
- $web_user = $this->drupalCreateUserRolePerm(array (
- 'access administration pages',
- 'administer site configuration',
- ));
- $this->drupalLoginUser($web_user);
-
- $edit = array (
- 'status[forum]' => 'forum',
- );
-
- $this->drupalPost('admin/build/modules/list/confirm', $edit, 'Save configuration');
- $this->assertWantedRaw(t('Some required modules must be enabled'), t('Make sure the dependency error is shown'));
-
- $this->assertFalse(module_exists('forum'), t('Check to make sure that the module has not somehow become enabled'));
- }
-}
-
-class DisableUninstallCoreModuleTest extends DrupalTestCase {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Disable/uninstall core modules'), 'desc' => 'Disables and uninstalls core modules, ensures that that tables are properly deleted, no error messages are shown, etc.', 'group' => 'Modules');
- }
-
- function testDisableUninstallCoreModules () {
- // Get a list of the modules to test
- $modules_to_test = array (
- 'aggregator',
- 'blog',
- 'blogapi',
- 'book',
- 'color',
- 'comment',
- 'contact',
- 'dblog',
- 'forum',
- 'help',
- 'locale',
- 'menu',
- 'openid',
- 'path',
- 'php',
- 'ping',
- 'poll',
- 'profile',
- 'search',
- 'statistics',
- 'syslog',
- 'taxonomy',
- 'throttle',
- 'tracker',
- 'translation',
- 'trigger',
- 'update',
- 'upload',
- );
-
- // Get a list of the currently enabled modules
- $enabled_modules = module_list(true, false);
-
- // We don't want to test any modules that are already enabled, since that would involve a loss of data
- foreach ($enabled_modules as $module) {
- if (in_array($module, $modules_to_test))
- unset($modules_to_test[array_search($module, $modules_to_test)]);
- }
-
- // Enable all the modules that are not already enabled
- include_once './includes/install.inc';
- module_enable($modules_to_test);
- drupal_install_modules($modules_to_test);
-
- $web_user = $this->drupalCreateUserRolePerm(array (
- 'access administration pages',
- 'administer site configuration',
- ));
- $this->drupalLoginUser($web_user);
-
- // Disable/uninstall the given modules: we keep every other module enabled
- // We do this loop because for each level of dependency, we need one more request
- while (count(array_diff(module_list(true, false), $enabled_modules)) > 0) {
- $edit = array();
- foreach ($modules_to_test as $module) {
- $edit['status['. $module .']'] = 0;
- }
- foreach ($enabled_modules as $module) {
- $edit['status['. $module .']'] = $module;
- }
-
- $this->drupalPost('admin/build/modules/list/confirm', $edit, 'Save configuration');
- $this->assertWantedRaw(t('The configuration options have been saved.'), t('Ensure that the module status has been updated'));
- }
-
- // Now, lets make sure the modules are truly disabled and then try to uninstall them
- module_list(true, false);
- $edit = array();
- foreach ($modules_to_test as $module) {
- $this->assertFalse(module_exists($module), t('Make sure the module has been disabled'));
-
- if (module_hook($module, 'uninstall'))
- $edit['uninstall['. $module .']'] = $module;
- }
-
- $this->drupalPost('admin/build/modules/uninstall/confirm', $edit, 'Uninstall');
- // We need to confirm this by clicking again
- $this->_browser->clickSubmit(t('Uninstall'));
- $this->assertWantedRaw(t('The selected modules have been uninstalled.'), 'Check to ensure that the modules have been removed');
-
- // Now, we check the tables for each module
- foreach ($modules_to_test as $module) {
- $cur_schema = drupal_get_schema_unprocessed($module);
-
- $tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
- foreach ($tables as $table)
- $this->assertFalse(db_table_exists($table), t('Ensure that the database table has been properly removed'));
- }
-
- drupal_clear_css_cache();
- drupal_clear_js_cache();
- }
-}
Index: tests/blogapi_module.test
===================================================================
RCS file: tests/blogapi_module.test
diff -N tests/blogapi_module.test
--- tests/blogapi_module.test 28 Jan 2008 08:48:37 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,165 +0,0 @@
- t('BlogAPI functionality'),
- 'desc' => t('Create, edit, and delete post; upload file; and set/get categories.'),
- 'group' => t('Blog API Tests'),
- );
- }
-
- function setUp() {
- parent::setUp();
-
- $this->drupalModuleEnable('blog');
- $this->drupalModuleEnable('blogapi');
- $this->drupalModuleEnable('taxonomy');
- }
-
- function test_blog_API() {
- // Create admin user and taxononmy for later use.
- $admin_user = $this->drupalCreateUserRolePerm(array('administer taxonomy'));
- $this->drupalLoginUser($admin_user);
-
- $vid = $this->add_vocabulary('simpletest_vocab');
-
- $term = $this->add_term($vid, 'simpletest_term1');
-
- $this->drupalGet('logout');
-
- // Create user.
- $web_user = $this->drupalCreateUserRolePerm(array('create blog entries', 'delete own blog entries', 'edit own blog entries', 'administer content with blog api'));
- $this->drupalLoginUser($web_user);
-
- // Init common variables.
- $local = url('xmlrpc.php', array('absolute' => TRUE));
- $appid = 'simpletest';
-
- // Get user's blog.
- $result = xmlrpc($local, 'blogger.getUsersBlogs', $appid, $web_user->name, $web_user->pass_raw);
- $this->assertTrue($result, 'Request for user\'s blogs returned correctly.');
-
- if ($result !== FALSE) {
- $this->assertTrue(array_key_exists('url', $result[0]), 'Blog found.');
-
- if (array_key_exists('url', $result[0])) {
- $blog_id = substr($result[0]['url'], strrpos($result[0]['url'], '/') + 1);
- }
- }
-
- // Create post.
- $content = $this->randomName(10);
- $result = xmlrpc($local, 'blogger.newPost', $appid, $blog_id, $web_user->name, $web_user->pass_raw, $content, TRUE);
- $this->assertTrue($result, 'Post created.');
-
- $nid = $result;
-
- // Check recent posts.
- $result = xmlrpc($local, 'blogger.getRecentPosts', $appid, $blog_id, $web_user->name, $web_user->pass_raw, 5);
- $this->assertTrue($result, 'Recent post list retreived.');
-
- if ($result !== FALSE && array_key_exists('title', $result[0])) {
- $this->assertEqual($content, $result[0]['title'], 'Post found.');
- }
- else
- $this->assertTrue(false, 'Post found.');
-
- // Edit post.
- $content_new = $this->randomName(10);
- $result = xmlrpc($local, 'blogger.editPost', $appid, $nid, $web_user->name, $web_user->pass_raw, $content_new, TRUE);
- $this->assertTrue($result, 'Post successfully modified.');
-
- // Upload file.
- $file_contents = 'This is a test file that will be transfered via BlogAPI!';
- $file = array();
- $file['name'] = $this->randomName() .'.txt';
- $file['type'] = 'text';
- $file['bits'] = xmlrpc_base64($file_contents);
- $result = xmlrpc($local, 'metaWeblog.newMediaObject', $blog_id, $web_user->name, $web_user->pass_raw, $file);
- $this->assertTrue($result, 'File successfully uploaded.');
-
- $url = (array_key_exists('url', $result) ? $result['url'] : '');
-
- // Check uploaded file.
- $this->drupalGet($url);
- $this->assertEqual($this->drupalGetContent(), $file_contents, 'Uploaded contents verified.');
-
- // Set post categories.
- $categories = array(array('categoryId' => $term));
- $result = xmlrpc($local, 'mt.setPostCategories', $nid, $web_user->name, $web_user->pass_raw, $categories);
- $this->assertTrue($result, 'Post categories set.');
-
- // Get post categories.
- $result = xmlrpc($local, 'mt.getPostCategories', $nid, $web_user->name, $web_user->pass_raw);
- $this->assertTrue($result, 'Category list successfully retreived.');
-
- if ($result !== FALSE && array_key_exists('categoryId', $result[0])) {
- $this->assertEqual($term, $result[0]['categoryId'], 'Category list verified.');
- }
-
- // Delete post.
- $result = xmlrpc($local, 'blogger.deletePost', $appid, $nid, $web_user->name, $web_user->pass_raw, TRUE);
- $this->assertTrue($result, 'Post successfully deleted.');
-
- $this->drupalGet('logout');
-
- // Remove taxonmy vocab.
- $this->drupalLoginUser($admin_user);
-
- $this->drupalPost('admin/content/taxonomy/edit/vocabulary/'. $vid, array(), 'Delete');
- $this->drupalPost(NULL, array(), 'Delete');
- $this->assertWantedRaw(t('Deleted vocabulary %vocab.', array('%vocab' => 'simpletest_vocab')), 'Removed vocabulary.');
- }
-
- /**
- * Add taxonomy vocabulary.
- *
- * @param string $vocab Vocabulary name.
- */
- function add_vocabulary($vocab) {
- $edit = array();
- $edit['name'] = $vocab;
- $edit['nodes[blog]'] = TRUE;
- $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, 'Save');
- $this->assertWantedRaw(t('Created new vocabulary %vocab.', array('%vocab' => $edit['name'])), 'Taxonomy vocabulary added.');
-
- $vocab_arr = taxonomy_get_vocabularies();
- $vid = NULL;
- foreach ($vocab_arr as $vocab_item) {
- if ($vocab_item->name == $vocab) {
- $vid = $vocab_item->vid;
- break;
- }
- }
-
- $this->assertNotNull($vid, 'Vocabulary found in database.');
- return $vid;
- }
-
- /**
- * Add a taxonomy term to vocabulary.
- *
- * @param integer $vid Vocabulary id.
- * @param string $term Term name.
- */
- function add_term($vid, $term) {
- $edit = array();
- $edit['name'] = $term;
- $this->drupalPost('admin/content/taxonomy/'. $vid .'/add/term', $edit, 'Save');
- $this->assertWantedRaw(t('Created new term %term.', array('%term' => $edit['name'])), 'Taxonomy term added.');
-
- $tree = taxonomy_get_tree($vid);
- $tid = NULL;
- foreach ($tree as $tree_term) {
- if ($tree_term->name == $term) {
- $tid = $tree_term->tid;
- break;
- }
- }
-
- $this->assertNotNull($tid, 'Term found in database.');
- return $tid;
- }
-}
Index: tests/path_module.test
===================================================================
RCS file: tests/path_module.test
diff -N tests/path_module.test
--- tests/path_module.test 28 Jan 2008 08:48:37 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,144 +0,0 @@
- t('Path alias functionality'),
- 'desc' => t('Add, edit, delete, and change alias and verify its consistency in the database.'),
- 'group' => t('Path Tests'),
- );
- }
-
- /**
- * Create user, setup permissions, log user in, and create a node.
- */
- function setUp() {
- parent::setUp();
-
- $this->drupalModuleEnable('path');
-
- // create and login user
- $web_user = $this->drupalCreateUserRolePerm(array('edit own page content', 'create page content', 'administer url aliases', 'create url aliases'));
- $this->drupalLoginUser($web_user);
- }
-
- /**
- * Test alias functionality through the admin interfaces.
- */
- function testAdminAlias() {
- // create test node
- $node1 = $this->createNode();
-
- // create alias
- $edit = array();
- $edit['src'] = 'node/' . $node1->nid;
- $edit['dst'] = $this->randomName(8);
- $this->drupalPost('admin/build/path/add', $edit, 'Create new alias');
-
- // confirm that the alias works
- $this->drupalGet($edit['dst']);
- $this->assertText($node1->title, 'Alias works.');
-
- // change alias
- $pid = $this->getPID($edit['dst']);
-
- $previous = $edit['dst'];
- $edit['dst'] = $this->randomName(8);
- $this->drupalPost('admin/build/path/edit/' . $pid, $edit, 'Update alias');
-
- // confirm that the alias works
- $this->drupalGet($edit['dst']);
- $this->assertText($node1->title, 'Changed alias works.');
-
- // make sure that previous alias no longer works
- $this->drupalGet($previous);
- $this->assertNoText($node1->title, 'Previous alias no longer works.');
- $this->assertTitle(new PatternExpectation('/Page not found/'), 'We get page not found error');
-
- // create second test node
- $node2 = $this->createNode();
-
- // set alias to second test node
- $edit['src'] = 'node/' . $node2->nid;
- // leave $edit['dst'] the same
- $this->drupalPost('admin/build/path/add', $edit, 'Create new alias');
-
- // confirm that the alias didn't make a duplicate
- $this->assertWantedRaw(t('The alias %alias is already in use in this language.', array('%alias' => $edit['dst'])), 'Attempt to move alias was rejected.');
-
- // delete alias
- $this->drupalPost('admin/build/path/delete/' . $pid, array(), 'Confirm');
-
- // confirm that the alias no longer works
- $this->drupalGet($edit['dst']);
- $this->assertNoText($node1->title, 'Alias was successfully deleted.');
- }
-
- /**
- * Test alias functionality through the node interfaces.
- */
- function testNodeAlias() {
- // create test node
- $node1 = $this->createNode();
-
- // create alias
- $edit = array();
- $edit['path'] = $this->randomName(8);
- $this->drupalPost('node/' . $node1->nid . '/edit', $edit, 'Save');
-
- // confirm that the alias works
- $this->drupalGet($edit['path']);
- $this->assertText($node1->title, 'Alias works.');
-
- // change alias
- $previous = $edit['path'];
- $edit['path'] = $this->randomName(8);
- $this->drupalPost('node/' . $node1->nid . '/edit', $edit, 'Save');
-
- // confirm that the alias works
- $this->drupalGet($edit['path']);
- $this->assertText($node1->title, 'Changed alias works.');
-
- // make sure that previous alias no longer works
- $this->drupalGet($previous);
- $this->assertNoText($node1->title, 'Previous alias no longer works.');
- $this->assertTitle(new PatternExpectation('/Page not found/'), 'We get page not found error');
-
- // create second test node
- $node2 = $this->createNode();
-
- // set alias to second test node
- // leave $edit['path'] the same
- $this->drupalPost('node/' . $node2->nid . '/edit', $edit, 'Save');
-
- // confirm that the alias didn't make a duplicate
- $this->assertText(t('The path is already in use.'), 'Attempt to moved alias was rejected.');
-
- // delete alias
- $this->drupalPost('node/' . $node1->nid . '/edit', array('path' => ''), 'Save');
-
- // confirm that the alias no longer works
- $this->drupalGet($edit['path']);
- $this->assertNoText($node1->title, 'Alias was successfully deleted.');
- }
-
- function getPID($dst) {
- return db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $dst));
- }
-
- function createNode() {
- $this->drupalVariableSet('node_options_page', array('status', 'promote'));
-
- $edit = array();
- $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10);
- $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
- $this->drupalPost('node/add/page', $edit, 'Save');
-
- // check to make sure the node was created
- $node = node_load(array('title' => $edit['title']));
- $this->assertNotNull(($node === FALSE ? NULL : $node), 'Node found in database. %s');
-
- return $node;
- }
-}
Index: tests/xmlrpc_validator1.test
===================================================================
RCS file: tests/xmlrpc_validator1.test
diff -N tests/xmlrpc_validator1.test
--- tests/xmlrpc_validator1.test 8 Sep 2007 23:02:40 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,116 +0,0 @@
- 'XML-RPC validator1',
- 'desc' => 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' => 'XML-RPC Tests');
- }
-
- function test_run_all_tests() {
- if (!$this->drupalModuleEnable('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">>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');
- }
-}
-?>
\ No newline at end of file
Index: tests/translation_module.test
===================================================================
RCS file: tests/translation_module.test
diff -N tests/translation_module.test
--- tests/translation_module.test 28 Jan 2008 08:48:37 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,150 +0,0 @@
- t('Translation functionality'),
- 'desc' => t('Create a story with translation, modify the story outdating translation, and update translation.'),
- 'group' => t('Translation Tests'),
- );
- }
-
- function setUp() {
- parent::setUp();
-
- // Enable modules.
- $this->drupalModuleEnable('locale');
- $this->drupalModuleEnable('translation');
- }
-
- function test_content_translation() {
- // Setup users.
- $admin_user = $this->drupalCreateUserRolePerm(array('administer languages', 'administer content types'));
- $translator = $this->drupalCreateUserRolePerm(array('create story content', 'edit own story content', 'translate content'));
-
- $this->drupalLoginUser($admin_user);
-
- // Add languages.
- $this->add_language('en');
- $this->add_language('es');
-
- // Set story content type to use multilingual support with translation.
- $this->drupalPost('admin/content/types/story', array('language_content_type' => "2"), 'Save content type');
- $this->assertWantedRaw(t('The content type %type has been updated.', array('%type' => 'Story')), 'Story content type has been updated.');
-
- $this->drupalGet('logout');
- $this->drupalLoginUser($translator);
-
- // Create story in English.
- $node_title = 'Test Translation '. $this->randomName();
- $node = $this->create_story($node_title, 'Node body.', 'en');
-
- // Submit translation in Spanish.
- $node_trans_title = 'Test Traduccion '. $this->randomName();
- $node_trans = $this->create_translation($node->nid, $node_trans_title, 'Nodo cuerpo.', 'es');
-
- // Update origninal and mark translation as outdated.
- $edit = array();
- $edit['body'] = 'Node body. Additional Text.';
- $edit['translation[retranslate]'] = TRUE;
- $this->drupalPost('node/'. $node->nid .'/edit', $edit, 'Save');
- $this->assertWantedRaw(t('Story %title has been updated.', array('%title' => $node_title)), 'Original node updated.');
-
- // Check to make sure that interface shows translation as outdated
- $this->drupalGet('node/'. $node->nid .'/translate');
- $this->assertWantedRaw(''. t('outdated') .'', 'Translation marked as outdated.');
-
- // Update translation and mark as updated.
- $edit = array();
- $edit['body'] = 'Nodo cuerpo. Texto adicional.';
- $edit['translation[status]'] = FALSE;
- $this->drupalPost('node/'. $node_trans->nid .'/edit', $edit, 'Save');
- $this->assertWantedRaw(t('Story %title has been updated.', array('%title' => $node_trans_title)), 'Translated node updated.');
- }
-
- /**
- * Install a the specified language if it has not been already. Otherwise make sure that
- * the language is enabled.
- *
- * @param string $language_code The langauge code the check.
- */
- function add_language($language_code) {
- // Check to make sure that language has not already been installed.
- $this->drupalGet('admin/settings/language');
-
- if (strpos($this->drupalGetContent(), 'enabled['. $language_code .']') === FALSE) {
- // Doesn't have language installed so add it.
- $edit = array();
- $edit['langcode'] = $language_code;
- $this->drupalPost('admin/settings/language/add', $edit, 'Add language');
-
- $languages = language_list('language', TRUE); // make sure not using cached version
- $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
-
- if (array_key_exists($language_code, $languages)) {
- $this->assertWantedRaw(t('The language %language has been created and can now be used. More information is available on the help screen.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))));
- }
- }
- else {
- // Ensure that it is enabled.
- $this->assertTrue(true, 'Language ['. $language_code .'] already installed.');
- $this->drupalPost(NULL, array('enabled['. $language_code .']' => TRUE), 'Save configuration');
-
- $this->assertWantedRaw(t('Configuration saved.'), 'Language successfully enabled.');
- }
- }
-
- /**
- * Create a story in the specified language.
- *
- * @param string $title Title of story in specified language.
- * @param string $body Body of story in specified language.
- * @param string $language Langauge code.
- */
- function create_story($title, $body, $language) {
- $this->drupalVariableSet('node_options_page', array('status', 'promote'));
-
- $edit = array();
- $edit['title'] = $title;
- $edit['body'] = $body;
- $edit['language'] = $language;
- $this->drupalPost('node/add/story', $edit, 'Save');
-
- $this->assertWantedRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Story created.');
-
- // Check to make sure the node was created.
- $node = node_load(array('title' => $edit['title']));
- $this->assertTrue($node, 'Node found in database.');
-
- return $node;
- }
-
- /**
- * Create a translation for the specified story in the specified language.
- *
- * @param integer $nid Node id of story to create translation for.
- * @param string $title Title of story in specified language.
- * @param string $body Body of story in specified language.
- * @param string $language Langauge code.
- */
- function create_translation($nid, $title, $body, $language) {
- $this->drupalGet('node/add/story', array('query' => array('translation' => $nid, 'language' => $language)));
-
- $edit = array();
- $edit['title'] = $title;
- $edit['body'] = $body;
-
- $this->drupalPost(NULL, $edit, 'Save');
-
- $this->assertWantedRaw(t('Story %title has been created.', array('%title' => $edit['title'])), 'Translation created.');
-
- // Check to make sure that translation was successfull.
- $node = node_load(array('title' => $edit['title']));
- $this->assertTrue($node, 'Node found in database.');
-
- return $node;
- }
-}
Index: tests/search_match.test
===================================================================
RCS file: tests/search_match.test
diff -N tests/search_match.test
--- tests/search_match.test 28 Jan 2008 07:40:47 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,181 +0,0 @@
- t('Search engine queries'),
- 'desc' => t('Indexes content and queries it.'),
- 'group' => t('Search'),
- );
- }
-
- function setUp() {
- parent::setUp();
-
- $this->drupalModuleEnable('search');
- }
-
- function test_matching() {
- $this->_cleanup();
- $this->_setup();
- $this->_test_queries();
- $this->_cleanup();
- }
-
- /**
- * Set up a small index of items to test against.
- */
- function _setup() {
- $this->drupalVariableSet('minimum_word_size', 3);
-
- for ($i = 1; $i <= 7; ++$i) {
- search_index($i, SEARCH_TYPE, $this->_get_text($i));
- }
- search_update_totals();
- }
-
- /**
- * Clean up the indexed test content.
- */
- function _cleanup() {
- for ($i = 1; $i < 7; ++$i) {
- search_wipe($i, SEARCH_TYPE);
- }
- search_update_totals();
- }
-
-
- /**
- * Helper method for generating snippets of content.
- *
- * Generated items to test against:
- * 1 ipsum
- * 2 dolore sit
- * 3 sit am ut
- * 4 am ut enim am
- * 5 ut enim am minim veniam
- * 6 enim am minim veniam es cillum
- * 7 am minim veniam es cillum dolore eu
- */
- function _get_text($n) {
- $words = explode(' ', "Ipsum dolore sit am. Ut enim am minim veniam. Es cillum dolore eu.");
- return implode(' ', array_slice($words, $n - 1, $n));
- }
-
- /**
- */
- function _test_queries() {
- /*
- Note: OR queries that include short words in OR groups are only accepted
- if the ORed terms are ANDed with at least one long word in the rest of the query.
-
- e.g. enim dolore OR ut = enim (dolore OR ut) = (enim dolor) OR (enim ut) -> good
- e.g. dolore OR ut = (dolore) OR (ut) -> bad
-
- This is a design limitation to avoid full table scans.
- */
- $queries = array(
- // Simple AND queries.
- 'ipsum' => array(1),
- 'enim' => array(4, 5, 6),
- 'xxxxx' => array(),
- 'enim minim' => array(5, 6),
- 'enim xxxxx' => array(),
- 'dolore eu' => array(7),
- 'dolore xx' => array(),
- 'ut minim' => array(5),
- 'xx minim' => array(),
- 'enim veniam am minim ut' => array(5),
- // Simple OR queries.
- 'dolore OR ipsum' => array(1, 2, 7),
- 'dolore OR xxxxx' => array(2, 7),
- 'dolore OR ipsum OR enim' => array(1, 2, 4, 5, 6, 7),
- 'ipsum OR dolore sit OR cillum' => array(2, 7),
- 'minim dolore OR ipsum' => array(7),
- 'dolore OR ipsum veniam' => array(7),
- 'minim dolore OR ipsum OR enim' => array(5, 6, 7),
- 'dolore xx OR yy' => array(),
- 'xxxxx dolore OR ipsum' => array(),
- // Negative queries.
- 'dolore -sit' => array(7),
- 'dolore -eu' => array(2),
- 'dolore -xxxxx' => array(2, 7),
- 'dolore -xx' => array(2, 7),
- // Phrase queries.
- '"dolore sit"' => array(2),
- '"sit dolore"' => array(),
- '"am minim veniam es"' => array(6, 7),
- '"minim am veniam es"' => array(),
- // Mixed queries.
- '"am minim veniam es" OR dolore' => array(2, 6, 7),
- '"minim am veniam es" OR "dolore sit"' => array(2),
- '"minim am veniam es" OR "sit dolore"' => array(),
- '"am minim veniam es" -eu' => array(6),
- '"am minim veniam" -"cillum dolore"' => array(5, 6),
- '"am minim veniam" -"dolore cillum"' => array(5, 6, 7),
- 'xxxxx "minim am veniam es" OR dolore' => array(),
- 'xx "minim am veniam es" OR dolore' => array(),
- );
- foreach ($queries as $query => $results) {
- $set = do_search($query, SEARCH_TYPE);
- $this->_test_query_matching($query, $set, $results);
- $this->_test_query_scores($query, $set, $results);
- $this->_cleanup_query();
- }
- }
-
- /**
- * Test the matching abilities of the engine.
- *
- * Verify if a query produces the correct results.
- */
- function _test_query_matching($query, $set, $results) {
- // Get result IDs.
- $found = array();
- foreach ($set as $item) {
- $found[] = $item->sid;
- }
-
- // Compare $results and $found.
- sort($found);
- sort($results);
- $this->assertEqual($found, $results, "Query matching '$query'");
- }
-
- /**
- * Test the scoring abilities of the engine.
- *
- * Verify if a query produces normalized, monotonous scores.
- */
- function _test_query_scores($query, $set, $results) {
- // Get result scores.
- $scores = array();
- foreach ($set as $item) {
- $scores[] = $item->score;
- }
- $this->_cleanup_query();
-
- // Check order.
- $sorted = $scores;
- sort($sorted);
- $this->assertEqual($scores, array_reverse($sorted), "Query order '$query'");
-
- // Check range.
- $this->assertEqual(!count($scores) || (min($scores) > 0.0 && max($scores) <= 1.0001), TRUE, "Query scoring '$query'");
- }
-
- /**
- * Remove the temporary tables created in a query, since multiple queries per page
- * are not supported.
- *
- * (Drupal 5.0 and below)
- */
- function _cleanup_query() {
- db_query('DROP TABLE IF EXISTS temp_search_sids');
- db_query('DROP TABLE IF EXISTS temp_search_results');
- }
-
-}
Index: tests/story_preview.test
===================================================================
RCS file: tests/story_preview.test
diff -N tests/story_preview.test
--- tests/story_preview.test 28 Jan 2008 08:48:37 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
- 'Story preview test',
- 'desc' => t('We want a working preview for storys, uh?'),
- 'group' => 'Node Tests');
- }
-
- function testStoryPreview() {
- /* Prepare settings */
- $this->drupalVariableSet('node_options_story', array('status', 'promote'));
- /* Prepare a user to do the stuff */
- $web_user = $this->drupalCreateUserRolePerm(array('edit own story content', 'create story content'));
- $this->drupalLoginUser($web_user);
-
- $edit = array(
- 'title'=>'!SimpleTest! title' . $this->randomName(20),
- 'body'=>'!SimpleTest! body' . $this->randomName(200),
- );
- $this->drupalPost('node/add/story', $edit, 'Preview');
-
- $this->assertWantedText(t('Preview'), 'Preview text is here');
- $this->assertWantedText(t($edit['title']), 'Hello, the random title');
- $this->assertWantedText(t($edit['body']), 'test is over, the body\'s still there');
-
- $this->assertFieldByName('title', $edit['title'], 'The title is on it\'s place');
-
- }
-
-}
Index: tests/poll_module.test
===================================================================
RCS file: tests/poll_module.test
diff -N tests/poll_module.test
--- tests/poll_module.test 28 Jan 2008 08:48:37 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,91 +0,0 @@
-assertTrue(TRUE, 'Poll create' . $standalone);
- $web_user = $this->drupalCreateUserRolePerm(array('create poll content', 'access content'));
- $this->drupalLoginUser($web_user);
- $title = $this->randomName();
- $edit = array (
- 'title' => $title,
- 'choice[0][chtext]' => 'choice 1',
- 'choice[1][chtext]' => 'choice 2',
- );
- $this->drupalPost('node/add/poll', $edit, 'More choices');
- $edit = array(
- 'title' => $title,
- 'choice[0][chtext]' => 'choice 1',
- 'choice[1][chtext]' => 'choice 2',
- 'choice[2][chtext]' => 'choice 3',
- 'choice[3][chtext]' => 'choice 4',
- 'choice[4][chtext]' => 'choice 5',
- 'choice[5][chtext]' => 'choice 6',
- 'choice[6][chtext]' => 'choice 7',
- );
- if ($standalone) {
- $this->drupalPost(NULL, $edit, 'Preview');
- for ($i = 0; $i <= 6; $i++) {
- $bar = theme('poll_bar', $edit['choice['. $i .'][chtext]'], NULL, 0, FALSE, FALSE);
- $this->assertTrue($bar, "bar $i is themed");
- $this->assertWantedRaw($bar, "bar $i found in preview");
- }
- }
- $this->drupalPost(NULL, $edit, 'Save');
- $this->nid = preg_replace('/\D/', '', $this->getUrl());
- $this->assertWantedRaw(t('@type %title has been created.', array('@type' => node_get_types('name', 'poll'), '%title' => $title)), 'Poll has been created.');
- }
-
-}
-
-class PollCreateTest extends PollTests {
-
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Poll create'), 'desc' => 'Adds "more choices", previews and creates a poll.', 'group' => 'Poll module tests');
- }
-
- function setUp() {
- parent::setUp();
- $this->drupalModuleEnable('poll');
- }
-
- function testPollCreate() {
- $this->pollCreate(TRUE);
- }
-}
-
-class PollVoteTest extends PollTests {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Poll vote'), 'desc' => 'Vote on a poll', 'group' => 'Poll module tests');
- }
-
- function setUp() {
- parent::setUp();
- $this->drupalModuleEnable('poll');
- }
-
- function tearDown() {
- parent::tearDown();
- }
-
- function testPollVote() {
- $this->pollCreate(FALSE);
- $this->drupalGet('logout');
- $web_user = $this->drupalCreateUserRolePerm(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
- $this->drupalLoginUser($web_user);
- $edit = array (
- 'choice' => '1',
- );
- $this->drupalPost('node/'. $this->nid, $edit, 'Vote');
- $this->assertText('Your vote was recorded.', 'Your vote was recorded.');
- $this->drupalGet("node/$this->nid/votes");
- $this->assertText(t('This table lists all the recorded votes for this poll. If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.'), 'Vote table text.');
- $this->assertText('choice 2', 'vote recorded');
- }
-}
Index: tests/forum_module.test
===================================================================
RCS file: tests/forum_module.test
diff -N tests/forum_module.test
--- tests/forum_module.test 28 Jan 2008 08:48:37 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,364 +0,0 @@
- t('Forum test functions'), 'desc' => 'Helps the forum test cases run by providing common functions. Does not need to be checked.', 'group' => 'Forum');
- }
-
- function setUp() {
- parent::setUp();
-
- // Enable the forum module and its dependencies
- $this->drupalModuleEnable('taxonomy');
- $this->drupalModuleEnable('comment');
- $this->drupalModuleEnable('forum');
- }
-
- function createForumContainer() {
- // Generate a random name/description
- $title = $this->randomName(10);
- $description = $this->randomName(100);
-
- $edit = array(
- 'name' => $title,
- 'description' => $description,
- 'parent[0]' => '0',
- 'weight' => '0',
- );
-
- // Double check that the page says it has created the container
- $this->drupalPost('admin/content/forum/add/container', $edit, 'Save');
- $type = t('forum container');
- $this->assertWantedRaw(t('Created new @type %term.', array('%term' => $title, '@type' => $type)), t('New forum container has been created'));
-
- // Grab the newly created container
- $term = db_fetch_array(db_query("SELECT * FROM {term_data} t WHERE t.vid = %d AND t.name = '%s' AND t.description = '%s'", variable_get('forum_nav_vocabulary', ''), $title, $description));
-
- // Make sure we actually found a container
- $this->assertTrue(!empty($term), 'The container actually exists in the database');
-
- return $term;
- }
-
- function createForum() {
- // Generate a random name/description
- $title = $this->randomName(10);
- $description = $this->randomName(100);
-
- $edit = array(
- 'name' => $title,
- 'description' => $description,
- 'parent[0]' => '0',
- 'weight' => '0',
- );
-
- // Double check that the page says it has created the forum
- $this->drupalPost('admin/content/forum/add/forum', $edit, 'Save');
- $type = t('forum');
- $this->assertWantedRaw(t('Created new @type %term.', array('%term' => $title, '@type' => $type)), t('New forum has been created'));
-
- // Grab the newly created forum
- $term = db_fetch_array(db_query("SELECT * FROM {term_data} t WHERE t.vid = %d AND t.name = '%s' AND t.description = '%s'", variable_get('forum_nav_vocabulary', ''), $title, $description));
-
- // Make sure we actually found a forum
- $this->assertTrue(!empty($term), 'The forum actually exists in the database');
-
- return $term;
- }
-}
-
-class AddForumTest extends DrupalForumTestCase {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Add forum'), 'desc' => 'Adds a forum and a forum container and verifies that they have been created.', 'group' => 'Forum');
- }
-
- function testAddForumContainer() {
- // Attempt to create a forum container
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- ));
- $this->drupalLoginUser($web_user);
-
- // Create the container, all the assertions are handled in the function
- $container = $this->createForumContainer();
-
- // Delete the forum container we created
- if (!empty($container))
- taxonomy_del_term($container['tid']);
- }
-
- function testAddForum() {
- // Attempt to create a forum
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- ));
- $this->drupalLoginUser($web_user);
-
- // Create the forum, all assertions are handled in the function
- $forum = $this->createForum();
-
- // Delete the forum we created
- if (!empty($forum))
- taxonomy_del_term($forum['tid']);
- }
-}
-
-class EditForumTaxonomyTest extends DrupalForumTestCase {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Edit forum taxonomy'), 'desc' => 'Edits the forum taxonomy.', 'group' => 'Forum');
- }
-
- function testEditForumTaxonomy() {
- // Attempt to edit the forum taxonomy
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer taxonomy',
- ));
- $this->drupalLoginUser($web_user);
-
- $vid = variable_get('forum_nav_vocabulary', '');
- $original_settings = taxonomy_vocabulary_load($vid);
-
- // Generate a random name/description
- $title = $this->randomName(10);
- $description = $this->randomName(100);
-
- $edit = array(
- 'name' => $title,
- 'description' => $description,
- 'help' => '',
- 'weight' => -10
- );
-
- // Double check that the page says it has edited the vocabulary
- $this->drupalPost('admin/content/taxonomy/edit/vocabulary/'. $vid, $edit, 'Save');
- $this->assertWantedRaw(t('Updated vocabulary %name.', array('%name' => $title)), t('Vocabulary has been edited'));
-
- // Grab the newly edited vocabulary
- $cur_settings = db_fetch_array(db_query('SELECT v.* FROM {vocabulary} v WHERE v.vid = %d', $vid));
-
- // Make sure we actually edited the vocabulary properly
- $this->assertTrue($cur_settings['name'] == $title, 'The name has been updated properly');
- $this->assertTrue($cur_settings['description'] == $description, 'The description has been updated properly');
-
- // Restore the original settings
- $original_settings = (array) $original_settings;
-
- taxonomy_save_vocabulary($original_settings);
- }
-}
-
-
-class AddTopicToForum extends DrupalForumTestCase {
- /**
- * Implementation of get_info() for information
- */
- function get_info() {
- return array('name' => t('Add/move topics'), 'desc' => 'Tests adding and moving topics within forums.', 'group' => 'Forum');
- }
-
- function testAddTopicToForum() {
- // Attempt to create a forum
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- 'create forum topics'
- ));
- $this->drupalLoginUser($web_user);
-
- // Generate a forum
- $forum = $this->createForum();
-
- // Now, we try to create the topic in the forum
- // Generate a random subject/body
- $title = $this->randomName(20);
- $description = $this->randomName(200);
-
- $edit = array(
- 'title' => $title,
- 'body' => $description
- );
-
- // Double check that the page says it has created the topic
- $this->drupalPost('node/add/forum/'. $forum['tid'], $edit, 'Save');
- $type = t('Forum topic');
- $this->assertWantedRaw(t('@type %term has been created.', array('%term' => $title, '@type' => $type)), t('New forum topic has been created'));
- $this->assertNoUnwantedRaw(t('The item %term is only a container for forums.', array('%term' => $forum['name'])), t('No error message shown'));
-
- // Then find the new topic, load it, and make sure the text we chose appears
- $new_topic = node_load(array('title' => $title), null, true);
- $this->drupalGet("node/$new_topic->nid");
-
- $this->assertWantedRaw($title, t('Looking for subject text'));
- $this->assertWantedRaw($description, t('Looking for body text'));
-
- // Delete the topic
- node_delete($new_topic->nid);
-
- // Delete the forum we created
- if (!empty($forum))
- taxonomy_del_term($forum['tid']);
- }
-
- function testAddTopicToContainer() {
- // Attempt to create a forum container
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- 'create forum topics'
- ));
- $this->drupalLoginUser($web_user);
-
- // Create the container
- $container = $this->createForumContainer();
-
- // Now, we try to create the topic in the forum
- // Generate a random subject/body
- $title = $this->randomName(20);
- $description = $this->randomName(200);
-
- $edit = array(
- 'title' => $title,
- 'body' => $description
- );
-
- // Double check that the page says it hasn't created the topic
- $this->drupalPost('node/add/forum/'. $container['tid'], $edit, 'Save');
- $type = t('Forum topic');
- $this->assertNoUnwantedRaw(t('@type %term has been created.', array('%term' => $title, '@type' => $type)), t('No "new forum has been created" message'));
- $this->assertWantedRaw(t('The item %term is only a container for forums.', array('%term' => $container['name'])), t('Error message shown'));
-
- // Then make sure the node does not exist
- $new_topic = node_load(array('title' => $title), null, true);
- $this->assertTrue(empty($new_topic), t('There is no new topic'));
-
- // Delete the forum container we created
- if (!empty($container))
- taxonomy_del_term($container['tid']);
- }
-
- function testMoveTopicToForum() {
- // Attempt to create a forum
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- 'create forum topics',
- 'edit any forum topic'
- ));
- $this->drupalLoginUser($web_user);
-
- $forum1 = $this->createForum();
- $forum2 = $this->createForum();
-
- // Now, we try to create the topic in the forum
- // Generate a random subject/body
- $title = $this->randomName(20);
- $description = $this->randomName(200);
-
- $edit = array(
- 'title' => $title,
- 'body' => $description
- );
-
- // Double check that the page says it has created the topic
- $this->drupalPost('node/add/forum/'. $forum1['tid'], $edit, 'Save');
- $type = t('Forum topic');
- $this->assertWantedRaw(t('@type %term has been created.', array('%term' => $title, '@type' => $type)), t('New forum topic has been created'));
- $this->assertNoUnwantedRaw(t('The item %term is only a container for forums.', array('%term' => $forum1['name'])), t('No error message shown'));
-
- // Then find the new topic and edit it to move it
- $new_topic = node_load(array('title' => $title), null, true);
- $vid = variable_get('forum_nav_vocabulary', '');
-
- $edit = array(
- 'title' => $title,
- 'taxonomy['. $vid .']' => $forum2['tid'],
- 'body' => $description
- );
-
- // Double check that the page says it has updated the topic
- // Also, double check that the new forum name is there and not the old
- $this->drupalPost('node/'. $new_topic->nid .'/edit', $edit, 'Save');
- $type = t('Forum topic');
- $this->assertWantedRaw(t('@type %term has been updated.', array('%term' => $title, '@type' => $type)), t('Topic has been moved'));
- $this->assertWantedRaw($forum2['name'], t('New forum name is present'));
- $this->assertNoUnwantedRaw($forum1['name'], t('Old forum name is not present'));
-
- // Delete the topic
- node_delete($new_topic->nid);
-
- // Delete the forums we created
- if (!empty($forum1))
- taxonomy_del_term($forum1['tid']);
- if (!empty($forum2))
- taxonomy_del_term($forum2['tid']);
- }
-
- function testMoveTopicWithCopyToForum() {
- // Attempt to create a forum
- $web_user = $this->drupalCreateUserRolePerm(array(
- 'access administration pages',
- 'administer forums',
- 'create forum topics',
- 'edit any forum topic'
- ));
- $this->drupalLoginUser($web_user);
-
- $forum1 = $this->createForum();
- $forum2 = $this->createForum();
-
- // Now, we try to create the topic in the forum
- // Generate a random subject/body
- $title = $this->randomName(20);
- $description = $this->randomName(200);
-
- $edit = array(
- 'title' => $title,
- 'body' => $description
- );
-
- // Double check that the page says it has created the topic
- $this->drupalPost('node/add/forum/'. $forum1['tid'], $edit, 'Save');
- $type = t('Forum topic');
- $this->assertWantedRaw(t('@type %term has been created.', array('%term' => $title, '@type' => $type)), t('New forum topic has been created'));
- $this->assertNoUnwantedRaw(t('The item %term is only a container for forums.', array('%term' => $forum1['name'])), t('No error message shown'));
-
- // Then find the new topic and edit it to move it
- $new_topic = node_load(array('title' => $title), null, true);
- $vid = variable_get('forum_nav_vocabulary', '');
-
- $edit = array(
- 'title' => $title,
- 'taxonomy['. $vid .']' => $forum2['tid'],
- 'body' => $description
- );
-
- // Double check that the page says it has updated the topic
- // Also, double check that the new forum name is there and not the old
- $this->drupalPost('node/'. $new_topic->nid .'/edit', $edit, 'Save');
- $type = t('Forum topic');
- $this->assertWantedRaw(t('@type %term has been updated.', array('%term' => $title, '@type' => $type)), t('Topic has been moved'));
- $this->assertWantedRaw($forum2['name'], t('New forum name is present'));
- $this->assertNoUnwantedRaw($forum1['name'], t('Old forum name is not present'));
-
- // Delete the topic
- node_delete($new_topic->nid);
-
- // Delete the forums we created
- if (!empty($forum1))
- taxonomy_del_term($forum1['tid']);
- if (!empty($forum2))
- taxonomy_del_term($forum2['tid']);
- }
-}
Index: tests/page_creation.test
===================================================================
RCS file: tests/page_creation.test
diff -N tests/page_creation.test
--- tests/page_creation.test 21 Feb 2008 08:16:22 -0000 1.19
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,35 +0,0 @@
- t('Page node creation'),
- 'desc' => t('Create a page node and verify its consistency in the database.'),
- 'group' => 'Node Tests',
- );
- }
-
- function testPageCreation() {
- /* Prepare settings */
- $this->drupalVariableSet('node_options_page', array('status', 'promote'));
-
- /* Prepare a user to do the stuff */
- $web_user = $this->drupalCreateUserRolePerm(array('edit own page content', 'create page content'));
- $this->drupalLoginUser($web_user);
-
- $edit = array();
- $edit['title'] = '!SimpleTest test node! ' . $this->randomName(10);
- $edit['body'] = '!SimpleTest test body! ' . $this->randomName(32) . ' ' . $this->randomName(32);
- $this->drupalPost('node/add/page', $edit, 'Save');
-
- $this->assertWantedRaw(t('!post %title has been created.', array ('!post' => 'Page', '%title' => $edit['title'])), 'Page created');
-
- $node = node_load(array('title' => $edit['title']));
- $this->assertNotNull($node, t('Node !title found in database.', array ('!title' => $edit['title'])));
-
- }
-}
Index: tests/page_view.test
===================================================================
RCS file: tests/page_view.test
diff -N tests/page_view.test
--- tests/page_view.test 28 Jan 2008 07:40:47 -0000 1.14
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,38 +0,0 @@
- t('Unauthorized node view'),
- 'desc' => t('Creates a node of type page and then an unpermissioned user attempts to edit the node, '
- . 'before tries with an anonymous user. Asserts failure.'
- . ' br>WARNING: This is based on default registered user permuissions (no administer nodes).')
- , 'group' => 'Node Tests',
- );
- }
-
- function testPageView() {
- /* Prepare a node to view */
- global $user;
- $node = $this->drupalCreateNode();
- $this->assertNotNull(node_load($node->nid), 'Node created');
-
- /* Tries to edit with anonymous user */
- $html = $this->drupalGet("node/$node->nid/edit");
- $this->assertResponse(403);
-
- /* Prepare a user to request the node view */
- $test_user = $this->drupalCreateUserRolePerm(array('access content'));
- $this->drupalLoginUser($test_user);
-
- $html = $this->drupalGet("node/$node->nid/edit");
- $this->assertResponse(403);
-
- $test_user = $this->drupalCreateUserRolePerm(array('administer nodes'));
- //TODO: Add edit page attempt with administer nodes user
- node_delete($node->nid);
- }
-}
Index: tests/profile_module.test
===================================================================
RCS file: tests/profile_module.test
diff -N tests/profile_module.test
--- tests/profile_module.test 28 Jan 2008 08:48:37 -0000 1.13
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,974 +0,0 @@
- 'Test Single field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access administration pages, administer site configuration, administer users';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in');
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $edit = array('category' => $my_category,
- 'title' => $title,
- 'name' => $form_name,
- 'explanation' => $explanation,
- );
- $this->drupalPost('admin/user/profile/add/textfield', $edit, 'Save field',0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
-
- // checking field
- $this->assertField($form_name , '');
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $edit[$form_name] = $this->randomName(20);
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($edit[$form_name], "Checking ". $edit[$form_name]);
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
- }
-
-}
-
-class ProfileModuleTestTextarea extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Textarea field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
- $this->drupalPost("admin/user/profile/add/textarea", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
-
- // checking field
- $this->assertField($form_name, '');
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $edit[$form_name] = $this->randomName(20);
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($edit[$form_name], "Checking ". $edit[$form_name]);
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
- }
-}
-
-
-class ProfileModuleTestFreelist extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Freelist field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
- $this->drupalPost("admin/user/profile/add/list", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
-
- // checking field
- $this->assertField($form_name, '');
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $edit[$form_name] = $this->randomName(20);
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($edit[$form_name], "Checking ". $edit[$form_name]);
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
- }
-
-}
-
-
-class ProfileModuleTestCheckbox extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Checkbox field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileCheckbox() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
- $this->drupalPost("admin/user/profile/add/checkbox", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
-
- // checking field
- $this->assertField($form_name, false);
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $edit[$form_name] = 1;
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
- // checking profile page
- $this->assertWantedText($title, "Checking checkbox");
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(10);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
- }
-}
-
-class ProfileModuleTestUrl extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Url field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalVariableSet('user_register',1);
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
- $this->drupalPost("admin/user/profile/add/url", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
-
- // checking field
- $this->assertField($form_name, '');
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $edit[$form_name] = 'http://www.' . $this->randomName(10). '.org';
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($edit[$form_name], "Checking ". $edit[$form_name]);
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
-
- }
-}
-
-class ProfileModuleTestSelection extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Selection field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- $options = "";
- for($i = 0; $i < 3; $i++)
- $options .= $this->randomName(8) . "\n";
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation, 'options' => $options);
- $this->drupalPost("admin/user/profile/add/selection", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
- // can we choose something which doesn't come from the list ?
- $this->assertFalse($this->setField('edit['.$form_name .']', $this->randomName(10)));
- // or can we choose each of our options
- $op_tab = explode("\n", $options,3);
- foreach($op_tab as $option)
- $this->assertTrue($this->setField($form_name, $option));
-
-
- // ok, now let put some data
- unset($edit);
- $edit = array();
- $checking = array();
- $element = rand(0,2);
- $key = $form_name;
- $edit[$key] = rtrim($op_tab[$element]);
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($edit[$form_name], "Checking ". $edit[$form_name]);
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
-
- }
-
-}
-
-
-class ProfileModuleTestDate extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test Date field', 'desc' => "Testing profile module with add/edit/delete new fields into profile page" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
- }
-
- function testProfileSingle() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in',0 );
-
- //wartosci
- $my_category = 'Simpletest';
- //single line textfield
- $title = "single_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- $explanation = $this->randomName(50);
- /* $options = "";
- for($i = 0; $i < 3; $i++)
- $options .= $this->randomName(8) . "\n";*/
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'explanation' => $explanation);
- $this->drupalPost("admin/user/profile/add/date", $edit, 'Save field' , 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $single_field = array('title' => $title, 'form_name' => $form_name, 'explanation' => $explanation);
-
- // checking simple fields
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
- // checking name
- $this->assertWantedText($title, "Checking title for ". $title);
- // checking explanation
- $this->assertWantedText($explanation, "Checking explanation for ". $title);
- // checking days/month/years
- foreach(array('year', 'month', 'day') as $field)
- $this->assertFalse($this->setField('edit['.$form_name .']['. $field .']', $this->randomName(4)), 'Checking data field ['.$field.']');
- // ok, now let put some data
- // date 9-01-1983
- unset($edit);
- foreach(array('year' => 1983, 'month' => 'Jan', 'day' => 9) as $field => $v) {
- $key = $form_name . '[' . $field . ']';
- $edit[$key] = $v;
- }
-
- list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y'), 2);
-
- $replace = array('d' => sprintf('%02d', 9),
- 'j' => 9,
- 'm' => sprintf('%02d', '1'),
- 'M' => map_month(1),
- 'Y' => 1983);
- $data = strtr($format, $replace);
- $this->drupalPost("user/". $user->uid. "/edit/$my_category", $edit, 'Save' , 0);
- $this->_browser->get(url("user/". $user->uid));
-
- // checking profile page
- $this->assertWantedText($data, "Checking date $data");
- $this->assertWantedText($title, "Checking $title");
- // update field
- $new_title = $this->randomName(20);
- $this->drupalPost("admin/user/profile/edit/$fid", array('title' => $new_title), 'Save field' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertWantedText($new_title, "Checking updated field");
- // deleting field
- $this->drupalPost("admin/user/profile/delete/$fid", array(), 'Delete' , 0);
- $this->_browser->get(url("admin/user/profile"));
- $this->assertNoUnwantedText($new_title, "Checking deleted field $title");
-
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =%d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
-
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
-
- }
-
-}
-
-
-class ProfileModuleTest2 extends DrupalTestCase {
- function get_info() {
- $modules = (module_list());
- return array('name' => 'Test other fields', 'desc' => "Testing weight, title page, required" , 'group' => 'Profile Module');
- }
-
- function _rolesApi($op, $edit) {
- if ($op == 'delete') {
- $id = $edit['rid'];
- db_query('DELETE FROM {role} WHERE rid = %d', $id);
- db_query('DELETE FROM {permission} WHERE rid = %d', $id);
-
- // Update the users who have this role set:
- $result = db_query('SELECT DISTINCT(ur1.uid) FROM {users_roles} ur1 LEFT JOIN {users_roles} ur2 ON ur2.uid = ur1.uid WHERE ur1.rid = %d AND ur2.rid != ur1.rid', $id);
- $uid = array();
-
- while ($u = db_fetch_object($result)) {
- $uid[] = $u->uid;
- }
-
- if ($uid) {
- db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN (%s)', $id, implode(', ', $uid));
- }
-
- // Users with only the deleted role are put back in the authenticated users pool.
- db_query('UPDATE {users_roles} SET rid = %d WHERE rid = %d', DRUPAL_AUTHENTICATED_RID, $id);
-
- }
- else if ($op == 'add') {
- if (isset($edit['name'])) {
- db_query("INSERT INTO {role} (name) VALUES ('%s')", $edit['name']);
- $result = db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
- $rid = db_result($result);
- db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $edit['perm']);
- return $rid;
- }
- else {
- return 0;
- }
- }
-
- }
-
- function testProfileOtherFields() {
- $this->drupalModuleEnable('profile');
- // create test user
- $edit['name'] = 'Profile '. $this->randomName(5);
- $edit['perm'] = 'access content, administer users, access user profiles, administer site configuration, access administration pages, access configuration pages, access user profiles';
- $rid = $this->_rolesApi('add', $edit );
- $name = $this->randomName();
- $pass = $this->randomName();
- $mail = "$name@example.com";
- unset($edit);
- $edit['roles'] = array($rid => $rid);
- $user = user_save('', array('name' => $name, 'pass' => $pass, 'init' => $mail, 'mail' => $mail, 'roles' => $edit['roles'], 'status' => 1));
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in', 0);
- //wartosci
- $my_category = $this->randomName(10);
- //single line textfield
- $title = "first_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- // weight
- $weight = 3;
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'required' => 1);
- $this->drupalPost("admin/user/profile/add/textfield", $edit, 'Save field', 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $sfield1 = array('fid'=> $fid, 'title' => $title);
- //second one line textfield
- $title = "second_" . $this->randomName(10);
- $form_name = 'profile_' . $title;
- // weight
- $weight = -2;
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'weight' => $weight, 'register' => 1, 'required' => 1);
- $this->drupalPost("admin/user/profile/add/textfield", $edit, 'Save field', 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $sfield2 = array('fid'=> $fid, 'title' => $title);
- // checking
- $this->_browser->get(url("user/". $user->uid. "/edit/$my_category"));
- $content = $this->_browser->getContent();
- $pos1 = strpos($content, $sfield1['title']);
- $pos2 = strpos($content, $sfield2['title']);
- $this->assertTrue($pos2 < $pos1, 'Checking weight field');
- $delete_fields = array();
- $delete_fields[] = $sfield1['fid'];
- $delete_fields[] = $sfield2['fid'];
- // check if this field is visible in registration form
- // logout
- $this->_browser->get(url("logout"));
- $this->_browser->get(url("user/register"));
- $this->assertNoUnwantedText($sfield1['title'], 'Field is not visible in registration form');
- $this->assertWantedText($sfield2['title'], 'Field is visible in registration form');
- // try to register
- $fname = $this->randomName(5, 'simpletest_');
- $fmail = "$fname@drupaltest.example.com";
- $edit = array('name' => $fname,
- 'mail' => $fmail);
- $this->drupalPost('user/register', $edit, 'Create new account', 0);
- //$key = t('The field %field is required.', array('%field' => $title));
- //$this->assertWantedText($key, 'Checking error message');
- //log in
- $edit = array('name' => $name, 'pass' => $pass);
- $this->drupalPost('user', $edit, 'Log in', 0);
- // TITLE
- //selection
- $title = $this->randomName(10);
- $form_name = 'profile_' . $title;
- $page_title = $this->randomName(5) . " %value";
- $options = "";
- for($i = 0; $i < 3; $i++)
- $options .= $this->randomName(8) . "\n";
- $edit = array('category' => $my_category, 'title' => $title, 'name' => $form_name, 'page' => $page_title, 'options' => $options);
- $this->drupalPost("admin/user/profile/add/selection", $edit, 'Save field', 0);
- $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE title = "%s"', $title));
- $element = rand(0,2);
- $op_tab = explode("\n", $options,3);
- $choice = rtrim($op_tab[$element]);
- // checking
- $this->_browser->get(url("profile/". $form_name. "/$choice"));
- $title = str_replace("%value", $choice, $page_title);
-
- $this->assertTitle($title. ' | '. variable_get('site_name', 'Drupal'), "Checking title $title");
- $this->assertWantedText($title, "Checking $title in content");
- $delete_fields[] = $fid;
-
- foreach($delete_fields as $delfid) {
- $this->drupalPost("admin/user/profile/delete/".$delfid, array(), 'Delete', 0 );
- }
- // delete test user and roles
- if ($user->uid > 0) {
- db_query('DELETE FROM {users} WHERE uid =' .
- ' %d', $user->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $user->uid);
- module_invoke_all('user', 'delete', '', $user);
- }
- //delete roles
- $edit['rid'] = $rid;
- $this->_rolesApi('delete', $edit);
-
- }
-}
-
-?>
Index: tests/comment_module.test
===================================================================
RCS file: tests/comment_module.test
diff -N tests/comment_module.test
--- tests/comment_module.test 7 Mar 2008 18:20:12 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,375 +0,0 @@
- t('Comment functionality'),
- 'desc' => t('Thoroughly test comment administration and user interfaces.'),
- 'group' => t('Comment Tests'),
- );
- }
-
- function setUp() {
- parent::setUp();
-
- $this->drupalModuleEnable('comment');
-
- // Create users.
- $this->admin_user = $this->drupalCreateUserRolePerm(array('administer content types', 'administer comments', 'administer permissions'));
- $this->web_user = $this->drupalCreateUserRolePerm(array('access comments', 'post comments', 'create story content'));
-
- $this->drupalLoginUser($this->web_user);
- $this->node = $this->drupalCreateNode(array('type' => 'story'));
- $this->assertTrue($this->node, 'Story node created.');
- $this->drupalGet('logout');
- }
-
- /**
- * Test comment interface.
- */
-// function testCommentInterface() {
-// // Set comments to not have subject.
-// $this->drupalLoginUser($this->admin_user);
-// $this->set_comment_preview(TRUE);
-// $this->set_comment_subject(FALSE);
-// $this->drupalGet('logout');
-//
-// // Post comment without subject
-// $this->drupalLoginUser($this->web_user);
-// $this->drupalGet('comment/reply/'. $this->node->nid);
-// $this->assertNoPattern('/(input)(.*?)(name="subject")/', 'Subject field not found.');
-//
-// // Set comments to have subject and preview to required.
-// $this->drupalGet('logout');
-// $this->drupalLoginUser($this->admin_user);
-// $this->set_comment_subject(true);
-// $this->set_comment_preview(true);
-// $this->drupalGet('logout');
-//
-// // Create comment that requires preview.
-// $this->drupalLoginUser($this->web_user);
-// $comment = $this->post_comment($this->node, $this->randomName(), $this->randomName());
-// $this->assertTrue($this->comment_exists($comment), 'Comment found.');
-//
-// // Reply to comment.
-// $this->drupalGet('comment/reply/'. $this->node->nid .'/'. $comment->id);
-// $reply = $this->post_comment(NULL, $this->randomName(), $this->randomName());
-// $this->assertTrue($this->comment_exists($reply, TRUE), 'Reply found.');
-//
-// // Edit reply.
-// $this->drupalGet('comment/edit/'. $reply->id);
-// $reply = $this->post_comment(NULL, $this->randomName(), $this->randomName());
-// $this->assertTrue($this->comment_exists($reply, TRUE), 'Modified reply found.');
-//
-// // Delete comment and make sure that reply is also removed.
-// $this->drupalGet('logout');
-// $this->drupalLoginUser($this->admin_user);
-// $this->delete_comment($comment);
-//
-// $this->drupalGet('node/'. $this->node->nid);
-// $this->assertFalse($this->comment_exists($comment), 'Comment not found.');
-// $this->assertFalse($this->comment_exists($reply, TRUE), 'Reply not found.');
-// }
-
- /**
- * Test comment form on node page.
- */
- function testFormOnPage() {
- // Enabled comment form on node page.
- $this->drupalLoginUser($this->admin_user);
- $this->set_comment_form(TRUE);
- $this->drupalGet('logout');
-
- // Submit comment through node form.
- $this->drupalLoginUser($this->web_user);
- $this->drupalGet('node/'. $this->node->nid);
- $form_comment = $this->post_comment(NULL, $this->randomName(), $this->randomName());
- $this->assertTrue($this->comment_exists($form_comment), 'Form comment found.');
-
- // Disable comment form on node page.
- $this->drupalGet('logout');
- $this->drupalLoginUser($this->admin_user);
- $this->set_comment_form(FALSE);
- }
-
- /**
- * Test anonymous comment functionality.
- */
- function testAnonymous() {
- $this->drupalLoginUser($this->admin_user);
- // Enabled anonymous user comments.
- $this->set_anonymous_user_comment(TRUE, TRUE);
- $this->set_comment_anonymous('0'); // Ensure that doesn't require contact info.
- $this->drupalGet('logout');
-
- // Post anonymous comment without contact info.
- $anonymous_comment1 = $this->post_comment($this->node, $this->randomName(), $this->randomName());
- $this->assertTrue($this->comment_exists($anonymous_comment1), 'Anonymous comment without contact info found.');
-
- // Allow contact info.
- $this->drupalLoginUser($this->admin_user);
- $this->set_comment_anonymous('1');
- $this->drupalGet('logout');
-
- // Post anonymous comment with contact info (optional).
- $this->drupalGet('comment/reply/'. $this->node->nid);
- $this->assertTrue($this->comment_contact_info_available(), 'Contact information available.');
-
- $anonymous_comment2 = $this->post_comment($this->node, $this->randomName(), $this->randomName());
- $this->assertTrue($this->comment_exists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.');
-
- // Require contact info.
- $this->drupalLoginUser($this->admin_user);
- $this->set_comment_anonymous('2');
- $this->drupalGet('logout');
-
- // Try to post comment with contact info (required).
- $this->drupalGet('comment/reply/'. $this->node->nid);
- $this->assertTrue($this->comment_contact_info_available(), 'Contact information available.');
-
- $anonymous_comment3 = $this->post_comment($this->node, $this->randomName(), $this->randomName(), TRUE, TRUE);
- $this->assertText(t('E-mail field is required.'), 'E-mail required.'); // Name should have 'Anonymous' for value by default.
- $this->assertFalse($this->comment_exists($anonymous_comment3), 'Anonymous comment with contact info (required) not found.');
-
- // Post comment with contact info (required).
- $anonymous_comment3 = $this->post_comment($this->node, $this->randomName(), $this->randomName(), TRUE, array('mail' => 'tester@simpletest.org'));
- $this->assertTrue($this->comment_exists($anonymous_comment3), 'Anonymous comment with contact info (required) found.');
-
- // Unpublish comment.
- $this->drupalLoginUser($this->admin_user);
- $this->perform_comment_operation($anonymous_comment3, 'unpublish');
-
- $this->drupalGet('admin/content/comment/approval');
- $this->assertWantedRaw('comments['. $anonymous_comment3->id .']', 'Comment was unpublished.');
-
- // Publish comment.
- $this->perform_comment_operation($anonymous_comment3, 'publish', TRUE);
-
- $this->drupalGet('admin/content/comment');
- $this->assertWantedRaw('comments['. $anonymous_comment3->id .']', 'Comment was published.');
-
- // Delete comment.
- $this->perform_comment_operation($anonymous_comment3, 'delete');
-
- $this->drupalGet('admin/content/comment');
- $this->assertNoUnwantedRaw('comments['. $anonymous_comment3->id .']', 'Comment was deleted.');
-
- // Set anonymouse comments to require approval.
- $this->set_anonymous_user_comment(TRUE, FALSE);
- $this->set_comment_anonymous('0'); // Ensure that doesn't require contact info.
- $this->drupalGet('logout');
-
- // Post anonymous comment without contact info.
- $subject = $this->randomName();
- $body = $this->randomName();
- $this->post_comment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
- $this->assertText(t('Your comment has been queued for moderation by site administrators and will be published after approval.'), 'Comment requires approval.');
-
- // Get unaproved comment id.
- $this->drupalLoginUser($this->admin_user);
- $anonymous_comment4 = $this->get_unaproved_comment($subject);
- $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
- $this->drupalGet('logout');
-
- $this->assertFalse($this->comment_exists($anonymous_comment4), 'Anonymous comment was not published.');
-
- // Approve comment.
- $this->drupalLoginUser($this->admin_user);
- $this->perform_comment_operation($anonymous_comment4, 'publish', TRUE);
- $this->drupalGet('logout');
-
- $this->drupalGet('node/'. $this->node->nid);
- $this->assertTrue($this->comment_exists($anonymous_comment4), 'Anonymous comment visible.');
-
- // Reset.
- $this->drupalLoginUser($this->admin_user);
- $this->set_anonymous_user_comment(FALSE, FALSE);
- }
-
- /**
- * Post comment.
- *
- * @param object $node Node to post comment on.
- * @param string $subject Comment subject.
- * @param string $comment Comment body.
- * @param boolean $preview Should preview be required.
- * @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
- */
- function post_comment($node, $subject, $comment, $preview = TRUE, $contact = NULL) {
- $edit = array();
- $edit['subject'] = $subject;
- $edit['comment'] = $comment;
- if ($contact !== NULL && is_array($contact)) {
- $edit += $contact;
- }
-
- if ($node !== NULL) {
- $this->drupalGet('comment/reply/'. $node->nid);
- }
- if ($preview) {
- $this->assertFieldById('edit-comment');
- $this->assertNoPattern('/(input)(.*?)(value="Save")/', 'Save button not found.'); // Preview required so no save button should be found.
- $this->drupalPost(NULL, $edit, 'Preview');
- }
- $this->drupalPost(NULL, array(), 'Save');
-
- $match = array();
- // Get comment ID
- preg_match('/#comment-([^"]+)/', $this->_browser->getURL(), $match);
-
- // get comment
- if ($contact !== TRUE) { // If true then attempting to find error message.
- $this->assertText($subject, 'Comment posted.');
- $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.');
- }
- if (isset($match[1])) {
- return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
- }
- else {
- return NULL;
- }
- }
-
- /**
- * Checks current pag for specified comment.
- *
- * @param object $comment Comment object.
- * @param boolean $reply The comment is a reply to another comment.
- * @return boolean Comment found.
- */
- function comment_exists($comment, $reply = FALSE) {
- if ($comment && is_object($comment)) {
- $regex = '/'. ($reply ? '(.*?)' : '');
- $regex .= '