diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-02 16:05:53 -0400 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-11-02 16:05:53 -0400 |
commit | fd6ee50e06cb48c9e3a476bf23285875484ff5f7 (patch) | |
tree | 9a3af2e3d58546c0cc3f6040c4086766e5198c99 /tests | |
parent | 88b100d818940340e660c9f372526b1b5466bf3a (diff) | |
download | forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.gz forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.bz2 forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.tar.xz forums-fd6ee50e06cb48c9e3a476bf23285875484ff5f7.zip |
[ticket/11162] Extract existing behavior into a function and add a test.
PHPBB3-11162
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functions/fixtures/duplicates.xml | 56 | ||||
-rw-r--r-- | tests/functions/update_rows_avoiding_duplicates_test.php | 71 |
2 files changed, 127 insertions, 0 deletions
diff --git a/tests/functions/fixtures/duplicates.xml b/tests/functions/fixtures/duplicates.xml new file mode 100644 index 0000000000..bc08016a8f --- /dev/null +++ b/tests/functions/fixtures/duplicates.xml @@ -0,0 +1,56 @@ +<?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>2</value> + <value>2</value> + <value>1</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + </row> + + <!-- conflicting entries --> + <row> + <value>1</value> + <value>4</value> + <value>1</value> + </row> + <row> + <value>1</value> + <value>5</value> + <value>1</value> + </row> + + <!-- conflicting and non-conflicting entries --> + <row> + <value>1</value> + <value>6</value> + <value>1</value> + </row> + <row> + <value>1</value> + <value>7</value> + <value>1</value> + </row> + <row> + <value>2</value> + <value>6</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions/update_rows_avoiding_duplicates_test.php new file mode 100644 index 0000000000..0e949717d2 --- /dev/null +++ b/tests/functions/update_rows_avoiding_duplicates_test.php @@ -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.php'; + +class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/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_trivial_update($description, $from, $to, $expected_result_count) + { + $db = $this->new_dbal(); + + phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); + + $sql = 'SELECT count(*) AS count + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . $db->sql_escape($to); + $result = $db->sql_query($sql); + $result_count = $db->sql_fetchfield('count'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_result_count, $result_count); + } +} |