View source
<?php
class DrupalForumTestCase extends DrupalTestCase {
function get_info() {
return array(
'name' => 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();
$this
->drupalModuleEnable('taxonomy');
$this
->drupalModuleEnable('comment');
$this
->drupalModuleEnable('forum');
}
function createForumContainer() {
$title = $this
->randomName(10);
$description = $this
->randomName(100);
$edit = array(
'name' => $title,
'description' => $description,
'parent[0]' => '0',
'weight' => '0',
);
$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'));
$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));
$this
->assertTrue(!empty($term), 'The container actually exists in the database');
return $term;
}
function createForum() {
$title = $this
->randomName(10);
$description = $this
->randomName(100);
$edit = array(
'name' => $title,
'description' => $description,
'parent[0]' => '0',
'weight' => '0',
);
$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'));
$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));
$this
->assertTrue(!empty($term), 'The forum actually exists in the database');
return $term;
}
}
class AddForumTest extends DrupalForumTestCase {
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() {
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer forums',
));
$this
->drupalLoginUser($web_user);
$container = $this
->createForumContainer();
if (!empty($container)) {
taxonomy_del_term($container['tid']);
}
}
function testAddForum() {
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer forums',
));
$this
->drupalLoginUser($web_user);
$forum = $this
->createForum();
if (!empty($forum)) {
taxonomy_del_term($forum['tid']);
}
}
}
class EditForumTaxonomyTest extends DrupalForumTestCase {
function get_info() {
return array(
'name' => t('Edit forum taxonomy'),
'desc' => 'Edits the forum taxonomy.',
'group' => 'Forum',
);
}
function testEditForumTaxonomy() {
$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);
$title = $this
->randomName(10);
$description = $this
->randomName(100);
$edit = array(
'name' => $title,
'description' => $description,
'help' => '',
'weight' => -10,
);
$this
->drupalPost('admin/content/taxonomy/edit/vocabulary/' . $vid, $edit, 'Save');
$this
->assertWantedRaw(t('Updated vocabulary %name.', array(
'%name' => $title,
)), t('Vocabulary has been edited'));
$cur_settings = db_fetch_array(db_query('SELECT v.* FROM {vocabulary} v WHERE v.vid = %d', $vid));
$this
->assertTrue($cur_settings['name'] == $title, 'The name has been updated properly');
$this
->assertTrue($cur_settings['description'] == $description, 'The description has been updated properly');
$original_settings = (array) $original_settings;
taxonomy_save_vocabulary($original_settings);
}
}
class AddTopicToForum extends DrupalForumTestCase {
function get_info() {
return array(
'name' => t('Add/move topics'),
'desc' => 'Tests adding and moving topics within forums.',
'group' => 'Forum',
);
}
function testAddTopicToForum() {
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer forums',
'create forum topics',
));
$this
->drupalLoginUser($web_user);
$forum = $this
->createForum();
$title = $this
->randomName(20);
$description = $this
->randomName(200);
$edit = array(
'title' => $title,
'body' => $description,
);
$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'));
$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'));
node_delete($new_topic->nid);
if (!empty($forum)) {
taxonomy_del_term($forum['tid']);
}
}
function testAddTopicToContainer() {
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer forums',
'create forum topics',
));
$this
->drupalLoginUser($web_user);
$container = $this
->createForumContainer();
$title = $this
->randomName(20);
$description = $this
->randomName(200);
$edit = array(
'title' => $title,
'body' => $description,
);
$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'));
$new_topic = node_load(array(
'title' => $title,
), null, true);
$this
->assertTrue(empty($new_topic), t('There is no new topic'));
if (!empty($container)) {
taxonomy_del_term($container['tid']);
}
}
function testMoveTopicToForum() {
$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();
$title = $this
->randomName(20);
$description = $this
->randomName(200);
$edit = array(
'title' => $title,
'body' => $description,
);
$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'));
$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,
);
$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'));
node_delete($new_topic->nid);
if (!empty($forum1)) {
taxonomy_del_term($forum1['tid']);
}
if (!empty($forum2)) {
taxonomy_del_term($forum2['tid']);
}
}
function testMoveTopicWithCopyToForum() {
$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();
$title = $this
->randomName(20);
$description = $this
->randomName(200);
$edit = array(
'title' => $title,
'body' => $description,
);
$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'));
$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,
);
$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'));
node_delete($new_topic->nid);
if (!empty($forum1)) {
taxonomy_del_term($forum1['tid']);
}
if (!empty($forum2)) {
taxonomy_del_term($forum2['tid']);
}
}
}