### 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.' - . '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 .= 'subject .'(.*?)'; // Match subject. - $regex .= $comment->comment .'(.*?)'; // Match comment. - $regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div. - return preg_match($regex, $this->drupalGetContent()); - } - else { - return FALSE; - } - } - - /** - * Delete comment. - * - * @param object $comment Comment to delete. - */ - function delete_comment($comment) { - $this->drupalPost('comment/delete/'. $comment->id, array(), 'Delete'); - $this->assertWantedText(t('The comment and all its replies have been deleted.'), 'Comment deleted.'); - } - - /** - * Set comment subject setting. - * - * @param boolean $enabled Subject value. - */ - function set_comment_subject($enabled) { - $this->set_comment_settings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject '. ($enabled ? 'enabled' : 'disabled') .'.'); - } - - /** - * Set comment preview setting. - * - * @param boolean $required Preview value. - */ - function set_comment_preview($required) { - $this->set_comment_settings('comment_preview', ($required ? '1' : '0'), 'Comment preview '. ($required ? 'required' : 'optional') .'.'); - } - - /** - * Set comment form setting. - * - * @param boolean $enabled Form value. - */ - function set_comment_form($enabled) { - $this->set_comment_settings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls '. ($enabled ? 'enabled' : 'disabled') .'.'); - } - - /** - * Set comment anonymous level setting. - * - * @param integer $level Anonymous level. - */ - function set_comment_anonymous($level) { - $this->set_comment_settings('comment_anonymous', $level, 'Anonymous commenting set to level '. $level .'.'); - } - - /** - * Set comment setting for story content type. - * - * @param string $name Name of variable. - * @param string $vale Value of variable. - * @param string $message Status message to display. - */ - function set_comment_settings($name, $value, $message) { - $this->drupalVariableSet($name .'_story', $value); - $this->assertTrue(TRUE, $message); // Display status message. - } - - /** - * Set anonymous comment setting. - * - * @param boolean $enabled Allow anonymous commenting. - * @param boolean $without_approval Allow anonymous commenting without approval. - */ - function set_anonymous_user_comment($enabled, $without_approval) { - $edit = array(); - $edit['1-access-comments'] = $enabled; - $edit['1-post-comments'] = $enabled; - $edit['1-post-comments-without-approval'] = $without_approval; - $this->drupalPost('admin/user/permissions', $edit, 'Save permissions'); - $this->assertText(t('The changes have been saved.'), 'Anonymous user comments '. ($enabled ? 'enabled' : 'disabled') .'.'); - } - - /** - * Check for contact info. - * - * @return boolean Contact info is avialable. - */ - function comment_contact_info_available() { - return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent()); - } - - /** - * Perform the specified operation on the specified comment. - * - * @param object $comment Comment to perform operation on. - * @param string $operation Operation to perform. - * @param boolean $aproval Operation is found on approval page. - */ - function perform_comment_operation($comment, $operation, $approval = FALSE) { - $edit = array(); - $edit['operation'] = $operation; - $edit['comments['. $comment->id .']'] = TRUE; - $this->drupalPost('admin/content/comment'. ($approval ? '/approval' : ''), $edit, 'Update'); - - if ($operation == 'delete') { - $this->drupalPost(NULL, array(), 'Delete comments'); - $this->assertText(t('The comments have been deleted.'), 'Operation "'. $operation .'" was performed on comment.'); - } - else { - $this->assertText(t('The update has been performed.'), 'Operation "'. $operation .'" was performed on comment.'); - } - } - - /** - * Get the comment id for an unaproved comment. - * - * @param string $subject Comment subject to find. - * @return integer Comment id. - */ - function get_unaproved_comment($subject) { - $this->drupalGet('admin/content/comment/approval'); - preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>('. $subject .')/', $this->drupalGetContent(), $match); - return $match[2]; - } -} Index: tests/node_revisions.test =================================================================== RCS file: tests/node_revisions.test diff -N tests/node_revisions.test --- tests/node_revisions.test 28 Jan 2008 08:48:37 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,110 +0,0 @@ - t('Node revisions tests'), - 'desc' => t('Creates a node of type page and then a user tries various revision actions such as viewing, reverting to, and deleting revisions.'), - 'group' => 'Node Tests', - ); - } - - /** - * Setup function used by tests. Creates a node with three revisions. - * - * If $log is TRUE, then a log message will be recorded. - */ - function prepareRevisions($log = FALSE) { - - $returnarray = array(); - $numtimes = 3; // First, middle, last. - for ($i = 0; $i < $numtimes; $i++) { - $settings = array('revision' => 1); - if ($log && $i == 1) { - $logmessage = $this->randomName(32); - $settings['log'] = $logmessage; - $returnarray['log'] = $logmessage; - } - if ($i != 0) { - $settings['nid'] = $node->nid; - } - $node = $this->drupalCreateNode($settings); - if ($i == 1) { - $returnarray['text'] = $node->body; - $returnarray['vid'] = $node->vid; - } - // Avoid confusion on the revisions overview page which is sorted by r.timestamp. - sleep(1); - } - $returnarray['node'] = $node; - return $returnarray; - } - - /** - * Simpletest test. Tests to make sure the correct revision text appears on "view revisions" page. - */ - function testNodeRevisions() { - extract( $this->prepareRevisions() ); - - $test_user = $this->drupalCreateUserRolePerm(array('view revisions')); - $this->drupalLoginUser($test_user); - $this->drupalGet("node/$node->nid/revisions/$vid/view"); - $this->assertText($text, 'Check to make sure correct revision text appears on "view revisions" page.'); - - $this->cleanup($node->nid); - } - - /** - * Simpletest test. Tests to make sure the correct log message appears on "revisions overview" page. - */ - function testLogMessage() { - extract( $this->prepareRevisions(TRUE) ); - - $test_user = $this->drupalCreateUserRolePerm(array('view revisions')); - $this->drupalLoginUser($test_user); - $this->drupalGet("node/$node->nid/revisions"); - $this->assertText($log, 'Check to make sure log message is properly displayed.'); - - $this->cleanup($node->nid); - } - - /** - * Simpletest test. Tests to make sure the that revisions revert properly. - */ - function testRevisionRevert() { - extract( $this->prepareRevisions() ); - - $test_user = $this->drupalCreateUserRolePerm(array('revert revisions', 'edit any page content')); - $this->drupalLoginUser($test_user); - $this->drupalPost("node/$node->nid/revisions/$vid/revert", array(), 'Revert'); - $newnode = node_load($node->nid); - $this->assertTrue(($text == $newnode->body), 'Check to make sure reversions occur properly'); - - $this->cleanup($node->nid); - } - - /** - * Simpletest test. Tests to make sure the revision deletes properly. - */ - function testRevisionDelete() { - extract( $this->prepareRevisions() ); - - $test_user = $this->drupalCreateUserRolePerm(array('delete revisions', 'delete any page content')); - $this->drupalLoginUser($test_user); - $this->drupalPost("node/$node->nid/revisions/$vid/delete", array(), 'Delete'); - $this->assertTrue(db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d and VID = %d', $node->nid, $vid)) == 0, 'Check to make sure revisions delete properly'); $this->cleanup($node->nid); - - $this->cleanup($node->nid); - } - - /** - * Cleanup function used by tests. Deletes the associated node. - */ - function cleanup($nid) { - node_delete($nid); - } -} - Index: tests/taxonomy.module.test =================================================================== RCS file: tests/taxonomy.module.test diff -N tests/taxonomy.module.test --- tests/taxonomy.module.test 28 Jan 2008 08:48:37 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,384 +0,0 @@ - 'Vocabulary functions', 'desc' => "Create/Edit/Delete a vocabulary and assert that all fields were properly saved" , 'group' => 'Taxonomy'); - } - - function testVocabularyFunctions() { - //preparing data - $vid = 0; - $name = $this->randomName(200); - $description = $this->randomName(200); - $help = $this->randomName(200); - $hierarchy = rand(0,2); // Hierarchy 0,1,2 - $multiple = rand(0,1); // multiple 0,1 - $required = rand(0,1); // required 0,1 - $relations = rand(0,1); - $tags = rand(0,1); - $weight = rand(-9,9); - $module = 'taxonomy'; - $nodesList = array_keys(node_get_types()); - $maxNodes = rand(1, count($nodesList)); - $nodes = array(); - for($i = 0; $i < $maxNodes; $i++) { - $nodes[$nodesList[$i]] = $nodesList[$i]; - $nodesBak[$nodesList[$i]] = $nodesList[$i]; - } - $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', - 'required', 'tags', 'module', 'weight', 'nodes'); - $edit = array(); - foreach($_t as $key ) - $edit[$key] = $$key; - - // exec save function - taxonomy_save_vocabulary($edit); - //after save we use $nodesBak - ksort($nodesBak); - $edit['nodes'] = $nodesBak; - $vocabularies = taxonomy_get_vocabularies(); - foreach($vocabularies as $voc) { - if ($voc->name == $name) { - $vid = $voc->vid; - break; - } - } - $edit['vid'] = $vid; - // get data using function - $getEdit = taxonomy_vocabulary_load($vid); - foreach($getEdit as $key => $value ) { - $this->assertEqual($value, $edit[$key],"Checking value of $key"); - } - - // delete vocabulary - // to avoid exception messages we create array with empty fields - $deleteArray = array(); - foreach($getEdit as $key => $v) - $deleteArray[$key] = 0; - $deleteArray['vid'] = $vid; - taxonomy_save_vocabulary($deleteArray); - // checking if we deleted voc. - $vocabularies = taxonomy_get_vocabularies(); - $vid = 0; - foreach($vocabularies as $voc) { - if ($voc->name == $name) { - $vid = $voc->vid; - break; - } - } - $this->assertEqual($vid, 0, "Deleted vocabulary ($vid)"); - - } -} - - -class TaxonomyTermFunctions extends DrupalTestCase { - function get_info() { - return array('name' => 'Term functions', 'desc' => "Testing save/update/delete terms" , 'group' => 'Taxonomy'); - } - - function testTermsFunctions() { - //preparing data - // vocabulary, hierarchy -> disabled, related terms = on; - $edit = array(); - $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', - 'required', 'tags', 'module', 'weight', 'nodes'); - foreach($_t as $key ) { - $edit[$key] = 0; - } - $name = $this->randomName(20); - $relation = 1; - $edit['name'] = $name; - taxonomy_save_vocabulary($edit); - - // create term - $termname = $this->randomName(20); - $termdesc = $this->randomName(200); - $termweight = rand(-9, 9); - $randSyn = rand(0, 9); - $synonyms = array(); - for($i = 0; $i < $randSyn; $i++) { - $synonyms[] = $this->randomName(20); - } - $termsyn = implode("\n", $synonyms); - $data = array('name' => $termname, 'description' => $termdesc, 'weight' => $termweight, 'synonyms' => $termsyn, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - - // retrieve term and check all fields - $_tArray = taxonomy_get_term_by_name($termname); - $getTerm = $_tArray[0]; - $checkField = array('name', 'description', 'weight', 'vid'); - foreach($checkField as $v) { - $this->assertEqual($data[$v], $getTerm->$v, "Checking value of the term ($v)"); - } - $getSynonyms = taxonomy_get_synonyms($getTerm->tid); - $this->assertEqual(sort($synonyms), sort($getSynonyms), 'Checking synonyms'); - - // creating related terms - $relations = array(); - $staryTid = $getTerm->tid; - $relations[] = $staryTid; - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => 0, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => array($staryTid)); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $getTerm = $_tArray[0]; - $relations[] = $getTerm->tid; - - // Creating another term related to 2 terms above; - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => 0, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => array($staryTid, $getTerm->tid)); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $getTerm = $_tArray[0]; - - // check related terms - $related = taxonomy_get_related($getTerm->tid); - foreach($relations as $rTid) { - $this->assertTrue(array_key_exists($rTid, $related), "Checking relations ($rTid)"); - } - - // delete vocabulary - $edit['name'] = 0; - taxonomy_save_vocabulary($edit); - } - - function testTermsFunctionsSingleHierarchy() { - //preparing data - // vocabulary hierarchy->single - $edit = array(); - $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', - 'required', 'tags', 'module', 'weight', 'nodes'); - foreach($_t as $key ) { - $edit[$key] = 0; - } - - // create vocab - $name = $this->randomName(20); - $edit['hierarchy'] = 1; - $edit['name'] = $name; - taxonomy_save_vocabulary($edit); - - // create 1st term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent = $_tArray[0]; - - // create 2nd term as a child - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0, 'parent' => array($parent->tid)); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $children = $_tArray[0]; - - // check hierarchy - $getChildren = taxonomy_get_children($parent->tid); - $getParent = taxonomy_get_parents($children->tid); - $this->assertEqual($parent,$getParent[$parent->tid], 'Checking parents'); - $this->assertEqual($children,$getChildren[$children->tid], 'Checking children'); - - // delete vocabulary - $edit['name'] = 0; - taxonomy_save_vocabulary($edit); - } - - function testTermsFunctionsMultipleHierarchy() { - //preparing data - // vocabulary hierarchy->single - $edit = array(); - $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', - 'required', 'tags', 'module', 'weight', 'nodes'); - foreach($_t as $key ) - $edit[$key] = 0; - - $name = $this->randomName(20); - $edit['hierarchy'] = 1; - $edit['name'] = $name; - taxonomy_save_vocabulary($edit); - - // create 1st term - $parent = array(); - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[] = $_tArray[0]->tid; - - // create 2nd term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[] = $_tArray[0]->tid; - - // create 3rd term as a child - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0, 'parent' => array($parent)); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $children = $_tArray[0]; - - $getParent = taxonomy_get_parents($children->tid); - foreach($parent as $p) { - $this->assertTrue(array_key_exists($p, $getParent), "Checking parents ($p)"); - //$this->assertEqual($parent,$getParent[$parent->tid], 'Checking parents'); - } - - // delete vocabulary - $edit['name'] = 0; - taxonomy_save_vocabulary($edit); - } - -} - -class TaxonomyTestNodeApi extends DrupalTestCase { - function get_info() { - return array('name' => 'Taxonomy nodeapi', 'desc' => "Save & edit a node and assert that taxonomy terms are saved/loaded properly." , 'group' => 'Taxonomy'); - } - - function testTaxonomyNode() { - - //preparing data - // vocabulary hierarchy->single, multiple -> on - $edit = array(); - $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', - 'required', 'tags', 'module', 'weight', 'nodes'); - foreach($_t as $key) { - $edit[$key] = 0; - } - - $name = $this->randomName(20); - $edit['hierarchy'] = 1; - $edit['multiple'] = 1; - $edit['name'] = $name; - $edit['nodes'] = array('story' => 'story'); - taxonomy_save_vocabulary($edit); - $vid = $edit['vid']; // we need to persist vid after $edit is unset() - - $parent = array(); - $patternArray = array(); - - // create 1st term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[$_tArray[0]->tid] = $_tArray[0]->tid; - $patternArray['term name 1'] = $termname; - - // create 2nd term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[$_tArray[0]->tid] = $_tArray[0]->tid; - $patternArray['term name 2'] = $termname; - - // create test user and login - $perm = array('access content', 'create story content', 'edit own story content', 'delete own story content'); - $account = $this->drupalCreateUserRolePerm($perm); - $this->drupalLoginUser($account); - - // why is this printing out the user profile page? - // go to node/add/story - $this->drupalGet('node/add/story'); - $req = $this->_browser->getRequest(); - - $headers = $this->_browser->getHeaders(); - - $content = $this->drupalGetContent(); -// print($content). "\n\n\n all done \n\n"; - - // try to create story - $title = $this->randomName(); - $body = $this->randomName(100); - $edit = array('title' => $title, 'body' => $body, 'taxonomy-' . $vid => $parent); - - // multiple slect box was failing through drupalPost. Use raw POST instead - // Failing because they were being sent/handled wrong (earnest.berry@gmail.com ) - $action = url('node/add/story', array('absolute' => TRUE)); - $this->drupalPost($action, $edit, 'Save'); - $content = $this->drupalGetContent(); - $patternArray['body text'] = $body; - $patternArray['title'] = $title; - -// $node = array2object(node_load(array('title' => $title))); - $node = node_load(array('title' => $title)); - - $this->_browser->get(url("node/$node->nid")); - foreach($patternArray as $name => $termPattern) { - $this->assertText($termPattern, "Checking $name"); - } - - // checking database fields - $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $node->nid); - while ($nodeRow = db_fetch_array($result)) { - $this->assertTrue(in_array($nodeRow['tid'], $parent), 'Checking database record'); - } - - // ok, lets create new terms, and change this node - //pop array - array_pop($parent); - - // create 1st term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[] = $_tArray[0]->tid; - $patternArray['term name 2'] = $termname; - - // create 2nd term - $termname = $this->randomName(20); - $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); - taxonomy_save_term($data); - $_tArray = taxonomy_get_term_by_name($termname); - $parent[] = $_tArray[0]->tid; - $patternArray['term name 3'] = $termname; - - $edit = array('title' => $title, 'body' => $body, 'taxonomy-' . $vid => $parent); - - $this->drupalPost('node/'. $node->nid .'/edit', $edit, 'Save'); - - // TODO Do a MUCH better check here of the information msg - $patternArray['information message'] = 'been updated'; - foreach($patternArray as $name => $termPattern) { - $this->assertText($termPattern, "Checking $name"); - } - - // checking database fields - $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $node->nid); - while ($nodeRow = db_fetch_array($result)) { - $this->assertTrue(in_array($nodeRow['tid'], $parent), 'Checking database field'); - } - - // delete node through browser - $this->drupalPost('node/'. $node->nid .'/delete', array(), 'Delete' ); - // checking after delete - $this->_browser->get(url("node/".$node->nid)); - $this->assertNoUnwantedText($termname, "Checking if node exists"); - // checking database fields - $num_rows = db_result(db_query('SELECT COUNT(*) FROM {term_node} WHERE nid = %d', $node->nid)); - $this->assertEqual($num_rows, 0, 'Checking database field after deletion'); - - // delete vocabulary - // to avoid exception messages create array with empty fields - $edit = array(); - foreach($_t as $key ) { - $edit[$key] = 0; - } - $edit['name'] = 0; - $edit['vid'] = $vid; - taxonomy_save_vocabulary($edit); - - // restoring status - $this->drupalModuleDisable('story'); - } - -} - - -?> Index: tests/locale_module.test =================================================================== RCS file: tests/locale_module.test diff -N tests/locale_module.test --- tests/locale_module.test 28 Jan 2008 08:48:37 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,117 +0,0 @@ - t('String translate'), - 'desc' => 'Adds a new locale and translates its name', - 'group' => 'Locale', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('locale'); - } - - function testlocaleModuleTest() { - global $base_url; - - // User to add and remove language. - $admin_user = $this->drupalCreateUserRolePerm(array('administer languages', 'access administration pages')); - // User to translate and delete string. - $translate_user = $this->drupalCreateUserRolePerm(array('translate interface', 'access administration pages')); - // Code for the language. - $langcode = str_replace('simpletest_', 'si-', $this->randomName(6)); - // The English name for the language. This will be translated. - $name = $this->randomName(16); - // The native name for the language. - $native = $this->randomName(16); - // The domain prefix. Not tested yet. - $prefix = strtolower(str_replace('si-', '', $langcode)); - // This is the language indicator on the translation search screen for - // untranslated strings. Copied straight from locale.inc. - $language_indicator = "$langcode "; - // This will be the translation of $name. - $translation = $this->randomName(16); - - // Add language. - $this->drupalLoginUser($admin_user); - $edit = array ( - 'langcode' => $langcode, - 'name' => $name, - 'native' => $native, - 'prefix' => $prefix, - 'direction' => '0', - ); - $this->drupalPost('admin/settings/language/add', $edit, 'Add custom language'); - // Add string. - t($name, array(), $langcode); - // Reset locale cache. - locale(NULL, NULL, TRUE); - $this->assertText($langcode, 'Language code found'); - $this->assertText($name, 'Name found'); - $this->assertText($native, 'Native found'); - // No t() here, we do not want to add this string to the database and it's - // surely not translated yet. - $this->assertText($native, 'Test language added'); - $this->drupalGet('logout'); - - // Search for the name and translate it. - $this->drupalLoginUser($translate_user); - $search = array ( - 'string' => $name, - 'language' => 'all', - 'translation' => 'all', - 'group' => 'all', - ); - $this->drupalPost('admin/build/translate/search', $search, 'Search'); - // assertText seems to remove the input field where $name always could be - // found, so this is not a false assert. See how assertNoText succeeds - // later. - $this->assertText($name, 'Search found the name'); - $this->assertWantedRaw($language_indicator, 'Name is untranslated'); - // It's presumed that this is the only result. Given the random name, it's - // reasonable. - $this->clickLink('edit'); - // We save the lid from the path. - $lid = preg_replace('/\D/', '', substr($this->getUrl(), strlen($base_url))); - // No t() here, it's surely not translated yet. - $this->assertText($name, 'name found on edit screen'); - $edit = array ( - "translations[$langcode]" => $translation, - ); - $this->drupalPost(NULL, $edit, 'Save translations'); - $this->assertText(t('The string has been saved.'), 'The string has been saved.'); - $this->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, 't() works'); - $this->drupalPost('admin/build/translate/search', $search, 'Search'); - // The indicator should not be here. - $this->assertNoUnwantedRaw($language_indicator, 'String is translated'); - $this->drupalGet('logout'); - - // Delete the language - $this->drupalLoginUser($admin_user); - $path = 'admin/settings/language/delete/'. $langcode; - // This a confirm form, we do not need any fields changed. - $this->drupalPost($path, array(), 'Delete'); - // We need raw here because %locale will add HTML. - $this->assertWantedRaw(t('The language %locale has been removed.', array('%locale' => $name)), 'The test language has been removed.'); - // Reload to remove $name. - $this->drupalGet($path); - $this->assertNoText($langcode, 'Language code not found'); - $this->assertNoText($name, 'Name not found'); - $this->assertNoText($native, 'Native not found'); - $this->drupalGet('logout'); - - // Delete the name string. - $this->drupalLoginUser($translate_user); - $this->drupalGet('admin/build/translate/delete/'. $lid); - $this->assertText(t('The string has been removed.'), 'The string has been removed message.'); - $this->drupalPost('admin/build/translate/search', $search, 'Search'); - $this->assertNoText($name, 'Search now can not find the name'); - } -} Index: tests/menu_module.test =================================================================== RCS file: tests/menu_module.test diff -N tests/menu_module.test --- tests/menu_module.test 28 Jan 2008 08:48:37 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,275 +0,0 @@ - t('Menu link creation/deletion'), - 'desc' => t('Create two links in the Navigation menu, check their data, and delete them using the menu module UI.'), - 'group' => 'Menu Module Tests', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('menu'); - } - - function testCreateCheckDelete() { - - $web_user = $this->drupalCreateUserRolePerm(array('access content', 'administer menu', 'access administration pages',)); - $this->drupalLoginUser($web_user); - - $mlid1 = $this->uiCreateLink(); - $mlid2 = $this->uiCreateLink($mlid1); - - $link1 = menu_link_load($mlid1); - $this->assertTrue((bool)$link1, '1st link created and loaded'); - - $link2 = menu_link_load($mlid2); - $this->assertTrue((bool)$link2, '2nd link created as child and loaded'); - - // Check the structure in the DB of the two links. - // In general, if $n = $link['depth'] then $link['p'. $n] == $link['mlid'] and $link['p'. ($n - 1)] == $link['plid'] (unless depth == 0). - // All $link['p'. $n] for $n > depth must be 0. - // We know link1 is at the top level, so $link1['deptj'] == 1 and $link1['plid'] == 0. - // We know that the parent of link2 is link1, so $link2['plid'] == $link1['mlid']. - // Both links were created in the avigation menu. - $this->assertTrue($link1['p2'] == 0 && $link1['p1'] == $mlid1 && $link1['plid'] == 0 && $link1['depth'] == 1 && $link1['has_children'], '1st link has correct data'); - $this->assertTrue($link2['menu_name'] == 'navigation' && $link2['p2'] == $mlid2 && $link2['p1'] == $mlid1 && $link2['plid'] == $mlid1 && $link2['depth'] == 2 , '2nd link has correct data'); - $this->uiDeleteLink($mlid1); - $this->assertFalse(menu_link_load($mlid1), '1st link deleted'); - - $link2 = menu_link_load($mlid2); - $this->assertTrue($link2['plid'] == 0, '2nd link re-parented'); - $this->uiDeleteLink($mlid2); - $this->assertFalse(menu_link_load($mlid2), '2nd link link deleted'); - } - /** - * Delete a menu link using the menu module UI. - */ - function uiDeleteLink($mlid) { - $this->drupalPost("admin/build/menu/item/". $mlid ."/delete", array(), "Confirm"); - } - /** - * Create a menu link using the menu module UI. - */ - function uiCreateLink($plid = 0, $menu_name = 'navigation') { - $this->drupalGet("admin/build/menu-customize/$menu_name/add"); - $this->assertResponse(200); - - $title = '!link_'. $this->randomName(16); - $edit = array ( - 'menu[link_path]' => '', - 'menu[link_title]' => $title, - 'menu[description]' => '', - 'menu[parent]' => $menu_name.':'.$plid, - 'menu[weight]' => '0', - ); - - $this->drupalPost("admin/build/menu-customize/". $menu_name ."/add", $edit, "Save"); - $out = $this->drupalGet("admin/build/menu-customize/$menu_name"); - $this->assertText($title, 'Link created'); - $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_title = '%s'", $title)); - - return $mlid; - } -} - -class MenuModuleCustomMenuTest extends MenuModuleTestCase { - - /** - * Implementation of get_info() for information - */ - function get_info() { - return array( - 'name' => t('Custom menu creation/deletion'), - 'desc' => t('Create a custom menu, add a link to it, and delete it using the menu module UI.'), - 'group' => 'Menu Module Tests', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('menu'); - } - - function tearDown() { - parent::tearDown(); - } - - function testCreateCheckDelete() { - $web_user = $this->drupalCreateUserRolePerm(array('access content', 'administer menu', 'access administration pages',)); - $this->drupalLoginUser($web_user); - - $this->drupalGet('admin/build/menu/add'); - $name = substr(md5($this->randomName(16)), 0, 20); - $title = $this->randomName(16); - $edit = array ( - 'menu_name' => $name, - 'description' => '', - 'title' => $title, - ); - $this->drupalPost("admin/build/menu/add", $edit, "Save"); - - $name = 'menu-' .$name; - $this->drupalGet('admin/build/menu'); - $this->assertText($title, 'Menu created'); - - $mlid1 = $this->uiCreateLink(0, $name); - $link1 = menu_link_load($mlid1); - $this->assertTrue((bool)$link1, '1st link created and loaded'); - - $this->drupalPost("admin/build/menu-customize/". $name ."/delete", array(), "Delete"); - $this->assertFalse(menu_load($name), 'Custom menu deleted'); - $this->assertFalse(menu_link_load($mlid1), '1st link deleted with menu'); - } -} - - -class MenuModuleEnable extends DrupalTestCase { - /** - * Implementation of get_info() for information - */ - function get_info() { - return array( - 'name' => t('Menu enable'), - 'desc' => 'Enable / disable a menu item', - 'group' => 'Menu Module Tests', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('menu'); - } - - function tearDown() { - parent::tearDown(); - } - - function testMenuModuleEnable() { - $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); - $this->drupalLoginUser($web_user); - $this->drupalGet('admin/build/menu-customize/navigation'); - $this->clickLink('edit', 0); - $url = $this->getUrl(); - preg_match('/\d+/', $url, $matches); - $item = menu_link_load($matches[0]); - $hidden = $item['hidden']; - $edit['menu[enabled]'] = $hidden ? 1 : FALSE; - $this->assertTrue(TRUE, $hidden ? 'Disabled item found' : 'Enabled item found'); - $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, 'Save'); - $item = menu_link_load($item['mlid']); - $this->assertTrue($item['hidden'] != $hidden, $item['hidden'] ? 'Item is now disabled' : 'Item is now enabled'); - $edit['menu[enabled]'] = $hidden ? FALSE : 1; - $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, 'Save'); - $item = menu_link_load($item['mlid']); - $this->assertTrue($item['hidden'] == $hidden, $item['hidden'] ? 'Item is disabled again' : 'Item is now enabled again'); - } -} - - -class MenuModuleReset extends DrupalTestCase { - /** - * Implementation of get_info() for information - */ - function get_info() { - return array( - 'name' => t('Menu reset'), - 'desc' => 'Edit and reset a menu item', - 'group' => 'Menu Module Tests', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('menu'); - } - - function tearDown() { - parent::tearDown(); - } - - function testMenuModuleReset() {; - $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); - $this->drupalLoginUser($web_user); - $form_state = array(); - $menu['menu_name'] = 'navigation'; - require_once drupal_get_path('module', 'menu') .'/menu.admin.inc'; - $form = drupal_retrieve_form('menu_overview_form', $form_state, $menu); - $found = FALSE; - foreach ($form as $mlid => $elements) { - if (isset($elements['#item']) && $elements['#item']['module'] == 'system') { - $found = TRUE; - $mlid = substr($mlid, 5); - break; - } - } - $this->assertTrue($found, 'System module item found'); - if ($found) { - // We can't use menu API here because of localization issues. - $item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid)); - $edit['menu[link_title]'] = $this->randomName(16); - $path = 'admin/build/menu/item/'. $mlid; - $this->drupalPost($path .'/edit', $edit, 'Save'); - $new_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid)); - $this->assertTrue($new_title == $edit['menu[link_title]'], 'Edit succesful'); - $this->assertFalse($item['link_title'] == $new_title, 'Item changed' ); - $reset_path = $path .'/reset'; - $this->assertWantedRaw($reset_path, 'Reset link found'); - $this->drupalPost($reset_path, array(), 'Reset'); - $reset_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid)); - $this->assertFalse($edit['menu[link_title]'] == $reset_title, 'Item reset'); - $this->assertText(t('The menu item was reset to its default settings.'), 'Reset message'); - drupal_write_record('menu_links', $item, 'mlid'); - $restored_item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid)); - $this->assertTrue($item == $restored_item, 'Item restored'); - } - } -} - - -class MenuModuleInvalidPath extends DrupalTestCase { - /** - * Implementation of get_info() for information - */ - function get_info() { - return array( - 'name' => t('Menu invalid path'), - 'desc' => 'Try to create a menu item with an invalid / inaccesible path.', - 'group' => 'Menu Module Tests', - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('menu'); - } - - function tearDown() { - parent::tearDown(); - } - - function testMenuModuleInvalidPath() { - $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); - $this->drupalLoginUser($web_user); - foreach (array('-&-', 'admin/user/permissions') as $invalid_path) { - $edit = array ( - 'menu[link_path]' => $invalid_path, - 'menu[link_title]' => 'title', - ); - $this->drupalPost("admin/build/menu-customize/navigation/add", $edit, "Save"); - $this->assertWantedRaw(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $invalid_path)), 'Invalid path failed'); - } - } -} Index: tests/upload_tests.test =================================================================== RCS file: tests/upload_tests.test diff -N tests/upload_tests.test --- tests/upload_tests.test 28 Jan 2008 08:48:37 -0000 1.14 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,328 +0,0 @@ - 'Upload user picture', 'desc' => 'Assure that dimension check, extension check and image scaling work as designed.' , 'group' => 'Upload Tests'); - } - - /* - * Test if directories specified in settings exist in filesystem - */ - - function testDirectories() { - // test if filepath is proper - $file_dir = file_directory_path(); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $file_check = file_check_directory($file_dir, FILE_CREATE_DIRECTORY, 'file_directory_path'); - $picture_path = $file_dir .'/'.$picture_dir; - - - $pic_check = file_check_directory($picture_path, FILE_CREATE_DIRECTORY, 'user_picture_path'); - // check directories - //$this->assertTrue($file_check,"The directory $file_dir doesn't exist or cannot be created."); - //$this->assertTrue($pic_check,"The directory $picture_path doesn't exist or cannot be created."); - $this->_directory_test = is_writable($picture_path); - $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made."); - } - - function testNoPicture() { - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // not a image - $img_path = realpath(drupal_get_path('module', 'simpletest'). "/tests/upload_tests.test"); - $edit = array('files[picture_upload]' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $this->assertWantedRaw(t('The selected file %file could not be uploaded. Only JPEG, PNG and GIF images are allowed.', array('%file' => 'upload_tests.test')), 'The uploaded file was not an image.'); - variable_set('user_pictures', $old_pic_set); - - // do we have to check users roles? - // delete test user and roles - - } - - /* - * Do one test if ImageGDToolkit is installed - */ - - /* - * Do the test: - * GD Toolkit is installed - * Picture has invalid dimension - * - * results: The image should be uploaded because ImageGDToolkit resizes the picture - */ - function testWithGDinvalidDimension() { - if ($this->_directory_Test) - if (image_get_toolkit()) { - - // PREPARE: - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // changing actual setting; - $old_dim = variable_get('user_picture_dimensions', '85x85'); - $old_size = variable_get('user_picture_file_size', '30'); - $img_path = realpath("modules/tests/pictureTesting.jpg"); - $info = image_get_info($img_path); - - // set new variables; - $test_size = floor(filesize($img_path) / 1000) + 1; - $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - // TEST: - $edit = array('picture' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $file_dir = variable_get('file_directory_path', 'files'); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; - - // get full url to the user's image - $picture = file_create_url($pic_path); - - // check if image is displayed in user's profile page - $content = $this->_browser->getContent(); - $this->assertTrue(strpos($content,$picture), "Image is displayed in user's profile page"); - - // check if file is located in proper directory - $this->assertTrue(is_file($pic_path), "File is located in proper directory"); - - // RESTORING: - variable_set('user_picture_file_size', $old_size); - variable_set('user_picture_dimensions', $old_dim); - - variable_set('user_pictures', $old_pic_set); - } - - } - - /* - * Do the test: - * GD Toolkit is installed - * Picture has invalid size - * - * results: The image should be uploaded because ImageGDToolkit resizes the picture - */ - - function testWithGDinvalidSize() { - if ($this->_directory_Test) - if (image_get_toolkit()) { - // PREPARE: - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // changing actual setting; - $old_dim = variable_get('user_picture_dimensions', '85x85'); - $old_size = variable_get('user_picture_file_size', '30'); - $img_path = realpath("modules/tests/pictureTesting.jpg"); - $info = image_get_info($img_path); - // set new variables; - - $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); - $test_size = floor(filesize($img_path) / 1000) - 1; - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - // TEST: - $edit = array('picture' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $file_dir = variable_get('file_directory_path', 'files'); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; - - // get full url to the user's image - $picture = file_create_url($pic_path); - - // check if image is displayed in user's profile page - $content = $this->_browser->getContent(); - $this->assertTrue(strpos($content,$picture), "Image is displayed in user's profile page"); - - // check if file is located in proper directory - $this->assertTrue(is_file($pic_path), "File is located in proper directory"); - - // RESTORING: - variable_set('user_picture_file_size', $old_size); - variable_set('user_picture_dimensions', $old_dim); - - variable_set('user_pictures', $old_pic_set); - } - } - - /* - * Do the test: - * GD Toolkit is not installed - * Picture has invalid size - * - * results: The image shouldn't be uploaded - */ - - function testWithoutGDinvalidDimension() { - if ($this->_directory_test) - if (!image_get_toolkit()) { - // PREPARE: - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // changing actual setting; - $old_dim = variable_get('user_picture_dimensions', '85x85'); - $old_size = variable_get('user_picture_file_size', '30'); - $img_path = realpath("modules/tests/pictureTesting.jpg"); - $info = image_get_info($img_path); - // set new variables; - $test_size = floor(filesize($img_path) / 1000) + 1; - $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - // TEST: - $edit = array('picture' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $text = t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))); - $this->assertWantedText($text, 'Checking response on invalid image (dimensions).'); - - // check if file is not uploaded - $file_dir = variable_get('file_directory_path', 'files'); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; - $this->assertFalse(is_file($pic_path), "File is not uploaded"); - - // restore variables; - variable_set('user_picture_file_size', $old_size); - variable_set('user_picture_dimensions', $old_dim); - - variable_set('user_pictures', $old_pic_set); - } - } -/* - * Do the test: - * GD Toolkit is not installed - * Picture has invalid size - * - * results: The image shouldn't be uploaded - */ - - function testWithoutGDinvalidSize() { - if ($this->_directory_test) - if (!image_get_toolkit()) { - // PREPARE: - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // changing actual setting; - $old_dim = variable_get('user_picture_dimensions', '85x85'); - $old_size = variable_get('user_picture_file_size', '30'); - $img_path = realpath("modules/tests/pictureTesting.jpg"); - $info = image_get_info($img_path); - // invalid size - // restore one and set another - $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); - $test_size = floor(filesize($img_path) / 1000) - 1; - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - $edit = array('picture' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $text = t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))); - $this->assertWantedText($text, 'Checking response on invalid image size.'); - - // check if file is not uploaded - $file_dir = variable_get('file_directory_path', 'files'); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; - $this->assertFalse(is_file($pic_path), "File is not uploaded"); - // restore variables; - variable_set('user_picture_file_size', $old_size); - variable_set('user_picture_dimensions', $old_dim); - - variable_set('user_pictures', $old_pic_set); - } - } - - /* - * Do the test: - * Picture is valid (proper size and dimension) - * - * results: The image should be uploaded - */ - - - function testPictureIsValid() { - if ($this->_directory_test) { - // PREPARE: - $old_pic_set = variable_get('user_pictures', 0); - variable_set('user_pictures', 1); - - /* Prepare a user to do the stuff */ - $user = $this->drupalCreateUserRolePerm(array('access content')); - $this->drupalLoginUser($user); - - // changing actual setting; - $old_dim = variable_get('user_picture_dimensions', '85x85'); - $old_size = variable_get('user_picture_file_size', '30'); - $img_path = realpath(drupal_get_path('module', 'simpletest'). "/tests/pictureTesting.jpg"); - $info = image_get_info($img_path); - - // valid size & dimensions - // restore one and set another - $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); - $test_size = floor(filesize($img_path) / 1000) + 1; - variable_set('user_picture_dimensions', $test_dim); - variable_set('user_picture_file_size', $test_size); - - - // TEST: - $edit = array('files[picture_upload]' => $img_path); - $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); - $picture_dir = variable_get('user_picture_path', 'pictures'); - $pic_path = file_directory_path() .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; - - // get full url to the user's image - $picture = file_create_url($pic_path); - - - // check if image is displayed in user's profile page - $content = $this->drupalGetContent(); - - $this->assertTrue(strpos($content, $picture), "Image is displayed in user's profile page"); - - // check if file is located in proper directory - $this->assertTrue(is_file($pic_path), "File is located in proper directory"); - - // RESTORING: - variable_set('user_picture_file_size', $old_size); - variable_set('user_picture_dimensions', $old_dim); - - variable_set('user_pictures', $old_pic_set); - - // DELETING UPLOADED PIC - file_delete($pic_path); - } - - - } -} - -?> Index: tests/story_edit.test =================================================================== RCS file: tests/story_edit.test diff -N tests/story_edit.test --- tests/story_edit.test 28 Jan 2008 08:48:37 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,58 +0,0 @@ - 'Story edit test', - 'desc' => t('We want a working edit for storys, uh?'), - 'group' => 'Node Tests'); - } - function testStoryEdit() { - - /* 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! test title' . $this->randomName(20), - 'body' => '!SimpleTest! test body' . $this->randomName(200), - ); - - //Create the page to edit - $this->drupalPost('node/add/story', $edit, 'Save'); - - $node = node_load(array('title' => $edit['title'])); - $this->assertNotNull($node, 'Node found in database'); - - $this->clickLink('Edit'); - - $editurl = url("node/$node->nid/edit", array('absolute' => true)); - $acturl = $this->_browser->getURL(); - - $this->assertEqual($editurl, $acturl); - - $this->assertWantedText(t('Edit'), 'Edit 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'); - - $edit = array( - 'title' => '!SimpleTest! test title' . $this->randomName(20), - 'body' => '!SimpleTest! test body' . $this->randomName(200), - ); - - - //edit the content of the page - $this->drupalPost("node/$node->nid/edit", $edit, 'Save'); - - $this->assertWantedText(t($edit['title']), 'Hello, the random title'); - $this->assertWantedText(t($edit['body']), 'test is over, the body\'s still there'); - } - -} Index: tests/node_teaser.test =================================================================== RCS file: tests/node_teaser.test diff -N tests/node_teaser.test --- tests/node_teaser.test 30 Jan 2008 08:25:33 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,154 +0,0 @@ - t('Node teaser tests'), - 'desc' => t('Calls node_teaser() with different strings and lengths.'), - 'group' => 'Node Tests', - ); - } - - function setUp() { - parent::setUp(); - } - - function tearDown() { - parent::tearDown(); - } - - /** - * Simpletest test. Tests an edge case where if the first sentence is a - * question and subsequent sentences are not. - * This failed in drupal 5. - * Test and patch for drupal 6 (committed) from - * http://drupal.org/node/180425 - */ - function testFirstSentenceQuestion() { - $body = 'A question? A sentence. Another sentence.'; - $expectedTeaser = 'A question? A sentence.'; - $this->callNodeTeaser($body, $expectedTeaser, NULL, 30); - } - - /** - * Simpletest test. A real-life example of the above edge case. - */ - function testFirstSentenceQuestion2() { - $body = 'Are you an UberBabe? (Or an appreciator of UberBabes?) I am most definitely an UberBabe, and I\'m proud of it. Now, before anyone screams "sexism" or "bias" or "cheap" or anything more profane, let me clarify. An UberBabe is not someone who\'s playfully pierced navel protrudes from a belly bearing top. Not necessarily anyway. An UberBabe is a woman who likes being totally feminine, but is also smart as hell, brave, a rule breaker, speaks her mind, finds her own way, goes up against "the system" in a way that allows the system to evolve, and so on. UberBabes, frankly, kick booty - and they just may save the world.'; - $expectedTeaser = 'Are you an UberBabe? (Or an appreciator of UberBabes?) I am most definitely an UberBabe, and I\'m proud of it. Now, before anyone screams "sexism" or "bias" or "cheap" or anything more profane, let me clarify.'; - $this->callNodeTeaser($body, $expectedTeaser, NULL, 300); - } - - /** - * Simpletest test. Runs a test adapted from - * http://drupal.org/node/180425#comment-634230 - */ - function testLength() { - // This body string tests a number of edge cases. - $body = "

\nHi\n

\n

\nfolks\n
\n!\n

"; - - // The teasers we expect node_teaser() to return when $size is the index - // of each array item. - // Using an input format with no line-break filter: - $teasers = array( - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "<", - "", - "

\n", - "

\nH", - "

\nHi", - "

\nHi\n", - "

\nHi\n<", - "

\nHi\n\nHi\n\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - ); - // And Using an input format WITH the line-break filter. - $teasers_lb = array( - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "<", - "", - "

", - "

", - "

", - "

\nHi", - "

\nHi", - "

\nHi", - "

\nHi", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - "

\nHi\n

\n

\nfolks\n
\n!\n

", - ); - - // Test node_teaser() for different sizes. - for ($i = 0; $i <= 37; $i++) { - $this->callNodeTeaser($body, $teasers[$i], NULL, $i); - $this->callNodeTeaser($body, $teasers_lb[$i], 1, $i); - $this->callNodeTeaser($body, $teasers_lb[$i], 2, $i); - } - } - - /** - * Calls node_teaser() and asserts that the expected teaser is returned. - */ - function callNodeTeaser($body, $expectedTeaser, $format = NULL, $size = NULL) { - $teaser = node_teaser($body, $format, $size); - $this->assertIdentical($teaser, $expectedTeaser); - } -} - Index: tests/book_module.test =================================================================== RCS file: tests/book_module.test diff -N tests/book_module.test --- tests/book_module.test 28 Jan 2008 08:48:37 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,144 +0,0 @@ - t('Book functionality'), - 'desc' => t('Create a book, add pages, and test book interface.'), - 'group' => t('Book Tests'), - ); - } - - function setUp() { - parent::setUp(); - - $this->drupalModuleEnable('book'); - } - - /** - * Test book funcitonality through node interfaces. - */ - function testBook() { - // create users - $book_author = $this->drupalCreateUserRolePerm(array('create new books', 'create book content', 'add content to books')); - $web_user = $this->drupalCreateUserRolePerm(array('access printer-friendly version')); - - // create new book - $this->drupalLoginUser($book_author); - - $this->book = $this->createBookNode('new'); - $book = $this->book; - - /* - * add page hiearchy to book - * Book - * |- Node 0 - * |- Node 1 - * |- Node 2 - * |- Node 3 - * |- Node 4 - */ - $nodes = array(); - $nodes[] = $this->createBookNode($book->nid); // Node 0 - $nodes[] = $this->createBookNode($book->nid, $nodes[0]->book['mlid']); // Node 1 - $nodes[] = $this->createBookNode($book->nid, $nodes[0]->book['mlid']); // Node 2 - $nodes[] = $this->createBookNode($book->nid); // Node 3 - $nodes[] = $this->createBookNode($book->nid); // Node 4 - - $this->drupalGet('logout'); - - // check to make sure that book pages display properly - $this->drupalLoginUser($web_user); - - $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), false, false, $nodes[0]); - $this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1]); - $this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2]); - $this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3]); - $this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4]); - $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, false); - } - - /** - * Checks the outline of sub-pages; previous, up, and next; and check printer friendly version. - * - * @param Node $node Node to check. - * @param array $nodes Nodes that should be in outline. - * @param Node $previous Previous link node. - * @param Node $up Up link node. - * @param Node $next Next link node. - */ - function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) { - static $number = 0; - $this->drupalGet('node/' . $node->nid); - - // check outline structure - if ($nodes !== NULL) - $this->assertPattern($this->generateOutlinePattern($nodes), 'Node ' . $number . ' outline confirmed.'); - else - $this->assertNotNull(true, 'Node ' . $number . ' doesn\'t have outline.'); - - // check previous, up, and next links - if ($previous) - $this->assertWantedRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), 'Prevoius page link found.'); - if ($up) - $this->assertWantedRaw(l('up', 'node/' . $up->nid, array('attributes' => array('class' => 'page-up', 'title' => t('Go to parent page')))), 'Up page link found.'); - if ($next) - $this->assertWantedRaw(l($next->title . ' ›', 'node/' . $next->nid, array('attributes' => array('class' => 'page-next', 'title' => t('Go to next page')))), 'Next page link found.'); - - // check printer friendly version - $this->drupalGet('book/export/html/' . $node->nid); - $this->assertText($node->title, 'Printer friendly title found.'); - $node->body = str_replace('', '', $node->body); - $this->assertWantedRaw(check_markup($node->body, $node->format), 'Printer friendly body found.'); - - $number++; - } - - /** - * Create a regular expression to check for the sub-nodes in the outline. - * - * @param array $nodes Nodes to check in outline. - */ - function generateOutlinePattern($nodes) { - $outline = ''; - foreach ($nodes as $node) - $outline .= '(node\/' . $node->nid . ')(.*?)(' . $node->title . ')(.*?)'; - - return '/
/s'; - } - - /** - * Create book node. - * - * @param integer $book_nid Book node id or set to 'new' to create new book. - * @param integer $parent Parent book reference id. - */ - function createBookNode($book_nid, $parent = NULL) { - static $number = 0; // used to ensure that when sorted nodes stay in same order - $this->drupalVariableSet('node_options_page', array('status', 'promote')); - - $edit = array(); - $edit['title'] = $number . ' - SimpleTest test node ' . $this->randomName(10); - $edit['body'] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32); - $edit['book[bid]'] = $book_nid; - - if ($parent !== NULL) { - $this->drupalPost('node/add/book', $edit, 'Change book (update list of parents)'); - - $edit['book[plid]'] = $parent; - $this->drupalPost(NULL, $edit, 'Save'); - } - else - $this->drupalPost('node/add/book', $edit, 'Save'); - - // check to make sure the book node was created - $node = node_load(array('title' => $edit['title'])); - $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.'); - $number++; - - return $node; - } -} Index: tests/content_actions.test =================================================================== RCS file: tests/content_actions.test diff -N tests/content_actions.test --- tests/content_actions.test 28 Jan 2008 08:48:37 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,69 +0,0 @@ - t('Actions content'), - 'desc' => t('Perform various tests with content actions.') , - 'group' => 'Actions', - ); - } - - /** - * Various tests, all in one function to assure they happen in the right order. - */ - function testActionsContent() { - global $user; - - $this->drupalModuleEnable('trigger'); - - $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action'); - - $hash = md5('node_publish_action'); - - $not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); - $this->assertFalse($not_clean, t('Actions were already assigned to the trigger. Unassign all content triggers before attempting to run again.')); - - if ($not_clean) { - return; - } - - // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. (Wow, those metaphors work out nicely). - - $test_user = $this->drupalCreateUserRolePerm(array('administer actions', 'create page content')); - $this->drupalLoginUser($test_user); - - // Set action id to "publish post". - $edit = array('aid' => $hash); - $this->drupalPost('admin/build/trigger/node', $edit, 'Assign'); - - // Create an unpublished node. - $node = $this->drupalCreateNode(array('status' => 0)); - // Node should be published automatically. - $loaded_node = node_load($node->nid); - $this->assertTrue($loaded_node->status == 1, t('Check to make sure the node is automatically published')); - - // Leave action assigned for next test - - // Test 2: There should be an error when the action is assigned to the trigger twice. - - $edit = array('aid' => $hash); - $this->drupalPost('admin/build/trigger/node', $edit, 'Assign'); - $this->assertWantedRaw(t('The action you chose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.')); - - // Test 3: The action should be able to be unassigned from a trigger. - - // This effectively cleans up as well. - $this->drupalPost('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), 'Unassign'); - $this->assertWantedRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure action can be unassigned from trigger.')); - - $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); - $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.')); - } -} Index: tests/functional/module/translation.test =================================================================== RCS file: tests/functional/module/translation.test diff -N tests/functional/module/translation.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/translation.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,150 @@ + 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/functional/module/search.test =================================================================== RCS file: tests/functional/module/search.test diff -N tests/functional/module/search.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/search.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,181 @@ + 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/functional/module/upload.test =================================================================== RCS file: tests/functional/module/upload.test diff -N tests/functional/module/upload.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/upload.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,328 @@ + 'Upload user picture', 'desc' => 'Assure that dimension check, extension check and image scaling work as designed.' , 'group' => 'Upload Tests'); + } + + /* + * Test if directories specified in settings exist in filesystem + */ + + function testDirectories() { + // test if filepath is proper + $file_dir = file_directory_path(); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $file_check = file_check_directory($file_dir, FILE_CREATE_DIRECTORY, 'file_directory_path'); + $picture_path = $file_dir .'/'.$picture_dir; + + + $pic_check = file_check_directory($picture_path, FILE_CREATE_DIRECTORY, 'user_picture_path'); + // check directories + //$this->assertTrue($file_check,"The directory $file_dir doesn't exist or cannot be created."); + //$this->assertTrue($pic_check,"The directory $picture_path doesn't exist or cannot be created."); + $this->_directory_test = is_writable($picture_path); + $this->assertTrue($this->_directory_test, "The directory $picture_path doesn't exist or is not writable. Further tests won't be made."); + } + + function testNoPicture() { + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // not a image + $img_path = realpath(drupal_get_path('module', 'simpletest'). "/tests/upload_tests.test"); + $edit = array('files[picture_upload]' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $this->assertWantedRaw(t('The selected file %file could not be uploaded. Only JPEG, PNG and GIF images are allowed.', array('%file' => 'upload_tests.test')), 'The uploaded file was not an image.'); + variable_set('user_pictures', $old_pic_set); + + // do we have to check users roles? + // delete test user and roles + + } + + /* + * Do one test if ImageGDToolkit is installed + */ + + /* + * Do the test: + * GD Toolkit is installed + * Picture has invalid dimension + * + * results: The image should be uploaded because ImageGDToolkit resizes the picture + */ + function testWithGDinvalidDimension() { + if ($this->_directory_Test) + if (image_get_toolkit()) { + + // PREPARE: + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // changing actual setting; + $old_dim = variable_get('user_picture_dimensions', '85x85'); + $old_size = variable_get('user_picture_file_size', '30'); + $img_path = realpath("modules/tests/pictureTesting.jpg"); + $info = image_get_info($img_path); + + // set new variables; + $test_size = floor(filesize($img_path) / 1000) + 1; + $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); + variable_set('user_picture_dimensions', $test_dim); + variable_set('user_picture_file_size', $test_size); + + // TEST: + $edit = array('picture' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $file_dir = variable_get('file_directory_path', 'files'); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; + + // get full url to the user's image + $picture = file_create_url($pic_path); + + // check if image is displayed in user's profile page + $content = $this->_browser->getContent(); + $this->assertTrue(strpos($content,$picture), "Image is displayed in user's profile page"); + + // check if file is located in proper directory + $this->assertTrue(is_file($pic_path), "File is located in proper directory"); + + // RESTORING: + variable_set('user_picture_file_size', $old_size); + variable_set('user_picture_dimensions', $old_dim); + + variable_set('user_pictures', $old_pic_set); + } + + } + + /* + * Do the test: + * GD Toolkit is installed + * Picture has invalid size + * + * results: The image should be uploaded because ImageGDToolkit resizes the picture + */ + + function testWithGDinvalidSize() { + if ($this->_directory_Test) + if (image_get_toolkit()) { + // PREPARE: + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // changing actual setting; + $old_dim = variable_get('user_picture_dimensions', '85x85'); + $old_size = variable_get('user_picture_file_size', '30'); + $img_path = realpath("modules/tests/pictureTesting.jpg"); + $info = image_get_info($img_path); + // set new variables; + + $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); + $test_size = floor(filesize($img_path) / 1000) - 1; + variable_set('user_picture_dimensions', $test_dim); + variable_set('user_picture_file_size', $test_size); + + // TEST: + $edit = array('picture' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $file_dir = variable_get('file_directory_path', 'files'); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; + + // get full url to the user's image + $picture = file_create_url($pic_path); + + // check if image is displayed in user's profile page + $content = $this->_browser->getContent(); + $this->assertTrue(strpos($content,$picture), "Image is displayed in user's profile page"); + + // check if file is located in proper directory + $this->assertTrue(is_file($pic_path), "File is located in proper directory"); + + // RESTORING: + variable_set('user_picture_file_size', $old_size); + variable_set('user_picture_dimensions', $old_dim); + + variable_set('user_pictures', $old_pic_set); + } + } + + /* + * Do the test: + * GD Toolkit is not installed + * Picture has invalid size + * + * results: The image shouldn't be uploaded + */ + + function testWithoutGDinvalidDimension() { + if ($this->_directory_test) + if (!image_get_toolkit()) { + // PREPARE: + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // changing actual setting; + $old_dim = variable_get('user_picture_dimensions', '85x85'); + $old_size = variable_get('user_picture_file_size', '30'); + $img_path = realpath("modules/tests/pictureTesting.jpg"); + $info = image_get_info($img_path); + // set new variables; + $test_size = floor(filesize($img_path) / 1000) + 1; + $test_dim = ($info['width'] - 10) . 'x' . ($info['height'] - 10); + variable_set('user_picture_dimensions', $test_dim); + variable_set('user_picture_file_size', $test_size); + + // TEST: + $edit = array('picture' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $text = t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))); + $this->assertWantedText($text, 'Checking response on invalid image (dimensions).'); + + // check if file is not uploaded + $file_dir = variable_get('file_directory_path', 'files'); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; + $this->assertFalse(is_file($pic_path), "File is not uploaded"); + + // restore variables; + variable_set('user_picture_file_size', $old_size); + variable_set('user_picture_dimensions', $old_dim); + + variable_set('user_pictures', $old_pic_set); + } + } +/* + * Do the test: + * GD Toolkit is not installed + * Picture has invalid size + * + * results: The image shouldn't be uploaded + */ + + function testWithoutGDinvalidSize() { + if ($this->_directory_test) + if (!image_get_toolkit()) { + // PREPARE: + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // changing actual setting; + $old_dim = variable_get('user_picture_dimensions', '85x85'); + $old_size = variable_get('user_picture_file_size', '30'); + $img_path = realpath("modules/tests/pictureTesting.jpg"); + $info = image_get_info($img_path); + // invalid size + // restore one and set another + $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); + $test_size = floor(filesize($img_path) / 1000) - 1; + variable_set('user_picture_dimensions', $test_dim); + variable_set('user_picture_file_size', $test_size); + + $edit = array('picture' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $text = t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))); + $this->assertWantedText($text, 'Checking response on invalid image size.'); + + // check if file is not uploaded + $file_dir = variable_get('file_directory_path', 'files'); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $pic_path = $file_dir .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; + $this->assertFalse(is_file($pic_path), "File is not uploaded"); + // restore variables; + variable_set('user_picture_file_size', $old_size); + variable_set('user_picture_dimensions', $old_dim); + + variable_set('user_pictures', $old_pic_set); + } + } + + /* + * Do the test: + * Picture is valid (proper size and dimension) + * + * results: The image should be uploaded + */ + + + function testPictureIsValid() { + if ($this->_directory_test) { + // PREPARE: + $old_pic_set = variable_get('user_pictures', 0); + variable_set('user_pictures', 1); + + /* Prepare a user to do the stuff */ + $user = $this->drupalCreateUserRolePerm(array('access content')); + $this->drupalLoginUser($user); + + // changing actual setting; + $old_dim = variable_get('user_picture_dimensions', '85x85'); + $old_size = variable_get('user_picture_file_size', '30'); + $img_path = realpath(drupal_get_path('module', 'simpletest'). "/tests/pictureTesting.jpg"); + $info = image_get_info($img_path); + + // valid size & dimensions + // restore one and set another + $test_dim = ($info['width'] + 10) . 'x' . ($info['height'] + 10); + $test_size = floor(filesize($img_path) / 1000) + 1; + variable_set('user_picture_dimensions', $test_dim); + variable_set('user_picture_file_size', $test_size); + + + // TEST: + $edit = array('files[picture_upload]' => $img_path); + $this->drupalPost('user/'.$user->uid.'/edit', $edit, 'Save' ); + $picture_dir = variable_get('user_picture_path', 'pictures'); + $pic_path = file_directory_path() .'/'.$picture_dir .'/picture-'.$user->uid.'.jpg'; + + // get full url to the user's image + $picture = file_create_url($pic_path); + + + // check if image is displayed in user's profile page + $content = $this->drupalGetContent(); + + $this->assertTrue(strpos($content, $picture), "Image is displayed in user's profile page"); + + // check if file is located in proper directory + $this->assertTrue(is_file($pic_path), "File is located in proper directory"); + + // RESTORING: + variable_set('user_picture_file_size', $old_size); + variable_set('user_picture_dimensions', $old_dim); + + variable_set('user_pictures', $old_pic_set); + + // DELETING UPLOADED PIC + file_delete($pic_path); + } + + + } +} + +?> Index: tests/unit/xmlrpc.test =================================================================== RCS file: tests/unit/xmlrpc.test diff -N tests/unit/xmlrpc.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/unit/xmlrpc.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,116 @@ + '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'); + } +} +?> Index: tests/functional/module/book.test =================================================================== RCS file: tests/functional/module/book.test diff -N tests/functional/module/book.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/book.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,144 @@ + t('Book functionality'), + 'desc' => t('Create a book, add pages, and test book interface.'), + 'group' => t('Book Tests'), + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('book'); + } + + /** + * Test book funcitonality through node interfaces. + */ + function testBook() { + // create users + $book_author = $this->drupalCreateUserRolePerm(array('create new books', 'create book content', 'add content to books')); + $web_user = $this->drupalCreateUserRolePerm(array('access printer-friendly version')); + + // create new book + $this->drupalLoginUser($book_author); + + $this->book = $this->createBookNode('new'); + $book = $this->book; + + /* + * add page hiearchy to book + * Book + * |- Node 0 + * |- Node 1 + * |- Node 2 + * |- Node 3 + * |- Node 4 + */ + $nodes = array(); + $nodes[] = $this->createBookNode($book->nid); // Node 0 + $nodes[] = $this->createBookNode($book->nid, $nodes[0]->book['mlid']); // Node 1 + $nodes[] = $this->createBookNode($book->nid, $nodes[0]->book['mlid']); // Node 2 + $nodes[] = $this->createBookNode($book->nid); // Node 3 + $nodes[] = $this->createBookNode($book->nid); // Node 4 + + $this->drupalGet('logout'); + + // check to make sure that book pages display properly + $this->drupalLoginUser($web_user); + + $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), false, false, $nodes[0]); + $this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1]); + $this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2]); + $this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3]); + $this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4]); + $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, false); + } + + /** + * Checks the outline of sub-pages; previous, up, and next; and check printer friendly version. + * + * @param Node $node Node to check. + * @param array $nodes Nodes that should be in outline. + * @param Node $previous Previous link node. + * @param Node $up Up link node. + * @param Node $next Next link node. + */ + function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) { + static $number = 0; + $this->drupalGet('node/' . $node->nid); + + // check outline structure + if ($nodes !== NULL) + $this->assertPattern($this->generateOutlinePattern($nodes), 'Node ' . $number . ' outline confirmed.'); + else + $this->assertNotNull(true, 'Node ' . $number . ' doesn\'t have outline.'); + + // check previous, up, and next links + if ($previous) + $this->assertWantedRaw(l('‹ ' . $previous->title, 'node/' . $previous->nid, array('attributes' => array('class' => 'page-previous', 'title' => t('Go to previous page')))), 'Prevoius page link found.'); + if ($up) + $this->assertWantedRaw(l('up', 'node/' . $up->nid, array('attributes' => array('class' => 'page-up', 'title' => t('Go to parent page')))), 'Up page link found.'); + if ($next) + $this->assertWantedRaw(l($next->title . ' ›', 'node/' . $next->nid, array('attributes' => array('class' => 'page-next', 'title' => t('Go to next page')))), 'Next page link found.'); + + // check printer friendly version + $this->drupalGet('book/export/html/' . $node->nid); + $this->assertText($node->title, 'Printer friendly title found.'); + $node->body = str_replace('', '', $node->body); + $this->assertWantedRaw(check_markup($node->body, $node->format), 'Printer friendly body found.'); + + $number++; + } + + /** + * Create a regular expression to check for the sub-nodes in the outline. + * + * @param array $nodes Nodes to check in outline. + */ + function generateOutlinePattern($nodes) { + $outline = ''; + foreach ($nodes as $node) + $outline .= '(node\/' . $node->nid . ')(.*?)(' . $node->title . ')(.*?)'; + + return '/
/s'; + } + + /** + * Create book node. + * + * @param integer $book_nid Book node id or set to 'new' to create new book. + * @param integer $parent Parent book reference id. + */ + function createBookNode($book_nid, $parent = NULL) { + static $number = 0; // used to ensure that when sorted nodes stay in same order + $this->drupalVariableSet('node_options_page', array('status', 'promote')); + + $edit = array(); + $edit['title'] = $number . ' - SimpleTest test node ' . $this->randomName(10); + $edit['body'] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32); + $edit['book[bid]'] = $book_nid; + + if ($parent !== NULL) { + $this->drupalPost('node/add/book', $edit, 'Change book (update list of parents)'); + + $edit['book[plid]'] = $parent; + $this->drupalPost(NULL, $edit, 'Save'); + } + else + $this->drupalPost('node/add/book', $edit, 'Save'); + + // check to make sure the book node was created + $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.'); + $number++; + + return $node; + } +} Index: tests/functional/module/locale.test =================================================================== RCS file: tests/functional/module/locale.test diff -N tests/functional/module/locale.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/locale.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,117 @@ + t('String translate'), + 'desc' => 'Adds a new locale and translates its name', + 'group' => 'Locale', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('locale'); + } + + function testlocaleModuleTest() { + global $base_url; + + // User to add and remove language. + $admin_user = $this->drupalCreateUserRolePerm(array('administer languages', 'access administration pages')); + // User to translate and delete string. + $translate_user = $this->drupalCreateUserRolePerm(array('translate interface', 'access administration pages')); + // Code for the language. + $langcode = str_replace('simpletest_', 'si-', $this->randomName(6)); + // The English name for the language. This will be translated. + $name = $this->randomName(16); + // The native name for the language. + $native = $this->randomName(16); + // The domain prefix. Not tested yet. + $prefix = strtolower(str_replace('si-', '', $langcode)); + // This is the language indicator on the translation search screen for + // untranslated strings. Copied straight from locale.inc. + $language_indicator = "$langcode "; + // This will be the translation of $name. + $translation = $this->randomName(16); + + // Add language. + $this->drupalLoginUser($admin_user); + $edit = array ( + 'langcode' => $langcode, + 'name' => $name, + 'native' => $native, + 'prefix' => $prefix, + 'direction' => '0', + ); + $this->drupalPost('admin/settings/language/add', $edit, 'Add custom language'); + // Add string. + t($name, array(), $langcode); + // Reset locale cache. + locale(NULL, NULL, TRUE); + $this->assertText($langcode, 'Language code found'); + $this->assertText($name, 'Name found'); + $this->assertText($native, 'Native found'); + // No t() here, we do not want to add this string to the database and it's + // surely not translated yet. + $this->assertText($native, 'Test language added'); + $this->drupalGet('logout'); + + // Search for the name and translate it. + $this->drupalLoginUser($translate_user); + $search = array ( + 'string' => $name, + 'language' => 'all', + 'translation' => 'all', + 'group' => 'all', + ); + $this->drupalPost('admin/build/translate/search', $search, 'Search'); + // assertText seems to remove the input field where $name always could be + // found, so this is not a false assert. See how assertNoText succeeds + // later. + $this->assertText($name, 'Search found the name'); + $this->assertWantedRaw($language_indicator, 'Name is untranslated'); + // It's presumed that this is the only result. Given the random name, it's + // reasonable. + $this->clickLink('edit'); + // We save the lid from the path. + $lid = preg_replace('/\D/', '', substr($this->getUrl(), strlen($base_url))); + // No t() here, it's surely not translated yet. + $this->assertText($name, 'name found on edit screen'); + $edit = array ( + "translations[$langcode]" => $translation, + ); + $this->drupalPost(NULL, $edit, 'Save translations'); + $this->assertText(t('The string has been saved.'), 'The string has been saved.'); + $this->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, 't() works'); + $this->drupalPost('admin/build/translate/search', $search, 'Search'); + // The indicator should not be here. + $this->assertNoUnwantedRaw($language_indicator, 'String is translated'); + $this->drupalGet('logout'); + + // Delete the language + $this->drupalLoginUser($admin_user); + $path = 'admin/settings/language/delete/'. $langcode; + // This a confirm form, we do not need any fields changed. + $this->drupalPost($path, array(), 'Delete'); + // We need raw here because %locale will add HTML. + $this->assertWantedRaw(t('The language %locale has been removed.', array('%locale' => $name)), 'The test language has been removed.'); + // Reload to remove $name. + $this->drupalGet($path); + $this->assertNoText($langcode, 'Language code not found'); + $this->assertNoText($name, 'Name not found'); + $this->assertNoText($native, 'Native not found'); + $this->drupalGet('logout'); + + // Delete the name string. + $this->drupalLoginUser($translate_user); + $this->drupalGet('admin/build/translate/delete/'. $lid); + $this->assertText(t('The string has been removed.'), 'The string has been removed message.'); + $this->drupalPost('admin/build/translate/search', $search, 'Search'); + $this->assertNoText($name, 'Search now can not find the name'); + } +} Index: tests/functional/module/profile.test =================================================================== RCS file: tests/functional/module/profile.test diff -N tests/functional/module/profile.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/profile.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,974 @@ + '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/functional/module/story.test =================================================================== RCS file: tests/functional/module/story.test diff -N tests/functional/module/story.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/story.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,92 @@ + 'Story edit test', + 'desc' => t('We want a working edit for storys, uh?'), + 'group' => 'Node Tests'); + } + function testStoryEdit() { + + /* 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! test title' . $this->randomName(20), + 'body' => '!SimpleTest! test body' . $this->randomName(200), + ); + + //Create the page to edit + $this->drupalPost('node/add/story', $edit, 'Save'); + + $node = node_load(array('title' => $edit['title'])); + $this->assertNotNull($node, 'Node found in database'); + + $this->clickLink('Edit'); + + $editurl = url("node/$node->nid/edit", array('absolute' => true)); + $acturl = $this->_browser->getURL(); + + $this->assertEqual($editurl, $acturl); + + $this->assertWantedText(t('Edit'), 'Edit 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'); + + $edit = array( + 'title' => '!SimpleTest! test title' . $this->randomName(20), + 'body' => '!SimpleTest! test body' . $this->randomName(200), + ); + + + //edit the content of the page + $this->drupalPost("node/$node->nid/edit", $edit, 'Save'); + + $this->assertWantedText(t($edit['title']), 'Hello, the random title'); + $this->assertWantedText(t($edit['body']), 'test is over, the body\'s still there'); + } + +} + +/** +* Test file for story_preview +*/ +class StoryPreviewTest extends DrupalTestCase { + function get_info() { + return array( + 'name' => '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/functional/module/forum.test =================================================================== RCS file: tests/functional/module/forum.test diff -N tests/functional/module/forum.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/forum.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,364 @@ + 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/functional/module/menu.test =================================================================== RCS file: tests/functional/module/menu.test diff -N tests/functional/module/menu.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/menu.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,275 @@ + t('Menu link creation/deletion'), + 'desc' => t('Create two links in the Navigation menu, check their data, and delete them using the menu module UI.'), + 'group' => 'Menu Module Tests', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('menu'); + } + + function testCreateCheckDelete() { + + $web_user = $this->drupalCreateUserRolePerm(array('access content', 'administer menu', 'access administration pages',)); + $this->drupalLoginUser($web_user); + + $mlid1 = $this->uiCreateLink(); + $mlid2 = $this->uiCreateLink($mlid1); + + $link1 = menu_link_load($mlid1); + $this->assertTrue((bool)$link1, '1st link created and loaded'); + + $link2 = menu_link_load($mlid2); + $this->assertTrue((bool)$link2, '2nd link created as child and loaded'); + + // Check the structure in the DB of the two links. + // In general, if $n = $link['depth'] then $link['p'. $n] == $link['mlid'] and $link['p'. ($n - 1)] == $link['plid'] (unless depth == 0). + // All $link['p'. $n] for $n > depth must be 0. + // We know link1 is at the top level, so $link1['deptj'] == 1 and $link1['plid'] == 0. + // We know that the parent of link2 is link1, so $link2['plid'] == $link1['mlid']. + // Both links were created in the avigation menu. + $this->assertTrue($link1['p2'] == 0 && $link1['p1'] == $mlid1 && $link1['plid'] == 0 && $link1['depth'] == 1 && $link1['has_children'], '1st link has correct data'); + $this->assertTrue($link2['menu_name'] == 'navigation' && $link2['p2'] == $mlid2 && $link2['p1'] == $mlid1 && $link2['plid'] == $mlid1 && $link2['depth'] == 2 , '2nd link has correct data'); + $this->uiDeleteLink($mlid1); + $this->assertFalse(menu_link_load($mlid1), '1st link deleted'); + + $link2 = menu_link_load($mlid2); + $this->assertTrue($link2['plid'] == 0, '2nd link re-parented'); + $this->uiDeleteLink($mlid2); + $this->assertFalse(menu_link_load($mlid2), '2nd link link deleted'); + } + /** + * Delete a menu link using the menu module UI. + */ + function uiDeleteLink($mlid) { + $this->drupalPost("admin/build/menu/item/". $mlid ."/delete", array(), "Confirm"); + } + /** + * Create a menu link using the menu module UI. + */ + function uiCreateLink($plid = 0, $menu_name = 'navigation') { + $this->drupalGet("admin/build/menu-customize/$menu_name/add"); + $this->assertResponse(200); + + $title = '!link_'. $this->randomName(16); + $edit = array ( + 'menu[link_path]' => '', + 'menu[link_title]' => $title, + 'menu[description]' => '', + 'menu[parent]' => $menu_name.':'.$plid, + 'menu[weight]' => '0', + ); + + $this->drupalPost("admin/build/menu-customize/". $menu_name ."/add", $edit, "Save"); + $out = $this->drupalGet("admin/build/menu-customize/$menu_name"); + $this->assertText($title, 'Link created'); + $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_title = '%s'", $title)); + + return $mlid; + } +} + +class MenuModuleCustomMenuTest extends MenuModuleTestCase { + + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => t('Custom menu creation/deletion'), + 'desc' => t('Create a custom menu, add a link to it, and delete it using the menu module UI.'), + 'group' => 'Menu Module Tests', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('menu'); + } + + function tearDown() { + parent::tearDown(); + } + + function testCreateCheckDelete() { + $web_user = $this->drupalCreateUserRolePerm(array('access content', 'administer menu', 'access administration pages',)); + $this->drupalLoginUser($web_user); + + $this->drupalGet('admin/build/menu/add'); + $name = substr(md5($this->randomName(16)), 0, 20); + $title = $this->randomName(16); + $edit = array ( + 'menu_name' => $name, + 'description' => '', + 'title' => $title, + ); + $this->drupalPost("admin/build/menu/add", $edit, "Save"); + + $name = 'menu-' .$name; + $this->drupalGet('admin/build/menu'); + $this->assertText($title, 'Menu created'); + + $mlid1 = $this->uiCreateLink(0, $name); + $link1 = menu_link_load($mlid1); + $this->assertTrue((bool)$link1, '1st link created and loaded'); + + $this->drupalPost("admin/build/menu-customize/". $name ."/delete", array(), "Delete"); + $this->assertFalse(menu_load($name), 'Custom menu deleted'); + $this->assertFalse(menu_link_load($mlid1), '1st link deleted with menu'); + } +} + + +class MenuModuleEnable extends DrupalTestCase { + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => t('Menu enable'), + 'desc' => 'Enable / disable a menu item', + 'group' => 'Menu Module Tests', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('menu'); + } + + function tearDown() { + parent::tearDown(); + } + + function testMenuModuleEnable() { + $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); + $this->drupalLoginUser($web_user); + $this->drupalGet('admin/build/menu-customize/navigation'); + $this->clickLink('edit', 0); + $url = $this->getUrl(); + preg_match('/\d+/', $url, $matches); + $item = menu_link_load($matches[0]); + $hidden = $item['hidden']; + $edit['menu[enabled]'] = $hidden ? 1 : FALSE; + $this->assertTrue(TRUE, $hidden ? 'Disabled item found' : 'Enabled item found'); + $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, 'Save'); + $item = menu_link_load($item['mlid']); + $this->assertTrue($item['hidden'] != $hidden, $item['hidden'] ? 'Item is now disabled' : 'Item is now enabled'); + $edit['menu[enabled]'] = $hidden ? FALSE : 1; + $this->drupalPost('admin/build/menu/item/'. $item['mlid'] .'/edit', $edit, 'Save'); + $item = menu_link_load($item['mlid']); + $this->assertTrue($item['hidden'] == $hidden, $item['hidden'] ? 'Item is disabled again' : 'Item is now enabled again'); + } +} + + +class MenuModuleReset extends DrupalTestCase { + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => t('Menu reset'), + 'desc' => 'Edit and reset a menu item', + 'group' => 'Menu Module Tests', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('menu'); + } + + function tearDown() { + parent::tearDown(); + } + + function testMenuModuleReset() {; + $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); + $this->drupalLoginUser($web_user); + $form_state = array(); + $menu['menu_name'] = 'navigation'; + require_once drupal_get_path('module', 'menu') .'/menu.admin.inc'; + $form = drupal_retrieve_form('menu_overview_form', $form_state, $menu); + $found = FALSE; + foreach ($form as $mlid => $elements) { + if (isset($elements['#item']) && $elements['#item']['module'] == 'system') { + $found = TRUE; + $mlid = substr($mlid, 5); + break; + } + } + $this->assertTrue($found, 'System module item found'); + if ($found) { + // We can't use menu API here because of localization issues. + $item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid)); + $edit['menu[link_title]'] = $this->randomName(16); + $path = 'admin/build/menu/item/'. $mlid; + $this->drupalPost($path .'/edit', $edit, 'Save'); + $new_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid)); + $this->assertTrue($new_title == $edit['menu[link_title]'], 'Edit succesful'); + $this->assertFalse($item['link_title'] == $new_title, 'Item changed' ); + $reset_path = $path .'/reset'; + $this->assertWantedRaw($reset_path, 'Reset link found'); + $this->drupalPost($reset_path, array(), 'Reset'); + $reset_title = db_result(db_query('SELECT link_title FROM {menu_links} WHERE mlid = %d', $mlid)); + $this->assertFalse($edit['menu[link_title]'] == $reset_title, 'Item reset'); + $this->assertText(t('The menu item was reset to its default settings.'), 'Reset message'); + drupal_write_record('menu_links', $item, 'mlid'); + $restored_item = db_fetch_array(db_query('SELECT * FROM {menu_links} WHERE mlid = %d', $mlid)); + $this->assertTrue($item == $restored_item, 'Item restored'); + } + } +} + + +class MenuModuleInvalidPath extends DrupalTestCase { + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => t('Menu invalid path'), + 'desc' => 'Try to create a menu item with an invalid / inaccesible path.', + 'group' => 'Menu Module Tests', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalModuleEnable('menu'); + } + + function tearDown() { + parent::tearDown(); + } + + function testMenuModuleInvalidPath() { + $web_user = $this->drupalCreateUserRolePerm(array('administer menu')); + $this->drupalLoginUser($web_user); + foreach (array('-&-', 'admin/user/permissions') as $invalid_path) { + $edit = array ( + 'menu[link_path]' => $invalid_path, + 'menu[link_title]' => 'title', + ); + $this->drupalPost("admin/build/menu-customize/navigation/add", $edit, "Save"); + $this->assertWantedRaw(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $invalid_path)), 'Invalid path failed'); + } + } +} Index: tests/functional/module/node.test =================================================================== RCS file: tests/functional/module/node.test diff -N tests/functional/module/node.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/node.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,261 @@ + t('Node revisions tests'), + 'desc' => t('Creates a node of type page and then a user tries various revision actions such as viewing, reverting to, and deleting revisions.'), + 'group' => 'Node Tests', + ); + } + + /** + * Setup function used by tests. Creates a node with three revisions. + * + * If $log is TRUE, then a log message will be recorded. + */ + function prepareRevisions($log = FALSE) { + + $returnarray = array(); + $numtimes = 3; // First, middle, last. + for ($i = 0; $i < $numtimes; $i++) { + $settings = array('revision' => 1); + if ($log && $i == 1) { + $logmessage = $this->randomName(32); + $settings['log'] = $logmessage; + $returnarray['log'] = $logmessage; + } + if ($i != 0) { + $settings['nid'] = $node->nid; + } + $node = $this->drupalCreateNode($settings); + if ($i == 1) { + $returnarray['text'] = $node->body; + $returnarray['vid'] = $node->vid; + } + // Avoid confusion on the revisions overview page which is sorted by r.timestamp. + sleep(1); + } + $returnarray['node'] = $node; + return $returnarray; + } + + /** + * Simpletest test. Tests to make sure the correct revision text appears on "view revisions" page. + */ + function testNodeRevisions() { + extract( $this->prepareRevisions() ); + + $test_user = $this->drupalCreateUserRolePerm(array('view revisions')); + $this->drupalLoginUser($test_user); + $this->drupalGet("node/$node->nid/revisions/$vid/view"); + $this->assertText($text, 'Check to make sure correct revision text appears on "view revisions" page.'); + + $this->cleanup($node->nid); + } + + /** + * Simpletest test. Tests to make sure the correct log message appears on "revisions overview" page. + */ + function testLogMessage() { + extract( $this->prepareRevisions(TRUE) ); + + $test_user = $this->drupalCreateUserRolePerm(array('view revisions')); + $this->drupalLoginUser($test_user); + $this->drupalGet("node/$node->nid/revisions"); + $this->assertText($log, 'Check to make sure log message is properly displayed.'); + + $this->cleanup($node->nid); + } + + /** + * Simpletest test. Tests to make sure the that revisions revert properly. + */ + function testRevisionRevert() { + extract( $this->prepareRevisions() ); + + $test_user = $this->drupalCreateUserRolePerm(array('revert revisions', 'edit any page content')); + $this->drupalLoginUser($test_user); + $this->drupalPost("node/$node->nid/revisions/$vid/revert", array(), 'Revert'); + $newnode = node_load($node->nid); + $this->assertTrue(($text == $newnode->body), 'Check to make sure reversions occur properly'); + + $this->cleanup($node->nid); + } + + /** + * Simpletest test. Tests to make sure the revision deletes properly. + */ + function testRevisionDelete() { + extract( $this->prepareRevisions() ); + + $test_user = $this->drupalCreateUserRolePerm(array('delete revisions', 'delete any page content')); + $this->drupalLoginUser($test_user); + $this->drupalPost("node/$node->nid/revisions/$vid/delete", array(), 'Delete'); + $this->assertTrue(db_result(db_query('SELECT COUNT(vid) FROM {node_revisions} WHERE nid = %d and VID = %d', $node->nid, $vid)) == 0, 'Check to make sure revisions delete properly'); $this->cleanup($node->nid); + + $this->cleanup($node->nid); + } + + /** + * Cleanup function used by tests. Deletes the associated node. + */ + function cleanup($nid) { + node_delete($nid); + } +} + +class NodeTeaserTest extends DrupalTestCase { + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => t('Node teaser tests'), + 'desc' => t('Calls node_teaser() with different strings and lengths.'), + 'group' => 'Node Tests', + ); + } + + function setUp() { + parent::setUp(); + } + + function tearDown() { + parent::tearDown(); + } + + /** + * Simpletest test. Tests an edge case where if the first sentence is a + * question and subsequent sentences are not. + * This failed in drupal 5. + * Test and patch for drupal 6 (committed) from + * http://drupal.org/node/180425 + */ + function testFirstSentenceQuestion() { + $body = 'A question? A sentence. Another sentence.'; + $expectedTeaser = 'A question? A sentence.'; + $this->callNodeTeaser($body, $expectedTeaser, NULL, 30); + } + + /** + * Simpletest test. A real-life example of the above edge case. + */ + function testFirstSentenceQuestion2() { + $body = 'Are you an UberBabe? (Or an appreciator of UberBabes?) I am most definitely an UberBabe, and I\'m proud of it. Now, before anyone screams "sexism" or "bias" or "cheap" or anything more profane, let me clarify. An UberBabe is not someone who\'s playfully pierced navel protrudes from a belly bearing top. Not necessarily anyway. An UberBabe is a woman who likes being totally feminine, but is also smart as hell, brave, a rule breaker, speaks her mind, finds her own way, goes up against "the system" in a way that allows the system to evolve, and so on. UberBabes, frankly, kick booty - and they just may save the world.'; + $expectedTeaser = 'Are you an UberBabe? (Or an appreciator of UberBabes?) I am most definitely an UberBabe, and I\'m proud of it. Now, before anyone screams "sexism" or "bias" or "cheap" or anything more profane, let me clarify.'; + $this->callNodeTeaser($body, $expectedTeaser, NULL, 300); + } + + /** + * Simpletest test. Runs a test adapted from + * http://drupal.org/node/180425#comment-634230 + */ + function testLength() { + // This body string tests a number of edge cases. + $body = "

\nHi\n

\n

\nfolks\n
\n!\n

"; + + // The teasers we expect node_teaser() to return when $size is the index + // of each array item. + // Using an input format with no line-break filter: + $teasers = array( + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "<", + "", + "

\n", + "

\nH", + "

\nHi", + "

\nHi\n", + "

\nHi\n<", + "

\nHi\n\nHi\n\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + ); + // And Using an input format WITH the line-break filter. + $teasers_lb = array( + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "<", + "", + "

", + "

", + "

", + "

\nHi", + "

\nHi", + "

\nHi", + "

\nHi", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + "

\nHi\n

\n

\nfolks\n
\n!\n

", + ); + + // Test node_teaser() for different sizes. + for ($i = 0; $i <= 37; $i++) { + $this->callNodeTeaser($body, $teasers[$i], NULL, $i); + $this->callNodeTeaser($body, $teasers_lb[$i], 1, $i); + $this->callNodeTeaser($body, $teasers_lb[$i], 2, $i); + } + } + + /** + * Calls node_teaser() and asserts that the expected teaser is returned. + */ + function callNodeTeaser($body, $expectedTeaser, $format = NULL, $size = NULL) { + $teaser = node_teaser($body, $format, $size); + $this->assertIdentical($teaser, $expectedTeaser); + } +} Index: tests/functional/module/user.test =================================================================== RCS file: tests/functional/module/user.test diff -N tests/functional/module/user.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/user.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,260 @@ + 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/functional/module/system.test =================================================================== RCS file: tests/functional/module/system.test diff -N tests/functional/module/system.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/system.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,233 @@ + 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/functional/module/page.test =================================================================== RCS file: tests/functional/module/page.test diff -N tests/functional/module/page.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/page.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,72 @@ + 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']))); + + } +} + +class PageViewTest extends DrupalTestCase { + /** + * Implementation of get_info() for information + */ + function get_info() { + return array( + 'name' => 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.' + . '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/functional/module/trigger.test =================================================================== RCS file: tests/functional/module/trigger.test diff -N tests/functional/module/trigger.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/trigger.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,69 @@ + t('Actions content'), + 'desc' => t('Perform various tests with content actions.') , + 'group' => 'Actions', + ); + } + + /** + * Various tests, all in one function to assure they happen in the right order. + */ + function testActionsContent() { + global $user; + + $this->drupalModuleEnable('trigger'); + + $content_actions = array('node_publish_action', 'node_unpublish_action', 'node_make_sticky_action', 'node_make_unsticky_action', 'node_promote_action', 'node_unpromote_action'); + + $hash = md5('node_publish_action'); + + $not_clean = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); + $this->assertFalse($not_clean, t('Actions were already assigned to the trigger. Unassign all content triggers before attempting to run again.')); + + if ($not_clean) { + return; + } + + // Test 1: Assign an action to a trigger, then pull the trigger, and make sure the actions fire. (Wow, those metaphors work out nicely). + + $test_user = $this->drupalCreateUserRolePerm(array('administer actions', 'create page content')); + $this->drupalLoginUser($test_user); + + // Set action id to "publish post". + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/node', $edit, 'Assign'); + + // Create an unpublished node. + $node = $this->drupalCreateNode(array('status' => 0)); + // Node should be published automatically. + $loaded_node = node_load($node->nid); + $this->assertTrue($loaded_node->status == 1, t('Check to make sure the node is automatically published')); + + // Leave action assigned for next test + + // Test 2: There should be an error when the action is assigned to the trigger twice. + + $edit = array('aid' => $hash); + $this->drupalPost('admin/build/trigger/node', $edit, 'Assign'); + $this->assertWantedRaw(t('The action you chose is already assigned to that trigger.'), t('Check to make sure an error occurs when assigning an action to a trigger twice.')); + + // Test 3: The action should be able to be unassigned from a trigger. + + // This effectively cleans up as well. + $this->drupalPost('admin/build/trigger/unassign/nodeapi/presave/'. $hash, array(), 'Unassign'); + $this->assertWantedRaw(t('Action %action has been unassigned.', array('%action' => 'Publish post')), t('Check to make sure action can be unassigned from trigger.')); + + $assigned = db_result(db_query("SELECT COUNT(*) FROM {trigger_assignments} WHERE aid IN ('". implode("','", $content_actions) ."')")); + $this->assertFalse($assigned, t('Check to make sure unassign worked properly at the database level.')); + } +} Index: tests/functional/module/blogapi.test =================================================================== RCS file: tests/functional/module/blogapi.test diff -N tests/functional/module/blogapi.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/blogapi.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,165 @@ + 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/functional/module/taxonomy.test =================================================================== RCS file: tests/functional/module/taxonomy.test diff -N tests/functional/module/taxonomy.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/taxonomy.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,384 @@ + 'Vocabulary functions', 'desc' => "Create/Edit/Delete a vocabulary and assert that all fields were properly saved" , 'group' => 'Taxonomy'); + } + + function testVocabularyFunctions() { + //preparing data + $vid = 0; + $name = $this->randomName(200); + $description = $this->randomName(200); + $help = $this->randomName(200); + $hierarchy = rand(0,2); // Hierarchy 0,1,2 + $multiple = rand(0,1); // multiple 0,1 + $required = rand(0,1); // required 0,1 + $relations = rand(0,1); + $tags = rand(0,1); + $weight = rand(-9,9); + $module = 'taxonomy'; + $nodesList = array_keys(node_get_types()); + $maxNodes = rand(1, count($nodesList)); + $nodes = array(); + for($i = 0; $i < $maxNodes; $i++) { + $nodes[$nodesList[$i]] = $nodesList[$i]; + $nodesBak[$nodesList[$i]] = $nodesList[$i]; + } + $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', + 'required', 'tags', 'module', 'weight', 'nodes'); + $edit = array(); + foreach($_t as $key ) + $edit[$key] = $$key; + + // exec save function + taxonomy_save_vocabulary($edit); + //after save we use $nodesBak + ksort($nodesBak); + $edit['nodes'] = $nodesBak; + $vocabularies = taxonomy_get_vocabularies(); + foreach($vocabularies as $voc) { + if ($voc->name == $name) { + $vid = $voc->vid; + break; + } + } + $edit['vid'] = $vid; + // get data using function + $getEdit = taxonomy_vocabulary_load($vid); + foreach($getEdit as $key => $value ) { + $this->assertEqual($value, $edit[$key],"Checking value of $key"); + } + + // delete vocabulary + // to avoid exception messages we create array with empty fields + $deleteArray = array(); + foreach($getEdit as $key => $v) + $deleteArray[$key] = 0; + $deleteArray['vid'] = $vid; + taxonomy_save_vocabulary($deleteArray); + // checking if we deleted voc. + $vocabularies = taxonomy_get_vocabularies(); + $vid = 0; + foreach($vocabularies as $voc) { + if ($voc->name == $name) { + $vid = $voc->vid; + break; + } + } + $this->assertEqual($vid, 0, "Deleted vocabulary ($vid)"); + + } +} + + +class TaxonomyTermFunctions extends DrupalTestCase { + function get_info() { + return array('name' => 'Term functions', 'desc' => "Testing save/update/delete terms" , 'group' => 'Taxonomy'); + } + + function testTermsFunctions() { + //preparing data + // vocabulary, hierarchy -> disabled, related terms = on; + $edit = array(); + $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', + 'required', 'tags', 'module', 'weight', 'nodes'); + foreach($_t as $key ) { + $edit[$key] = 0; + } + $name = $this->randomName(20); + $relation = 1; + $edit['name'] = $name; + taxonomy_save_vocabulary($edit); + + // create term + $termname = $this->randomName(20); + $termdesc = $this->randomName(200); + $termweight = rand(-9, 9); + $randSyn = rand(0, 9); + $synonyms = array(); + for($i = 0; $i < $randSyn; $i++) { + $synonyms[] = $this->randomName(20); + } + $termsyn = implode("\n", $synonyms); + $data = array('name' => $termname, 'description' => $termdesc, 'weight' => $termweight, 'synonyms' => $termsyn, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + + // retrieve term and check all fields + $_tArray = taxonomy_get_term_by_name($termname); + $getTerm = $_tArray[0]; + $checkField = array('name', 'description', 'weight', 'vid'); + foreach($checkField as $v) { + $this->assertEqual($data[$v], $getTerm->$v, "Checking value of the term ($v)"); + } + $getSynonyms = taxonomy_get_synonyms($getTerm->tid); + $this->assertEqual(sort($synonyms), sort($getSynonyms), 'Checking synonyms'); + + // creating related terms + $relations = array(); + $staryTid = $getTerm->tid; + $relations[] = $staryTid; + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => 0, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => array($staryTid)); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $getTerm = $_tArray[0]; + $relations[] = $getTerm->tid; + + // Creating another term related to 2 terms above; + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => 0, 'vid' => $edit['vid'], 'tid' => 0, 'relations' => array($staryTid, $getTerm->tid)); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $getTerm = $_tArray[0]; + + // check related terms + $related = taxonomy_get_related($getTerm->tid); + foreach($relations as $rTid) { + $this->assertTrue(array_key_exists($rTid, $related), "Checking relations ($rTid)"); + } + + // delete vocabulary + $edit['name'] = 0; + taxonomy_save_vocabulary($edit); + } + + function testTermsFunctionsSingleHierarchy() { + //preparing data + // vocabulary hierarchy->single + $edit = array(); + $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', + 'required', 'tags', 'module', 'weight', 'nodes'); + foreach($_t as $key ) { + $edit[$key] = 0; + } + + // create vocab + $name = $this->randomName(20); + $edit['hierarchy'] = 1; + $edit['name'] = $name; + taxonomy_save_vocabulary($edit); + + // create 1st term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent = $_tArray[0]; + + // create 2nd term as a child + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0, 'parent' => array($parent->tid)); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $children = $_tArray[0]; + + // check hierarchy + $getChildren = taxonomy_get_children($parent->tid); + $getParent = taxonomy_get_parents($children->tid); + $this->assertEqual($parent,$getParent[$parent->tid], 'Checking parents'); + $this->assertEqual($children,$getChildren[$children->tid], 'Checking children'); + + // delete vocabulary + $edit['name'] = 0; + taxonomy_save_vocabulary($edit); + } + + function testTermsFunctionsMultipleHierarchy() { + //preparing data + // vocabulary hierarchy->single + $edit = array(); + $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', + 'required', 'tags', 'module', 'weight', 'nodes'); + foreach($_t as $key ) + $edit[$key] = 0; + + $name = $this->randomName(20); + $edit['hierarchy'] = 1; + $edit['name'] = $name; + taxonomy_save_vocabulary($edit); + + // create 1st term + $parent = array(); + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[] = $_tArray[0]->tid; + + // create 2nd term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[] = $_tArray[0]->tid; + + // create 3rd term as a child + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $edit['vid'], 'tid' => 0, 'relations' => 0, 'parent' => array($parent)); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $children = $_tArray[0]; + + $getParent = taxonomy_get_parents($children->tid); + foreach($parent as $p) { + $this->assertTrue(array_key_exists($p, $getParent), "Checking parents ($p)"); + //$this->assertEqual($parent,$getParent[$parent->tid], 'Checking parents'); + } + + // delete vocabulary + $edit['name'] = 0; + taxonomy_save_vocabulary($edit); + } + +} + +class TaxonomyTestNodeApi extends DrupalTestCase { + function get_info() { + return array('name' => 'Taxonomy nodeapi', 'desc' => "Save & edit a node and assert that taxonomy terms are saved/loaded properly." , 'group' => 'Taxonomy'); + } + + function testTaxonomyNode() { + + //preparing data + // vocabulary hierarchy->single, multiple -> on + $edit = array(); + $_t = array('vid', 'name', 'description', 'help', 'relations', 'hierarchy', 'multiple', + 'required', 'tags', 'module', 'weight', 'nodes'); + foreach($_t as $key) { + $edit[$key] = 0; + } + + $name = $this->randomName(20); + $edit['hierarchy'] = 1; + $edit['multiple'] = 1; + $edit['name'] = $name; + $edit['nodes'] = array('story' => 'story'); + taxonomy_save_vocabulary($edit); + $vid = $edit['vid']; // we need to persist vid after $edit is unset() + + $parent = array(); + $patternArray = array(); + + // create 1st term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[$_tArray[0]->tid] = $_tArray[0]->tid; + $patternArray['term name 1'] = $termname; + + // create 2nd term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[$_tArray[0]->tid] = $_tArray[0]->tid; + $patternArray['term name 2'] = $termname; + + // create test user and login + $perm = array('access content', 'create story content', 'edit own story content', 'delete own story content'); + $account = $this->drupalCreateUserRolePerm($perm); + $this->drupalLoginUser($account); + + // why is this printing out the user profile page? + // go to node/add/story + $this->drupalGet('node/add/story'); + $req = $this->_browser->getRequest(); + + $headers = $this->_browser->getHeaders(); + + $content = $this->drupalGetContent(); +// print($content). "\n\n\n all done \n\n"; + + // try to create story + $title = $this->randomName(); + $body = $this->randomName(100); + $edit = array('title' => $title, 'body' => $body, 'taxonomy-' . $vid => $parent); + + // multiple slect box was failing through drupalPost. Use raw POST instead + // Failing because they were being sent/handled wrong (earnest.berry@gmail.com ) + $action = url('node/add/story', array('absolute' => TRUE)); + $this->drupalPost($action, $edit, 'Save'); + $content = $this->drupalGetContent(); + $patternArray['body text'] = $body; + $patternArray['title'] = $title; + +// $node = array2object(node_load(array('title' => $title))); + $node = node_load(array('title' => $title)); + + $this->_browser->get(url("node/$node->nid")); + foreach($patternArray as $name => $termPattern) { + $this->assertText($termPattern, "Checking $name"); + } + + // checking database fields + $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $node->nid); + while ($nodeRow = db_fetch_array($result)) { + $this->assertTrue(in_array($nodeRow['tid'], $parent), 'Checking database record'); + } + + // ok, lets create new terms, and change this node + //pop array + array_pop($parent); + + // create 1st term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[] = $_tArray[0]->tid; + $patternArray['term name 2'] = $termname; + + // create 2nd term + $termname = $this->randomName(20); + $data = array('name' => $termname, 'description' => '', 'weight' => 0, 'synonyms' => '', 'vid' => $vid, 'tid' => 0, 'relations' => 0); + taxonomy_save_term($data); + $_tArray = taxonomy_get_term_by_name($termname); + $parent[] = $_tArray[0]->tid; + $patternArray['term name 3'] = $termname; + + $edit = array('title' => $title, 'body' => $body, 'taxonomy-' . $vid => $parent); + + $this->drupalPost('node/'. $node->nid .'/edit', $edit, 'Save'); + + // TODO Do a MUCH better check here of the information msg + $patternArray['information message'] = 'been updated'; + foreach($patternArray as $name => $termPattern) { + $this->assertText($termPattern, "Checking $name"); + } + + // checking database fields + $result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $node->nid); + while ($nodeRow = db_fetch_array($result)) { + $this->assertTrue(in_array($nodeRow['tid'], $parent), 'Checking database field'); + } + + // delete node through browser + $this->drupalPost('node/'. $node->nid .'/delete', array(), 'Delete' ); + // checking after delete + $this->_browser->get(url("node/".$node->nid)); + $this->assertNoUnwantedText($termname, "Checking if node exists"); + // checking database fields + $num_rows = db_result(db_query('SELECT COUNT(*) FROM {term_node} WHERE nid = %d', $node->nid)); + $this->assertEqual($num_rows, 0, 'Checking database field after deletion'); + + // delete vocabulary + // to avoid exception messages create array with empty fields + $edit = array(); + foreach($_t as $key ) { + $edit[$key] = 0; + } + $edit['name'] = 0; + $edit['vid'] = $vid; + taxonomy_save_vocabulary($edit); + + // restoring status + $this->drupalModuleDisable('story'); + } + +} + + +?> Index: tests/functional/module/comment.test =================================================================== RCS file: tests/functional/module/comment.test diff -N tests/functional/module/comment.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/comment.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,375 @@ + 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 .= 'subject .'(.*?)'; // Match subject. + $regex .= $comment->comment .'(.*?)'; // Match comment. + $regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div. + return preg_match($regex, $this->drupalGetContent()); + } + else { + return FALSE; + } + } + + /** + * Delete comment. + * + * @param object $comment Comment to delete. + */ + function delete_comment($comment) { + $this->drupalPost('comment/delete/'. $comment->id, array(), 'Delete'); + $this->assertWantedText(t('The comment and all its replies have been deleted.'), 'Comment deleted.'); + } + + /** + * Set comment subject setting. + * + * @param boolean $enabled Subject value. + */ + function set_comment_subject($enabled) { + $this->set_comment_settings('comment_subject_field', ($enabled ? '1' : '0'), 'Comment subject '. ($enabled ? 'enabled' : 'disabled') .'.'); + } + + /** + * Set comment preview setting. + * + * @param boolean $required Preview value. + */ + function set_comment_preview($required) { + $this->set_comment_settings('comment_preview', ($required ? '1' : '0'), 'Comment preview '. ($required ? 'required' : 'optional') .'.'); + } + + /** + * Set comment form setting. + * + * @param boolean $enabled Form value. + */ + function set_comment_form($enabled) { + $this->set_comment_settings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls '. ($enabled ? 'enabled' : 'disabled') .'.'); + } + + /** + * Set comment anonymous level setting. + * + * @param integer $level Anonymous level. + */ + function set_comment_anonymous($level) { + $this->set_comment_settings('comment_anonymous', $level, 'Anonymous commenting set to level '. $level .'.'); + } + + /** + * Set comment setting for story content type. + * + * @param string $name Name of variable. + * @param string $vale Value of variable. + * @param string $message Status message to display. + */ + function set_comment_settings($name, $value, $message) { + $this->drupalVariableSet($name .'_story', $value); + $this->assertTrue(TRUE, $message); // Display status message. + } + + /** + * Set anonymous comment setting. + * + * @param boolean $enabled Allow anonymous commenting. + * @param boolean $without_approval Allow anonymous commenting without approval. + */ + function set_anonymous_user_comment($enabled, $without_approval) { + $edit = array(); + $edit['1-access-comments'] = $enabled; + $edit['1-post-comments'] = $enabled; + $edit['1-post-comments-without-approval'] = $without_approval; + $this->drupalPost('admin/user/permissions', $edit, 'Save permissions'); + $this->assertText(t('The changes have been saved.'), 'Anonymous user comments '. ($enabled ? 'enabled' : 'disabled') .'.'); + } + + /** + * Check for contact info. + * + * @return boolean Contact info is avialable. + */ + function comment_contact_info_available() { + return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent()); + } + + /** + * Perform the specified operation on the specified comment. + * + * @param object $comment Comment to perform operation on. + * @param string $operation Operation to perform. + * @param boolean $aproval Operation is found on approval page. + */ + function perform_comment_operation($comment, $operation, $approval = FALSE) { + $edit = array(); + $edit['operation'] = $operation; + $edit['comments['. $comment->id .']'] = TRUE; + $this->drupalPost('admin/content/comment'. ($approval ? '/approval' : ''), $edit, 'Update'); + + if ($operation == 'delete') { + $this->drupalPost(NULL, array(), 'Delete comments'); + $this->assertText(t('The comments have been deleted.'), 'Operation "'. $operation .'" was performed on comment.'); + } + else { + $this->assertText(t('The update has been performed.'), 'Operation "'. $operation .'" was performed on comment.'); + } + } + + /** + * Get the comment id for an unaproved comment. + * + * @param string $subject Comment subject to find. + * @return integer Comment id. + */ + function get_unaproved_comment($subject) { + $this->drupalGet('admin/content/comment/approval'); + preg_match('/href="(.*?)#comment-([^"]+)"(.*?)>('. $subject .')/', $this->drupalGetContent(), $match); + return $match[2]; + } +} Index: tests/functional/module/path.test =================================================================== RCS file: tests/functional/module/path.test diff -N tests/functional/module/path.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/path.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,144 @@ + 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/functional/module/poll.test =================================================================== RCS file: tests/functional/module/poll.test diff -N tests/functional/module/poll.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/module/poll.test 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,91 @@ +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'); + } +}