diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-01-15 12:36:54 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-01-15 12:36:54 +0100 |
commit | 1dbc2d621861249a40633012fe33af02c097e69b (patch) | |
tree | 2264e29c7d678684e78e1436a1604f682e599da0 /tests/profile | |
parent | 7fd5f16fa2aeeaddfe21062ffe3c4052ec5ec6c1 (diff) | |
download | forums-1dbc2d621861249a40633012fe33af02c097e69b.tar forums-1dbc2d621861249a40633012fe33af02c097e69b.tar.gz forums-1dbc2d621861249a40633012fe33af02c097e69b.tar.bz2 forums-1dbc2d621861249a40633012fe33af02c097e69b.tar.xz forums-1dbc2d621861249a40633012fe33af02c097e69b.zip |
[ticket/11201] Fix dropdown tests
The error message is now already the language string including the fieldname
and not the language key anymore.
PHPBB3-11201
Diffstat (limited to 'tests/profile')
-rw-r--r-- | tests/profile/custom_test.php | 68 | ||||
-rw-r--r-- | tests/profile/custom_test~.php | 55 |
2 files changed, 68 insertions, 55 deletions
diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php new file mode 100644 index 0000000000..cfc350c162 --- /dev/null +++ b/tests/profile/custom_test.php @@ -0,0 +1,68 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_profile_custom_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/profile_fields.xml'); + } + + static public function dropdown_fields() + { + return array( + // note, there is an offset of 1 between option_id (0-indexed) + // in the database and values (1-indexed) to avoid problems with + // transmitting 0 in an HTML form + // required, value, expected + array(1, '0', 'FIELD_INVALID_VALUE-field', 'Required field should throw error for out-of-range value'), + array(1, '1', 'FIELD_REQUIRED-field', 'Required field should throw error for default value'), + array(1, '2', false, 'Required field should accept non-default value'), + array(0, '0', 'FIELD_INVALID_VALUE-field', 'Optional field should throw error for out-of-range value'), + array(0, '1', false, 'Optional field should accept default value'), + array(0, '2', false, 'Optional field should accept non-default value'), + ); + } + + /** + * @dataProvider dropdown_fields + */ + public function test_dropdown_validate($field_required, $field_value, $expected, $description) + { + global $db; + $db = $this->new_dbal(); + + $field_data = array( + 'field_id' => 1, + 'lang_id' => 1, + 'lang_name' => 'field', + 'field_novalue' => 1, + 'field_required' => $field_required, + ); + $user = $this->getMock('\phpbb\user'); + $user->expects($this->any()) + ->method('lang') + ->will($this->returnCallback(array($this, 'return_callback_implode'))); + + $cp = new \phpbb\profilefields\type\type_dropdown( + new \phpbb\profilefields\lang_helper($db), + $this->getMock('\phpbb\request\request'), + $this->getMock('\phpbb\template\template'), + $user + ); + $result = $cp->validate_profile_field($field_value, $field_data); + + $this->assertEquals($expected, $result, $description); + } + + public function return_callback_implode() + { + return implode('-', func_get_args()); + } +} diff --git a/tests/profile/custom_test~.php b/tests/profile/custom_test~.php deleted file mode 100644 index 1f33b45ba9..0000000000 --- a/tests/profile/custom_test~.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_profile_fields.php'; - -class phpbb_profile_custom_test extends phpbb_database_test_case -{ - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/profile_fields.xml'); - } - - static public function dropdownFields() - { - return array( - // note, there is an offset of 1 between option_id (0-indexed) - // in the database and values (1-indexed) to avoid problems with - // transmitting 0 in an HTML form - // required, value, expected - array(1, '0', 'FIELD_INVALID_VALUE', 'Required field should throw error for out-of-range value'), - array(1, '1', 'FIELD_REQUIRED', 'Required field should throw error for default value'), - array(1, '2', false, 'Required field should accept non-default value'), - array(0, '0', 'FIELD_INVALID_VALUE', 'Optional field should throw error for out-of-range value'), - array(0, '1', false, 'Optional field should accept default value'), - array(0, '2', false, 'Optional field should accept non-default value'), - ); - } - - /** - * @dataProvider dropdownFields - */ - public function test_dropdown_validate($field_required, $field_value, $expected, $description) - { - global $db; - $db = $this->new_dbal(); - - $field_data = array( - 'field_id' => 1, - 'lang_id' => 1, - 'field_novalue' => 1, - 'field_required' => $field_required, - ); - - $cp = new custom_profile; - $result = $cp->validate_profile_field(FIELD_DROPDOWN, $field_value, $field_data); - - $this->assertEquals($expected, $result, $description); - } -} |