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']); } }