t('Add forum container'), 'desc' => 'Adds a container for forums and verifies that the container has been created.', 'group' => 'Forum'); } function testAddForumContainer () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // Attempt to create a forum container $web_user = $this->drupalCreateUserRolePerm(array ( 'access administration pages', 'administer forums', )); $this->drupalLoginUser($web_user); // 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->drupalPostRequest('admin/content/forum/add/container', $edit, 'Save'); $this->assertWantedRaw('Created new forum container '. $title .'.', t('New forum container has been created')); // Loop through to find the newly inserted container $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a container $this->assertTrue(!empty($term), 'The container actually exists in the database'); // Delete the forum container we created if (!empty($term)) taxonomy_del_term($term['tid']); } } class AddForumTest extends DrupalTestCase { /** * Implementation of get_info() for information */ function get_info() { return array('name' => t('Add forum'), 'desc' => 'Adds a forum and verifies that the forum has been created.', 'group' => 'Forum'); } function testAddForum () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // Attempt to create a forum $web_user = $this->drupalCreateUserRolePerm(array ( 'access administration pages', 'administer forums', )); $this->drupalLoginUser($web_user); // 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->drupalPostRequest('admin/content/forum/add/forum', $edit, 'Save'); $this->assertWantedRaw('Created new forum '. $title .'.', t('New forum has been created')); // Loop through to find the newly inserted forum $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a forum $this->assertTrue(!empty($term), 'The forum actually exists in the database'); // Delete the forum we created if (!empty($term)) taxonomy_del_term($term['tid']); } } class EditForumTaxonomyTest extends DrupalTestCase { /** * 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 () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // 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->drupalPostRequest('admin/content/taxonomy/edit/vocabulary/'. $vid, $edit, 'Save'); $this->assertWantedRaw('Updated vocabulary '. $title .'.', t('Vocabulary has been edited')); // Loop through to find the newly edited vocabulary $result = db_query('SELECT v.* FROM {vocabulary} v WHERE v.vid = %d', $vid); $cur_settings = db_fetch_array($result); // 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, and use it as an opportunity to test the form again $edit = array ( 'name' => $original_settings->name, 'description' => $original_settings->description, 'help' => $original_settings->help, 'weight' => $original_settings->weight ); // Double check that the page says it has edited the vocabulary $this->drupalPostRequest('admin/content/taxonomy/edit/vocabulary/'. $vid, $edit, 'Save'); $this->assertWantedRaw('Updated vocabulary '. $original_settings->name .'.', t('Vocabulary has been edited')); } } class AddTopicToForum extends DrupalTestCase { /** * Implementation of get_info() for information */ function get_info() { return array('name' => t('Add topic to forum'), 'desc' => 'Attempts to create a new forum topic.', 'group' => 'Forum'); } function testAddTopicToForum () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // Attempt to create a forum $web_user = $this->drupalCreateUserRolePerm(array ( 'access administration pages', 'administer forums', 'create forum topics' )); $this->drupalLoginUser($web_user); // 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->drupalPostRequest('admin/content/forum/add/forum', $edit, 'Save'); $this->assertWantedRaw('Created new forum '. $title .'.', t('New forum has been created')); // Loop through to find the newly inserted forum $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a forum $this->assertTrue(!empty($term), 'The forum actually exists in the database'); // 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->drupalPostRequest('node/add/forum/'. $term['tid'], $edit, 'Save'); $this->assertWantedRaw('Forum topic '. $title .' has been created.', t('New forum topic has been created')); $this->assertNoUnwantedRaw('The item '. $term['name'] .' is only a container for forums.', 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(url('node/'. $new_topic->nid, array('absolute' => TRUE))); $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($term)) taxonomy_del_term($term['tid']); } } class AddTopicToContainerTest extends DrupalTestCase { /** * Implementation of get_info() for information */ function get_info() { return array('name' => t('Add topic to forum container'), 'desc' => 'Attempts to add a topic to a container, which should fail.', 'group' => 'Forum'); } function testAddTopicToContainer () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // Attempt to create a forum container $web_user = $this->drupalCreateUserRolePerm(array ( 'access administration pages', 'administer forums', 'create forum topics' )); $this->drupalLoginUser($web_user); // 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->drupalPostRequest('admin/content/forum/add/container', $edit, 'Save'); $this->assertWantedRaw('Created new forum container '. $title .'.', t('New forum container has been created')); // Loop through to find the newly inserted container $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a container $this->assertTrue(!empty($term), 'The container actually exists in the database'); // 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->drupalPostRequest('node/add/forum/'. $term['tid'], $edit, 'Save'); $this->assertNoUnwantedRaw('Forum topic '. $title .' has been created.', t('No "new forum topic has been created" message')); $this->assertWantedRaw('The item '. $term['name'] .' is only a container for forums.', 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($term)) taxonomy_del_term($term['tid']); } } class MoveTopicToForum extends DrupalTestCase { /** * Implementation of get_info() for information */ function get_info() { return array('name' => t('Move topic to forum'), 'desc' => 'Moves a topic from one forum to another.', 'group' => 'Forum'); } function testMoveTopicToForum () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // 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->drupalPostRequest('node/add/forum/'. $forum1['tid'], $edit, 'Save'); $this->assertWantedRaw('Forum topic '. $title .' has been created.', t('New forum topic has been created')); $this->assertNoUnwantedRaw('The item '. $forum1['name'] .' is only a container for forums.', 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->drupalPostRequest('node/'. $new_topic->nid .'/edit', $edit, 'Save'); $this->assertWantedRaw('Forum topic '. $title .' has been updated.', 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 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->drupalPostRequest('admin/content/forum/add/forum', $edit, 'Save'); $this->assertWantedRaw('Created new forum '. $title .'.', t('New forum has been created')); // Loop through to find the newly inserted forum $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a forum $this->assertTrue(!empty($term), 'The forum actually exists in the database'); return $term; } } class MoveTopicWithShadowToForum extends DrupalTestCase { /** * Implementation of get_info() for information */ function get_info() { return array('name' => t('Move topic to forum with shadow copy'), 'desc' => 'Moves a topic from one forum to another and leaves behind a shadow copy.', 'group' => 'Forum'); } function testMoveTopicWithShadowToForum () { // Enable the forum module and its dependencies $this->drupalModuleEnable('taxonomy'); $this->drupalModuleEnable('comment'); $this->drupalModuleEnable('forum'); // 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->drupalPostRequest('node/add/forum/'. $forum1['tid'], $edit, 'Save'); $this->assertWantedRaw('Forum topic '. $title .' has been created.', t('New forum topic has been created')); $this->assertNoUnwantedRaw('The item '. $forum1['name'] .' is only a container for forums.', 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'], 'shadow' => '1', 'body' => $description ); // Double check that the page says it has updated the topic // Also, double check that the new and old forum names are there $this->drupalPostRequest('node/'. $new_topic->nid .'/edit', $edit, 'Save'); $this->assertWantedRaw('Forum topic '. $title .' has been updated.', t('Topic has been moved')); $this->assertWantedRaw($forum2['name'], t('New forum name is present')); $this->assertWantedRaw($forum1['name'], t('Old forum name is present')); // Make sure that the shadow topic exists $new_topic = node_load(array('title' => $title), null, true); $this->assertTrue($new_topic->forum_tid != $new_topic->tid, t('Shadow topic exists')); // 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 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->drupalPostRequest('admin/content/forum/add/forum', $edit, 'Save'); $this->assertWantedRaw('Created new forum '. $title .'.', t('New forum has been created')); // Loop through to find the newly inserted forum $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name, t.description, t.weight FROM {term_data} t WHERE t.vid = %d', 't', 'tid'), variable_get('forum_nav_vocabulary', '')); $term = array(); while ($cur_term = db_fetch_array($result)) { if ($cur_term['name'] == $title && $cur_term['description'] == $description) { $term = $cur_term; break; } } // Make sure we actually found a forum $this->assertTrue(!empty($term), 'The forum actually exists in the database'); return $term; } }