diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/dbal/db_tools_test.php | 54 | ||||
-rw-r--r-- | tests/dbal/migration/revert.php | 8 | ||||
-rw-r--r-- | tests/dbal/migrator_test.php | 6 | ||||
-rw-r--r-- | tests/functions/validate_with_method_test.php | 39 | ||||
-rw-r--r-- | tests/log/fixtures/full_log.xml | 12 | ||||
-rw-r--r-- | tests/log/function_view_log_test.php | 27 | ||||
-rw-r--r-- | tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html | 2 | ||||
-rw-r--r-- | tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html | 3 | ||||
-rw-r--r-- | tests/template/template_events_test.php | 21 | ||||
-rw-r--r-- | tests/template/template_test.php | 19 | ||||
-rw-r--r-- | tests/template/templates/loop_nested_include.html | 4 | ||||
-rw-r--r-- | tests/template/templates/loop_nested_include1.html | 5 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_test_connection_manager.php | 17 |
13 files changed, 212 insertions, 5 deletions
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index e25335165a..df8f22083b 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -11,7 +11,9 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_dbal_db_tools_test extends phpbb_database_test_case { + /** @var \phpbb\db\driver\driver_interface */ protected $db; + /** @var \phpbb\db\tools */ protected $tools; protected $table_exists; protected $table_data; @@ -207,6 +209,32 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist')); } + public function test_column_change_with_index() + { + // Create column + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012', array('DECIMAL', 0))); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + + // Create index over the column + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012', array('c_bug_12012', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + + // Change type from int to string + $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12012', array('VCHAR:100', ''))); + + // Remove the index + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + $this->assertTrue($this->tools->sql_index_drop('prefix_table_name', 'i_bug_12012')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + + // Remove the column + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + } + public function test_column_remove() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); @@ -216,6 +244,28 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); } + public function test_column_remove_with_index() + { + // Create column + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012_2', array('UINT', 4))); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + + // Create index over the column + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_2', array('c_bug_12012_2', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_3', array('c_bug_12012_2'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + + // Remove the column + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012_2')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + } + public function test_column_remove_primary() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); @@ -252,7 +302,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_table_exists('prefix_test_table')); } - public function test_peform_schema_changes_drop_tables() + public function test_perform_schema_changes_drop_tables() { $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_table_exists', @@ -278,7 +328,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case )); } - public function test_peform_schema_changes_drop_columns() + public function test_perform_schema_changes_drop_columns() { $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_column_exists', diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index c2520f4d8a..1c98710ffb 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -35,6 +35,14 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { return array( array('config.add', array('foobartest', 0)), + array('custom', array(array(&$this, 'my_custom_function'))), ); } + + function my_custom_function() + { + global $migrator_test_revert_counter; + + $migrator_test_revert_counter += 1; + } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c18c49b2a0..cc3e92071f 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -174,10 +174,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case public function test_revert() { + global $migrator_test_revert_counter; + // Make sure there are no other migrations in the db, this could cause issues $this->db->sql_query("DELETE FROM phpbb_migrations"); $this->migrator->load_migration_state(); + $migrator_test_revert_counter = 0; + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); @@ -219,6 +223,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case { $this->fail('Revert did not remove test_column.'); } + + $this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again'); } public function test_fail() diff --git a/tests/functions/validate_with_method_test.php b/tests/functions/validate_with_method_test.php new file mode 100644 index 0000000000..86d7b9571c --- /dev/null +++ b/tests/functions/validate_with_method_test.php @@ -0,0 +1,39 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; + +class phpbb_functions_validate_with_method_test extends phpbb_test_case +{ + protected $helper; + + protected function setUp() + { + parent::setUp(); + + $this->helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_date() + { + $this->helper->assert_valid_data(array( + 'method_call' => array( + array(), + true, + array(array(array($this, 'with_method'), false)), + ), + )); + } + + public function validate_with_method($bool, $optional = false) + { + return ! $bool; + } +} diff --git a/tests/log/fixtures/full_log.xml b/tests/log/fixtures/full_log.xml index 4e5538d5a9..ef35884444 100644 --- a/tests/log/fixtures/full_log.xml +++ b/tests/log/fixtures/full_log.xml @@ -131,6 +131,18 @@ <value>LOG_SINGULAR_PLURAL</value> <value>a:1:{i:0;i:2;}</value> </row> + <row> + <value>11</value> + <value>1</value> + <value>1</value> + <value>15</value> + <value>3</value> + <value>0</value> + <value>127.0.0.1</value> + <value>1</value> + <value>LOG_MOD3</value> + <value>a:1:{i:0;s:5:"guest";}</value> + </row> </table> <table name="phpbb_users"> <column>user_id</column> diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 2f64459062..542d0adf9d 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -225,6 +225,27 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'viewforum' => '', 'action' => 'LOG_SINGULAR_PLURAL 2', ), + 11 => array( + 'id' => 11, + + 'reportee_id' => 0, + 'reportee_username' => '', + 'reportee_username_full'=> '', + + 'user_id' => 1, + 'username' => 'Anonymous', + 'username_full' => 'Anonymous', + + 'ip' => '127.0.0.1', + 'time' => 1, + 'forum_id' => 15, + 'topic_id' => 3, + + 'viewforum' => '', + 'action' => 'LOG_MOD3 guest ', + 'viewtopic' => '', + 'viewlogs' => '', + ), ); $test_cases = array( @@ -310,6 +331,11 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'expected_returned' => 0, 'user', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'plural', ), + array( + 'expected' => array(11), + 'expected_returned' => 0, + 'mod', 0, 5, 0, 15, 3, + ), ); foreach ($test_cases as $case => $case_data) @@ -362,6 +388,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case 'LOG_INSTALL_INSTALLED' => 'installed: %s', 'LOG_USER' => 'User<br /> %s', 'LOG_MOD2' => 'Mod2', + 'LOG_MOD3' => 'Mod3: %1$s, %2$s', 'LOG_SINGULAR_PLURAL' => array( 1 => 'singular', 2 => 'plural (%d)', diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html new file mode 100644 index 0000000000..4fdba859f3 --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html @@ -0,0 +1,2 @@ +[{event_loop.S_ROW_COUNT}<!-- BEGIN subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}] +<!-- END subloop -->] diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html new file mode 100644 index 0000000000..233b32a4c7 --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_subloop.html @@ -0,0 +1,3 @@ +<!-- BEGIN event_loop --> +event_loop<!-- EVENT test_event_subloop --> +<!-- END event_loop --> diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 41e00e86a7..d09f22944f 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -90,14 +90,33 @@ Zeta test event in all', array(), 'event_loop0|event_loop1|event_loop2', ), + array( + 'EVENT with subloop in loop', + 'ext_trivial', + array('silver'), + 'event_subloop.html', + array(), + array( + 'event_loop' => array(array()), + 'event_loop.subloop' => array(array()), + ), + array(), + 'event_loop[0[subloop:0]]', + 'Event files are missing opened parent loops: PHPBB3-12382', + ), ); } /** * @dataProvider template_data */ - public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) + public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected, $incomplete_message = '') { + if ($incomplete_message) + { + $this->markTestIncomplete($incomplete_message); + } + // Reset the engine state $this->setup_engine_for_events($dataset, $style_names); diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 74baa3d5b6..49804c26c5 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -320,6 +320,18 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "barbarbar1bar1", ), + array( + 'loop_nested_include.html', + array(), + array( + 'test_loop' => array(array('foo' => 'bar'), array('foo' => 'bar1')), + 'test_loop.inner' => array(array('myinner' => 'works')), + ), + array(), + "[bar|[bar|]][bar1|[bar1|[bar1|works]]]", + array(), + 'Included files are missing opened parent loops: PHPBB3-12382', + ), /* Does not pass with the current implementation. array( 'loop_reuse.html', @@ -363,8 +375,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case /** * @dataProvider template_data */ - public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array()) + public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array(), $incomplete_message = '') { + if ($incomplete_message) + { + $this->markTestIncomplete($incomplete_message); + } + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $lang_vars); } diff --git a/tests/template/templates/loop_nested_include.html b/tests/template/templates/loop_nested_include.html new file mode 100644 index 0000000000..eaad46cc5b --- /dev/null +++ b/tests/template/templates/loop_nested_include.html @@ -0,0 +1,4 @@ +<!-- BEGIN test_loop --> +[{test_loop.foo} + |<!-- INCLUDE loop_nested_include1.html -->] +<!-- END test_loop --> diff --git a/tests/template/templates/loop_nested_include1.html b/tests/template/templates/loop_nested_include1.html new file mode 100644 index 0000000000..0f1a180b4d --- /dev/null +++ b/tests/template/templates/loop_nested_include1.html @@ -0,0 +1,5 @@ +[{test_loop.foo}| +<!-- BEGIN inner --> +[{test_loop.foo}| +{test_loop.inner.myinner}] +<!-- END inner -->] diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index f6429b1ccb..887dad5b50 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -12,8 +12,11 @@ require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.ph class phpbb_database_test_connection_manager { + /** @var array */ private $config; + /** @var array */ private $dbms; + /** @var \PDO */ private $pdo; /** @@ -363,9 +366,21 @@ class phpbb_database_test_connection_manager $table_name, $table_data ); + foreach ($queries as $query) { - $this->pdo->exec($query); + if ($query === 'begin') + { + $this->pdo->beginTransaction(); + } + else if ($query === 'commit') + { + $this->pdo->commit(); + } + else + { + $this->pdo->exec($query); + } } } } |