diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2012-12-12 21:46:38 -0500 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-12-12 21:46:38 -0500 |
commit | e2c67a8e42beefe1631a90feeb2215e2137c944b (patch) | |
tree | 5d1cd0b0bc4ce1996c58f99b954e018655075aa7 /tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php | |
parent | f5de11438c471a76fc5c5f3a4b8c4c29d07ed734 (diff) | |
download | forums-e2c67a8e42beefe1631a90feeb2215e2137c944b.tar forums-e2c67a8e42beefe1631a90feeb2215e2137c944b.tar.gz forums-e2c67a8e42beefe1631a90feeb2215e2137c944b.tar.bz2 forums-e2c67a8e42beefe1631a90feeb2215e2137c944b.tar.xz forums-e2c67a8e42beefe1631a90feeb2215e2137c944b.zip |
[ticket/11162] Rename tricky updates to database helper.
PHPBB3-11162
Diffstat (limited to 'tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php')
-rw-r--r-- | tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php new file mode 100644 index 0000000000..6c0f2da1e1 --- /dev/null +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php @@ -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); + } +} |