1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

Merge branch 'develop-olympus' into develop

* develop-olympus: (22 commits)
  [ticket/11162] Reformat.
  [ticket/11162] Rename tricky updates to database helper.
  [ticket/11162] Use empty($queries).
  [ticket/11162] Review comments fixed.
  [ticket/11162] Reformat.
  [ticket/11162] Newlines to LF.
  [ticket/11162] Use correct functions.
  [ticket/11162] Account for notify_status.
  [ticket/11162] This test really only works for bookmarks.
  [ticket/11162] The test is not at all trivial.
  [ticket/11162] Add includes.
  [ticket/11162] Move to a separate file to avoid blowing out functions.php.
  [ticket/11162] No whitespace changes in olympus.
  [ticket/11162] Fix inaccurately copy pasted comment.
  [ticket/11162] Use phpbb_update_rows_avoiding_duplicates in mcp.
  [ticket/11162] Clarify that only the two tables actually work.
  [ticket/11162] Uncomment transactions.
  [ticket/11162] An implementation that actually works.
  [ticket/11162] Make count function upper case.
  [ticket/11162] Rename count variable name to remaining_rows.
  ...
This commit is contained in:
Andreas Fischer
2012-12-14 02:56:20 +01:00
7 changed files with 516 additions and 13 deletions

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);
}
}