Skip to content

Commit

Permalink
Test units: check whether number of old forum items equals number of …
Browse files Browse the repository at this point in the history
…fluxbb items
  • Loading branch information
daris committed Jan 31, 2012
1 parent 5c35238 commit 3ee265d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
define('FORUM_SI_REVISION', 2);
define('FORUM_PARSER_REVISION', 2);

class Invision_Power_Board_3_2 extends Forum
class IP_Board_3_2 extends Forum
{
// Will the passwords be converted?
const CONVERTS_PASSWORD = false;
Expand All @@ -22,7 +22,7 @@ class Invision_Power_Board_3_2 extends Forum
'bans' => array('banfilters', 'ban_id'),
'categories' => array('forums', 'id', 'parent_id = -1'),
'censoring' => array('badwords', 'wid'),
'config' => 0,
'config' => -1,
'forums' => array('forums', 'id', 'parent_id <> -1'),
// 'forum_perms' => 0,
'groups' => array('groups', 'g_id', 'g_id > 6'),
Expand Down
2 changes: 1 addition & 1 deletion forums/MyBB_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MyBB_1 extends Forum
'bans' => array('banned', 'uid'),
'categories' => array('forums', 'fid', 'type = \'c\''),
'censoring' => 0,//array('words', 'word_id'),
'config' => 0,
'config' => -1,
'forums' => array('forums', 'fid', 'type = \'f\''),
// 'forum_perms' => 0,
'groups' => array('usergroups', 'gid', 'gid > 7'),
Expand Down
2 changes: 1 addition & 1 deletion forums/PHP_Fusion_7.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PHP_Fusion_7 extends Forum
'bans' => array('blacklist', 'blacklist_id'),
'categories' => array('forums', 'forum_id', 'forum_cat = 0'),
'censoring' => -1,
'config' => 0,
'config' => -1,
'forums' => array('forums', 'forum_id', 'forum_cat <> 0'),
// 'forum_perms' => 0,
'groups' => array('user_groups', 'group_id'),
Expand Down
2 changes: 1 addition & 1 deletion forums/SMF_1_1_11.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SMF_1_1_11 extends Forum
'bans' => array('ban_items', 'ID_BAN'),
'categories' => array('categories', 'ID_CAT'),
'censoring' => -1,
'config' => 0,
'config' => -1,
'forums' => array('boards', 'ID_BOARD'),
// 'forum_perms' => 0,
'groups' => array('membergroups', 'ID_GROUP', 'minPosts = -1 AND ID_GROUP > 3'),
Expand Down
2 changes: 1 addition & 1 deletion forums/SMF_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SMF_2 extends Forum
'bans' => array('ban_items', 'id_ban'),
'categories' => array('categories', 'id_cat'),
'censoring' => -1,
'config' => 0,
'config' => -1,
'forums' => array('boards', 'id_board'),
// 'forum_perms' => 0,
'groups' => array('membergroups', 'id_group', 'min_posts = -1 AND id_group > 3'),
Expand Down
2 changes: 1 addition & 1 deletion forums/vBulletin_4_1_5.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VBulletin_4_1_5 extends Forum
'bans' => array('userban', 'userid'),
'categories' => array('forum', 'forumid', 'parentid = -1'),
'censoring' => 0,//array('words', 'word_id'),
'config' => 0,
'config' => -1,
'forums' => array('forum', 'forumid', 'parentid <> -1'),
// 'forum_perms' => 0,
'groups' => array('usergroup', 'usergroup', 'usergroupid > 8'),
Expand Down
16 changes: 16 additions & 0 deletions include/converter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ function finish()
$_SESSION['fluxbb_converter']['time'] = get_microtime() - $_SESSION['fluxbb_converter']['start_time'];
}

function get_forum_item_count()
{
if (isset($_SESSION['fluxbb_converter']['count']))
return $_SESSION['fluxbb_converter']['count'];
else
return $_SESSION['fluxbb_converter']['count'] = $this->forum->fetch_count();
}

function get_fluxbb_item_count()
{
if (isset($_SESSION['fluxbb_converter']['fluxbb_count']))
return $_SESSION['fluxbb_converter']['fluxbb_count'];
else
return $_SESSION['fluxbb_converter']['fluxbb_count'] = $this->fluxbb->fetch_count();
}

/**
* Regenerate FluxBB cache after conversion
*/
Expand Down
6 changes: 5 additions & 1 deletion include/fluxbb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FluxBB
'bans' => array('id'),
'categories' => array('id'),
'censoring' => array('id'),
'config' => 0,
'config' => -1,
'forums' => array('id'),
'forum_perms' => array('forum_id'),
'groups' => array('g_id', 'g_id > 4'),
Expand Down Expand Up @@ -72,6 +72,10 @@ function fetch_count()
foreach ($this->tables as $cur_table => $table_info)
{
$count = 0;

if (is_numeric($table_info))
$count = $table_info;

if (is_array($table_info))
{
$query = array(
Expand Down
6 changes: 5 additions & 1 deletion include/forum.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ function fetch_count()
foreach ($this->steps as $cur_step => $table_info)
{
$count = 0;
if (is_array($table_info))

if (is_numeric($table_info))
$count = $table_info;

else if (is_array($table_info))
{
$query = array(
'SELECT' => 'COUNT('.$this->db->escape($table_info[1]).')',
Expand Down
82 changes: 47 additions & 35 deletions tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,65 +64,77 @@
// Load converter script
require CONV_ROOT.'include/converter.class.php';

function convert($forum_type, $old_db_name, $old_db_prefix)
class ConverterTest extends PHPUnit_Framework_TestCase
{
global $old_db_config, $pun_config, $db_config, $db, $forum_config, $converter;

$fluxbb = new FluxBB($pun_config);
$db = $fluxbb->connect_database($db_config);

echo "\n\n".$forum_type.': '.$old_db_name."\n\n";
$forum_config['type'] = $forum_type;
$old_db_config['name'] = $old_db_name;
$old_db_config['prefix'] = $old_db_prefix;
$forum = load_forum($forum_config, $fluxbb);
$forum->connect_database($old_db_config);

$converter = new Converter($fluxbb, $forum);

// Start the converter
$redirect = array(null);
while ($redirect !== false)
protected function convert($forum_type, $old_db_name, $old_db_prefix)
{
conv_message();
conv_log('-----------------'."\n");
$redirect = $converter->convert($redirect[0], isset($redirect[1]) ? $redirect[1] : 0);
global $old_db_config, $pun_config, $db_config, $db, $forum_config;

$fluxbb = new FluxBB($pun_config);
$db = $fluxbb->connect_database($db_config);

echo "\n\n".$forum_type.': '.$old_db_name."\n\n";
$forum_config['type'] = $forum_type;
$old_db_config['name'] = $old_db_name;
$old_db_config['prefix'] = $old_db_prefix;
$forum = load_forum($forum_config, $fluxbb);
$forum->connect_database($old_db_config);

$converter = new Converter($fluxbb, $forum);

// Start the converter
$next_step = array(null);
while ($next_step !== false)
{
conv_message();
conv_log('-----------------'."\n");
$next_step = $converter->convert($next_step[0], isset($next_step[1]) ? $next_step[1] : 0);
}

$fluxbb_item_count = $converter->get_fluxbb_item_count();
$forum_item_count = $converter->get_forum_item_count();

foreach ($fluxbb_item_count as $table => $fluxbb_count)
{
if (!isset($forum_item_count[$table]))
continue;

$forum_count = $forum_item_count[$table];
if ($fluxbb_count != -1 && $forum_count != -1)
$this->assertEquals($fluxbb_count, $forum_count, 'Different item count for '.$table);
}

$forum->close_database();
$fluxbb->close_database();
}

$forum->close_database();

$fluxbb->close_database();
}

class ConverterTest extends PHPUnit_Framework_TestCase
{
function testMyBB()
{
convert('MyBB_1', 'mybb__test', 'mybb_');
$this->convert('MyBB_1', 'mybb__test', 'mybb_');
}

function testFusion()
function testPhpFusion()
{
convert('PHP_Fusion_7', 'fusion__test', 'fusion_');
$this->convert('PHP_Fusion_7', 'fusion__test', 'fusion_');
}

function testPhpbb3()
{
convert('PhpBB_3_0_9', 'phpbb__test', 'phpbb_');
$this->convert('PhpBB_3_0_9', 'phpbb__test', 'phpbb_');
}

function testPunBB()
{
convert('PunBB_1.3_1.4', 'punbb__test', 'pun_');
$this->convert('PunBB_1.3_1.4', 'punbb__test', 'pun_');
}

function testSmf1()
{
convert('SMF_1_1_11', 'smf1__test', 'smf_');
$this->convert('SMF_1_1_11', 'smf1__test', 'smf_');
}

function testSmf2()
{
convert('SMF_2', 'smf2__test', 'smf_');
$this->convert('SMF_2', 'smf2__test', 'smf_');
}
}

0 comments on commit 3ee265d

Please sign in to comment.