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->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');
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->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 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->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 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->drupalPostRequest('node/add/forum/'. $forum['tid'], $edit, 'Save');
$this->assertWantedRaw('Forum topic '. $title .' has been created.', t('New forum topic has been created'));
$this->assertNoUnwantedRaw('The item '. $forum['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($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->drupalPostRequest('node/add/forum/'. $container['tid'], $edit, 'Save');
$this->assertNoUnwantedRaw('Forum topic '. $title .' has been created.', t('No "new forum topic has been created" message'));
$this->assertWantedRaw('The item '. $container['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($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->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 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->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']);
}
}