aboutsummaryrefslogtreecommitdiffstats
path: root/tests/text_reparser
diff options
context:
space:
mode:
authorJoshyPHP <s9e.dev@gmail.com>2015-07-06 01:43:43 +0200
committerJoshyPHP <s9e.dev@gmail.com>2015-07-06 23:45:20 +0200
commit7ccb6389124c5e990abaa917a6684fc3f4d072db (patch)
tree41ed0ef6d95a77643f0499b34fdc81364e05505a /tests/text_reparser
parentca5d4fd31031a47cc3a485457473b82660b84ed1 (diff)
downloadforums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.gz
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.bz2
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.tar.xz
forums-7ccb6389124c5e990abaa917a6684fc3f4d072db.zip
[ticket/13987] Add --dry-run option to reparser CLI
PHPBB3-13987
Diffstat (limited to 'tests/text_reparser')
-rw-r--r--tests/text_reparser/plugins/contact_admin_info_test.php33
-rw-r--r--tests/text_reparser/plugins/poll_option_test.php31
-rw-r--r--tests/text_reparser/plugins/test_row_based_plugin.php40
3 files changed, 73 insertions, 31 deletions
diff --git a/tests/text_reparser/plugins/contact_admin_info_test.php b/tests/text_reparser/plugins/contact_admin_info_test.php
index e577d2fd3d..e3df1ee2b8 100644
--- a/tests/text_reparser/plugins/contact_admin_info_test.php
+++ b/tests/text_reparser/plugins/contact_admin_info_test.php
@@ -28,6 +28,18 @@ class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_cas
return new \phpbb\textreparser\plugins\contact_admin_info(new \phpbb\config\db_text($this->db, CONFIG_TEXT_TABLE));
}
+ protected function get_rows()
+ {
+ $sql = 'SELECT config_name, config_value
+ FROM ' . CONFIG_TEXT_TABLE . '
+ ORDER BY config_name';
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
public function setUp()
{
global $config;
@@ -46,18 +58,19 @@ class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_cas
$this->assertEquals(1, $reparser->get_max_id());
}
- public function testReparse()
+ public function test_dry_run()
{
+ $old_rows = $this->get_rows();
$reparser = $this->get_reparser();
- $reparser->reparse_range(1, 1);
-
- $sql = 'SELECT config_name, config_value
- FROM ' . CONFIG_TEXT_TABLE . '
- ORDER BY config_name';
- $result = $this->db->sql_query($sql);
- $rows = $this->db->sql_fetchrowset($result);
- $this->db->sql_freeresult($result);
+ $reparser->reparse_range(1, 1, true);
+ $new_rows = $this->get_rows();
+ $this->assertEquals($old_rows, $new_rows);
+ }
+ public function test_reparse()
+ {
+ $reparser = $this->get_reparser();
+ $reparser->reparse_range(1, 1);
$expected = array(
array(
'config_name' => 'contact_admin_info',
@@ -76,6 +89,6 @@ class phpbb_textreparser_contact_admin_info_test extends phpbb_database_test_cas
'config_value' => '1a2hbwf5',
),
);
- $this->assertEquals($expected, $rows);
+ $this->assertEquals($expected, $this->get_rows());
}
}
diff --git a/tests/text_reparser/plugins/poll_option_test.php b/tests/text_reparser/plugins/poll_option_test.php
index acabda2146..cc6163a81b 100644
--- a/tests/text_reparser/plugins/poll_option_test.php
+++ b/tests/text_reparser/plugins/poll_option_test.php
@@ -28,6 +28,18 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case
return new \phpbb\textreparser\plugins\poll_option($this->db);
}
+ protected function get_rows()
+ {
+ $sql = 'SELECT topic_id, poll_option_id, poll_option_text
+ FROM ' . POLL_OPTIONS_TABLE . '
+ ORDER BY topic_id, poll_option_id';
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
public function setUp()
{
global $config;
@@ -46,18 +58,19 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case
$this->assertEquals(123, $reparser->get_max_id());
}
+ public function test_dry_run()
+ {
+ $old_rows = $this->get_rows();
+ $reparser = $this->get_reparser();
+ $reparser->reparse_range(1, 1, true);
+ $new_rows = $this->get_rows();
+ $this->assertEquals($old_rows, $new_rows);
+ }
+
public function testReparse()
{
$reparser = $this->get_reparser();
$reparser->reparse_range(2, 13);
-
- $sql = 'SELECT topic_id, poll_option_id, poll_option_text
- FROM ' . POLL_OPTIONS_TABLE . '
- ORDER BY topic_id, poll_option_id';
- $result = $this->db->sql_query($sql);
- $rows = $this->db->sql_fetchrowset($result);
- $this->db->sql_freeresult($result);
-
$expected = array(
array(
'topic_id' => 1,
@@ -110,6 +123,6 @@ class phpbb_textreparser_poll_option_test extends phpbb_database_test_case
'poll_option_text' => 'This row should be [b:abcd1234]ignored[/b:abcd1234]',
),
);
- $this->assertEquals($expected, $rows);
+ $this->assertEquals($expected, $this->get_rows());
}
}
diff --git a/tests/text_reparser/plugins/test_row_based_plugin.php b/tests/text_reparser/plugins/test_row_based_plugin.php
index befcb48bda..9f9ecc609a 100644
--- a/tests/text_reparser/plugins/test_row_based_plugin.php
+++ b/tests/text_reparser/plugins/test_row_based_plugin.php
@@ -20,6 +20,21 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t
abstract protected function get_reparser();
+ protected function get_rows(array $ids)
+ {
+ $reparser = $this->get_reparser();
+ $columns = $reparser->get_columns();
+ $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text
+ FROM ' . $reparser->get_table_name() . '
+ WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . '
+ ORDER BY id';
+ $result = $this->db->sql_query($sql);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ return $rows;
+ }
+
public function setUp()
{
global $config;
@@ -38,10 +53,19 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t
$this->assertEquals(1000, $reparser->get_max_id());
}
+ public function test_dry_run()
+ {
+ $old_rows = $this->get_rows(array(1));
+ $reparser = $this->get_reparser();
+ $reparser->reparse_range(1, 1, true);
+ $new_rows = $this->get_rows(array(1));
+ $this->assertEquals($old_rows, $new_rows);
+ }
+
/**
- * @dataProvider getReparseTests
+ * @dataProvider get_reparse_tests
*/
- public function testReparse($min_id, $max_id, $expected)
+ public function test_reparse($min_id, $max_id, $expected)
{
$reparser = $this->get_reparser();
$reparser->reparse_range($min_id, $max_id);
@@ -52,18 +76,10 @@ abstract class phpbb_textreparser_test_row_based_plugin extends phpbb_database_t
$ids[] = $row['id'];
}
- $columns = $reparser->get_columns();
- $sql = 'SELECT ' . $columns['id'] . ' AS id, ' . $columns['text'] . ' AS text
- FROM ' . $reparser->get_table_name() . '
- WHERE ' . $this->db->sql_in_set($columns['id'], $ids) . '
- ORDER BY id';
- $result = $this->db->sql_query($sql);
- $rows = $this->db->sql_fetchrowset($result);
- $this->db->sql_freeresult($result);
- $this->assertEquals($expected, $rows);
+ $this->assertEquals($expected, $this->get_rows($ids));
}
- public function getReparseTests()
+ public function get_reparse_tests()
{
return array(
array(