1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-12 18:45:20 +02:00

Merge branch 'ticket/11103' of github.com:EXreaction/phpbb3 into ticket/11103

This commit is contained in:
Nathan Guse 2012-12-15 18:25:51 -06:00
commit c9ca705149
12 changed files with 777 additions and 48 deletions

View File

@ -0,0 +1,206 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Updates rows in given table from a set of values to a new value.
* If this results in rows violating uniqueness constraints, the duplicate
* rows are eliminated.
*
* The only supported table is bookmarks.
*
* @param dbal $db Database object
* @param string $table Table on which to perform the update
* @param string $column Column whose values to change
* @param array $from_values An array of values that should be changed
* @param int $to_value The new value
* @return null
*/
function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_values, $to_value)
{
$sql = "SELECT $column, user_id
FROM $table
WHERE " . $db->sql_in_set($column, $from_values);
$result = $db->sql_query($sql);
$old_user_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$old_user_ids[$row[$column]][] = (int) $row['user_id'];
}
$db->sql_freeresult($result);
$sql = "SELECT $column, user_id
FROM $table
WHERE $column = " . (int) $to_value;
$result = $db->sql_query($sql);
$new_user_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$new_user_ids[$row[$column]][] = (int) $row['user_id'];
}
$db->sql_freeresult($result);
$queries = array();
foreach ($from_values as $from_value)
{
if (!isset($old_user_ids[$from_value]))
{
continue;
}
if (empty($new_user_ids))
{
$sql = "UPDATE $table
SET $column = " . (int) $to_value . "
WHERE $column = '" . $db->sql_escape($from_value) . "'";
$queries[] = $sql;
}
else
{
$different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]);
if (!empty($different_user_ids))
{
$sql = "UPDATE $table
SET $column = " . (int) $to_value . "
WHERE $column = '" . $db->sql_escape($from_value) . "'
AND " . $db->sql_in_set('user_id', $different_user_ids);
$queries[] = $sql;
}
}
}
if (!empty($queries))
{
$db->sql_transaction('begin');
foreach ($queries as $sql)
{
$db->sql_query($sql);
}
$sql = "DELETE FROM $table
WHERE " . $db->sql_in_set($column, $from_values);
$db->sql_query($sql);
$db->sql_transaction('commit');
}
}
/**
* Updates rows in given table from a set of values to a new value.
* If this results in rows violating uniqueness constraints, the duplicate
* rows are merged respecting notify_status (0 takes precedence over 1).
*
* The only supported table is topics_watch.
*
* @param dbal $db Database object
* @param string $table Table on which to perform the update
* @param string $column Column whose values to change
* @param array $from_values An array of values that should be changed
* @param int $to_value The new value
* @return null
*/
function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $column, $from_values, $to_value)
{
$sql = "SELECT $column, user_id, notify_status
FROM $table
WHERE " . $db->sql_in_set($column, $from_values);
$result = $db->sql_query($sql);
$old_user_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$old_user_ids[(int) $row['notify_status']][$row[$column]][] = (int) $row['user_id'];
}
$db->sql_freeresult($result);
$sql = "SELECT $column, user_id
FROM $table
WHERE $column = " . (int) $to_value;
$result = $db->sql_query($sql);
$new_user_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$new_user_ids[$row[$column]][] = (int) $row['user_id'];
}
$db->sql_freeresult($result);
$queries = array();
$extra_updates = array(
0 => 'notify_status = 0',
1 => '',
);
foreach ($from_values as $from_value)
{
foreach ($extra_updates as $notify_status => $extra_update)
{
if (!isset($old_user_ids[$notify_status][$from_value]))
{
continue;
}
if (empty($new_user_ids))
{
$sql = "UPDATE $table
SET $column = " . (int) $to_value . "
WHERE $column = '" . $db->sql_escape($from_value) . "'";
$queries[] = $sql;
}
else
{
$different_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $new_user_ids[$to_value]);
if (!empty($different_user_ids))
{
$sql = "UPDATE $table
SET $column = " . (int) $to_value . "
WHERE $column = '" . $db->sql_escape($from_value) . "'
AND " . $db->sql_in_set('user_id', $different_user_ids);
$queries[] = $sql;
}
if ($extra_update)
{
$same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids);
if (!empty($same_user_ids))
{
$sql = "UPDATE $table
SET $extra_update
WHERE $column = '" . (int) $to_value . "'
AND " . $db->sql_in_set('user_id', $same_user_ids);
$queries[] = $sql;
}
}
}
}
}
if (!empty($queries))
{
$db->sql_transaction('begin');
foreach ($queries as $sql)
{
$db->sql_query($sql);
}
$sql = "DELETE FROM $table
WHERE " . $db->sql_in_set($column, $from_values);
$db->sql_query($sql);
$db->sql_transaction('commit');
}
}

View File

@ -430,13 +430,12 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id)
// Message and return links // Message and return links
$success_msg = 'POSTS_MERGED_SUCCESS'; $success_msg = 'POSTS_MERGED_SUCCESS';
// If the topic no longer exist, we will update the topic watch table. // Update the topic watch table.
// To not let it error out on users watching both topics, we just return on an error... if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
$db->sql_return_on_error(true); {
$db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids)); include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
$db->sql_return_on_error(false); }
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids));
// Link to the new topic // Link to the new topic
$return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>'); $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');

View File

@ -615,7 +615,13 @@ function approve_post($post_id_list, $id, $mode)
{ {
$phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']);
$phpbb_notifications->add_notifications('topic', $post_data); $phpbb_notifications->add_notifications(array(
'quote',
'topic',
), $post_data);
$phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']);
$phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']);
if ($notify_poster) if ($notify_poster)
{ {
@ -631,6 +637,12 @@ function approve_post($post_id_list, $id, $mode)
'bookmark', 'bookmark',
'post', 'post',
), $post_data); ), $post_data);
$phpbb_notifications->mark_notifications_read(array(
'quote',
'bookmark',
'post',
),$post_data['post_id'], $user->data['user_id']);
if ($notify_poster) if ($notify_poster)
{ {

View File

@ -624,12 +624,11 @@ function merge_posts($topic_id, $to_topic_id)
else else
{ {
// If the topic no longer exist, we will update the topic watch table. // If the topic no longer exist, we will update the topic watch table.
// To not let it error out on users watching both topics, we just return on an error... if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status'))
$db->sql_return_on_error(true); {
$db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE topic_id = ' . (int) $topic_id); include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx);
$db->sql_return_on_error(false); }
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id);
} }
// Link to the new topic // Link to the new topic

View File

@ -702,17 +702,6 @@ class bbcode_firstpass extends bbcode
{ {
global $config, $user; global $config, $user;
/**
* If you change this code, make sure the cases described within the following reports are still working:
* #3572 - [quote="[test]test"]test [ test[/quote] - (correct: parsed)
* #14667 - [quote]test[/quote] test ] and [ test [quote]test[/quote] (correct: parsed)
* #14770 - [quote="["]test[/quote] (correct: parsed)
* [quote="[i]test[/i]"]test[/quote] (correct: parsed)
* [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote])
* #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted)
* #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed)
*/
$in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in))); $in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in)));
if (!$in) if (!$in)

View File

@ -226,16 +226,6 @@ class phpbb_notification_manager
*/ */
public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) public function mark_notifications_read($item_type, $item_id, $user_id, $time = false)
{ {
if (is_array($item_type))
{
foreach ($item_type as $type)
{
$this->mark_notifications_read($type, $item_id, $user_id, $time);
}
return;
}
$time = ($time !== false) ? $time : time(); $time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . " $sql = 'UPDATE ' . $this->notifications_table . "

View File

@ -2,28 +2,264 @@
/** /**
* *
* @package testing * @package testing
* @version $Id$ * @copyright (c) 2012 phpBB Group
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser_base.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php';
class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase
{ {
public function test_both_passes() public function bbcode_firstpass_data()
{ {
$this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); return array(
// Default bbcodes from in their simplest way
$parser = new phpbb_bbcode_parser(); array(
'Test default bbcodes: simple bold',
'[b]bold[/b]',
'[b:]bold[/b:]',
),
array(
'Test default bbcodes: simple underlined',
'[u]underlined[/u]',
'[u:]underlined[/u:]',
),
array(
'Test default bbcodes: simple italic',
'[i]italic[/i]',
'[i:]italic[/i:]',
),
array(
'Test default bbcodes: simple color rgb',
'[color=#FF0000]colored[/color]',
'[color=#FF0000:]colored[/color:]',
),
array(
'Test default bbcodes: simple color name',
'[color=red]colored[/color]',
'[color=red:]colored[/color:]',
),
array(
'Test default bbcodes: simple size',
'[size=75]smaller[/size]',
'[size=75:]smaller[/size:]',
),
array(
'Test default bbcodes: simple quote',
'[quote]quoted[/quote]',
'[quote:]quoted[/quote:]',
),
array(
'Test default bbcodes: simple quote with username',
'[quote=&quot;username&quot;]quoted[/quote]',
'[quote=&quot;username&quot;:]quoted[/quote:]',
),
array(
'Test default bbcodes: simple code',
'[code]unparsed code[/code]',
'[code:]unparsed code[/code:]',
),
array(
'Test default bbcodes: simple php code',
'[code=php]unparsed code[/code]',
'[code=php:]<span class="syntaxdefault">unparsed&nbsp;code</span>[/code:]',
),
array(
'Test default bbcodes: simple list',
'[list]no item[/list]',
'[list:]no item[/list:u:]',
),
array(
'Test default bbcodes: simple list-item only',
'[*]unparsed',
'[*]unparsed',
),
array(
'Test default bbcodes: simple list-item',
'[list][*]item[/list]',
'[list:][*:]item[/*:m:][/list:u:]',
),
array(
'Test default bbcodes: simple list-item closed',
'[list][*]item[/*][/list]',
'[list:][*:]item[/*:][/list:u:]',
),
array(
'Test default bbcodes: simple list-item numbered',
'[list=1][*]item[/list]',
'[list=1:][*:]item[/*:m:][/list:o:]',
),
array(
'Test default bbcodes: simple list-item alpha',
'[list=a][*]item[/list]',
'[list=a:][*:]item[/*:m:][/list:o:]',
),
array(
'Test default bbcodes: simple list-item roman',
'[list=i][*]item[/list]',
'[list=i:][*:]item[/*:m:][/list:o:]',
),
array(
'Test default bbcodes: simple list-item disc',
'[list=disc][*]item[/list]',
'[list=disc:][*:]item[/*:m:][/list:u:]',
),
array(
'Test default bbcodes: simple list-item circle',
'[list=circle][*]item[/list]',
'[list=circle:][*:]item[/*:m:][/list:u:]',
),
array(
'Test default bbcodes: simple list-item square',
'[list=square][*]item[/list]',
'[list=square:][*:]item[/*:m:][/list:u:]',
),
array(
'Test default bbcodes: simple img',
'[img]https://area51.phpbb.com/images/area51.png[/img]',
'[img:]https&#58;//area51&#46;phpbb&#46;com/images/area51&#46;png[/img:]',
),
array(
'Test default bbcodes: simple url',
'[url]https://area51.phpbb.com/[/url]',
'[url:]https&#58;//area51&#46;phpbb&#46;com/[/url:]',
),
array(
'Test default bbcodes: simple url with description',
'[url=https://area51.phpbb.com/]Area51[/url]',
'[url=https&#58;//area51&#46;phpbb&#46;com/:]Area51[/url:]',
),
array(
'Test default bbcodes: simple email',
'[email]bbcode-test@phpbb.com[/email]',
'[email:]bbcode-test@phpbb&#46;com[/email:]',
),
array(
'Test default bbcodes: simple email with description',
'[email=bbcode-test@phpbb.com]Email[/email]',
'[email=bbcode-test@phpbb&#46;com:]Email[/email:]',
),
array(
'Test default bbcodes: simple attachment',
'[attachment=0]filename[/attachment]',
'[attachment=0:]<!-- ia0 -->filename<!-- ia0 -->[/attachment:]',
),
$result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); // Special cases for quote which were reported as bugs before
$result = $parser->second_pass($result); array(
'PHPBB3-1401 - correct: parsed',
'[quote=&quot;&#91;test]test&quot;]test [ test[/quote]',
'[quote=&quot;&#91;test]test&quot;:]test [ test[/quote:]',
),
array(
'PHPBB3-6117 - correct: parsed',
'[quote]test[/quote] test ] and [ test [quote]test[/quote]',
'[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]',
),
array(
'PHPBB3-6200 - correct: parsed',
'[quote=&quot;[&quot;]test[/quote]',
'[quote=&quot;&#91;&quot;:]test[/quote:]',
),
array(
'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted',
'[quote]test[/[/b]quote] test [/quote][/quote] test',
'[quote:]test[/[/b]quote] test [/quote:][/quote] test',
),
array(
'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed',
'[quote=&quot;a&quot;]a[/quote][quote=&quot;a]a[/quote]',
'[quote=&quot;a&quot;:]a[/quote:][quote=&quot;a]a[/quote]',
),
$expected = '<span style="font-style: italic">Italic <span style="text-decoration: underline">underlined text</span></span>'; // Simple bbcodes nesting
array(
'Allow textual bbcodes in textual bbcodes',
'[b]bold [i]bold + italic[/i][/b]',
'[b:]bold [i:]bold + italic[/i:][/b:]',
),
array(
'Allow textual bbcodes in url with description',
'[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]',
'[url=https&#58;//area51&#46;phpbb&#46;com/:]Area51 [i:]italic[/i:][/url:]',
),
array(
'Allow url with description in textual bbcodes',
'[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]',
'[i:]italic [url=https&#58;//area51&#46;phpbb&#46;com/:]Area51[/url:][/i:]',
),
$this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); // Nesting bbcodes into quote usernames
array(
'Allow textual bbcodes in usernames',
'[quote=&quot;[i]test[/i]&quot;]test[/quote]',
'[quote=&quot;[i:]test[/i:]&quot;:]test[/quote:]',
),
array(
'Allow links bbcodes in usernames',
'[quote=&quot;[url=https://area51.phpbb.com/]test[/url]&quot;]test[/quote]',
'[quote=&quot;[url=https&#58;//area51&#46;phpbb&#46;com/:]test[/url:]&quot;:]test[/quote:]',
),
array(
'Allow img bbcodes in usernames - Username displayed the image',
'[quote=&quot;[img]https://area51.phpbb.com/images/area51.png[/img]&quot;]test[/quote]',
'[quote=&quot;[img:]https&#58;//area51&#46;phpbb&#46;com/images/area51&#46;png[/img:]&quot;:]test[/quote:]',
),
array(
'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]',
'[quote=&quot;[flash]http://www.phpbb.com/[/flash]&quot;]test[/quote]',
'[quote=&quot;&#91;flash]http://www.phpbb.com/&#91;/flash]&quot;:]test[/quote:]',
),
array(
'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]',
'[quote=&quot;[quote]test[/quote]&quot;]test[/quote]',
'[quote=&quot;&#91;quote]test&#91;/quote]&quot;:]test[/quote:]',
),
// Do not parse bbcodes in code boxes
array(
'Do not parse textual bbcodes in code',
'[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]',
'[code:]unparsed code &#91;b&#93;bold &#91;i&#93;bold + italic&#91;/i&#93;&#91;/b&#93;[/code:]',
),
array(
'Do not parse quote bbcodes in code',
'[code]unparsed code [quote=&quot;username&quot;]quoted[/quote][/code]',
'[code:]unparsed code &#91;quote=&quot;username&quot;&#93;quoted&#91;/quote&#93;[/code:]',
),
// New user friendly mixed nesting
array(
'Textual bbcode nesting into textual bbcode',
'[b]bold [i]bold + italic[/b] italic[/i]',
'[b:]bold [i:]bold + italic[/b:] italic[/i:]',
'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]',
),
);
}
/**
* @dataProvider bbcode_firstpass_data
*/
public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false)
{
if ($incomplete)
{
$this->markTestIncomplete($incomplete);
}
global $user, $request;
$user = new phpbb_mock_user;
$request = new phpbb_mock_request;
$bbcode = new bbcode_firstpass();
$bbcode->message = $message;
$bbcode->bbcode_init(false);
$bbcode->parse_bbcode();
$this->assertEquals($expected, $bbcode->message);
} }
} }

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_bookmarks">
<column>user_id</column>
<column>topic_id</column>
<!-- one entry for this topic -->
<row>
<value>1</value>
<value>1</value>
</row>
<!-- non-conflicting entries -->
<row>
<value>2</value>
<value>2</value>
</row>
<row>
<value>3</value>
<value>3</value>
</row>
<!-- conflicting entries -->
<row>
<value>1</value>
<value>4</value>
</row>
<row>
<value>1</value>
<value>5</value>
</row>
<!-- conflicting and non-conflicting entries -->
<row>
<value>1</value>
<value>6</value>
</row>
<row>
<value>1</value>
<value>7</value>
</row>
<row>
<value>2</value>
<value>6</value>
</row>
</table>
</dataset>

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_topics_watch">
<column>user_id</column>
<column>topic_id</column>
<column>notify_status</column>
<!-- one entry for this topic -->
<row>
<value>1</value>
<value>1</value>
<value>1</value>
</row>
<!-- non-conflicting entries -->
<row>
<value>1</value>
<value>2</value>
<value>1</value>
</row>
<row>
<value>2</value>
<value>3</value>
<value>0</value>
</row>
<!-- conflicting entries, same notify status -->
<row>
<value>1</value>
<value>4</value>
<value>1</value>
</row>
<row>
<value>1</value>
<value>5</value>
<value>1</value>
</row>
<!-- conflicting entries, notify status 0 into 1 -->
<row>
<value>1</value>
<value>6</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>7</value>
<value>1</value>
</row>
<!-- conflicting entries, notify status 1 into 0 -->
<row>
<value>1</value>
<value>8</value>
<value>1</value>
</row>
<row>
<value>1</value>
<value>9</value>
<value>0</value>
</row>
<!-- conflicting and non-conflicting entries -->
<row>
<value>1</value>
<value>10</value>
<value>0</value>
</row>
<row>
<value>1</value>
<value>11</value>
<value>1</value>
</row>
<row>
<value>2</value>
<value>10</value>
<value>1</value>
</row>
</table>
</dataset>

View File

@ -0,0 +1,101 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php';
class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/topics_watch_duplicates.xml');
}
public static function fixture_data()
{
return array(
// description
// from array
// to value
// expected count with to value post update
// expected notify_status values
array(
'trivial',
array(1),
1000,
1,
1,
),
array(
'no conflict',
array(2),
3,
2,
1,
),
array(
'conflict, same notify status',
array(4),
5,
1,
1,
),
array(
'conflict, notify status 0 into 1',
array(6),
7,
1,
0,
),
array(
'conflict, notify status 1 into 0',
array(8),
9,
1,
0,
),
array(
'conflict and no conflict',
array(10),
11,
2,
0,
),
);
}
/**
* @dataProvider fixture_data
*/
public function test_update($description, $from, $to, $expected_result_count, $expected_notify_status)
{
$db = $this->new_dbal();
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to);
$sql = 'SELECT COUNT(*) AS remaining_rows
FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . (int) $to;
$result = $db->sql_query($sql);
$result_count = $db->sql_fetchfield('remaining_rows');
$db->sql_freeresult($result);
$this->assertEquals($expected_result_count, $result_count);
// user id of 1 is the user being updated
$sql = 'SELECT notify_status
FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . (int) $to . '
AND user_id = 1';
$result = $db->sql_query($sql);
$notify_status = $db->sql_fetchfield('notify_status');
$db->sql_freeresult($result);
$this->assertEquals($expected_notify_status, $notify_status);
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php';
class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/bookmarks_duplicates.xml');
}
public static function fixture_data()
{
return array(
// description
// from array
// to value
// expected count with to value post update
array(
'trivial',
array(1),
10,
1,
),
array(
'no conflict',
array(2),
3,
2,
),
array(
'conflict',
array(4),
5,
1,
),
array(
'conflict and no conflict',
array(6),
7,
2,
),
);
}
/**
* @dataProvider fixture_data
*/
public function test_update($description, $from, $to, $expected_result_count)
{
$db = $this->new_dbal();
phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $from, $to);
$sql = 'SELECT COUNT(*) AS remaining_rows
FROM ' . BOOKMARKS_TABLE . '
WHERE topic_id = ' . (int) $to;
$result = $db->sql_query($sql);
$result_count = $db->sql_fetchfield('remaining_rows');
$db->sql_freeresult($result);
$this->assertEquals($expected_result_count, $result_count);
}
}

View File

@ -227,7 +227,6 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms']) switch ($this->config['dbms'])
{ {
case 'phpbb_db_driver_mysql': case 'phpbb_db_driver_mysql':
case 'phpbb_db_driver_mysql4':
case 'phpbb_db_driver_mysqli': case 'phpbb_db_driver_mysqli':
$sql = 'SHOW TABLES'; $sql = 'SHOW TABLES';
break; break;