From 11e3804f97fc0ac5317d8e211c117c6572699976 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 Sep 2010 01:09:56 +0200 Subject: [PATCH] [ticket/9823] Unit tests for build_cfg_template. PHPBB3-9823 --- tests/functions_acp/all_tests.php | 2 + tests/functions_acp/build_cfg_template.php | 193 +++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 tests/functions_acp/build_cfg_template.php diff --git a/tests/functions_acp/all_tests.php b/tests/functions_acp/all_tests.php index 2b9c06f0ed..d2895da311 100644 --- a/tests/functions_acp/all_tests.php +++ b/tests/functions_acp/all_tests.php @@ -15,6 +15,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) require_once 'test_framework/framework.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; +require_once 'functions_acp/build_cfg_template.php'; require_once 'functions_acp/build_select.php'; require_once 'functions_acp/h_radio.php'; require_once 'functions_acp/validate_range.php'; @@ -30,6 +31,7 @@ class phpbb_functions_acp_all_tests { $suite = new PHPUnit_Framework_TestSuite('phpBB Network Functions'); + $suite->addTestSuite('phpbb_functions_acp_build_cfg_template_test'); $suite->addTestSuite('phpbb_functions_acp_built_select_test'); $suite->addTestSuite('phpbb_functions_acp_h_radio_test'); $suite->addTestSuite('phpbb_functions_acp_validate_range_test'); diff --git a/tests/functions_acp/build_cfg_template.php b/tests/functions_acp/build_cfg_template.php new file mode 100644 index 0000000000..07f82e933a --- /dev/null +++ b/tests/functions_acp/build_cfg_template.php @@ -0,0 +1,193 @@ + '1'), + 'config_key_name', + array(), + '', + ), + array( + array('password', 20, 128), + 'key_name', + array('config_key_name' => '2'), + 'config_key_name', + array(), + '', + ), + array( + array('text', 0, 255), + 'key_name', + array('config_key_name' => '3'), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @dataProvider build_cfg_template_text_data + */ + public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang =new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_dimension_data() + { + return array( + array( + array('dimension', 20, 255), + 'key_name', + array('config_key_name_width' => 10, 'config_key_name_height' => 20), + 'config_key_name', + array(), + ' x ', + ), + array( + array('dimension', 0, 255), + 'key_name', + array('config_key_name_width' => 10, 'config_key_name_height' => 20), + 'config_key_name', + array(), + ' x ', + ), + ); + } + + /** + * @dataProvider build_cfg_template_dimension_data + */ + public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang =new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_textarea_data() + { + return array( + array( + array('textarea', 5, 30), + 'key_name', + array('config_key_name' => 'phpBB'), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @dataProvider build_cfg_template_textarea_data + */ + public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang =new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_radio_data() + { + return array( + array( + array('radio', 'enabled_disabled'), + 'key_name', + array('config_key_name' => '0'), + 'config_key_name', + array(), + '', + ), + array( + array('radio', 'enabled_disabled'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '0'), + 'config_key_name', + array(), + '', + ), + array( + array('radio', 'yes_no'), + 'key_name', + array('config_key_name' => '1'), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @dataProvider build_cfg_template_radio_data + */ + public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang =new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + + public function build_cfg_template_append_data() + { + return array( + array( + array('textarea', 5, 30), + 'key_name', + array('config_key_name' => 'phpBB'), + 'config_key_name', + array('append' => 'Bertie is cool!'), + 'Bertie is cool!', + ), + ); + } + + /** + * @dataProvider build_cfg_template_append_data + */ + public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user; + + $user->lang =new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } +}