mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11095] Docs and tests for phpbb_build_hidden_fields_for_query_params.
PHPBB3-11095
This commit is contained in:
parent
2a39df1a53
commit
3e907265d5
2 changed files with 85 additions and 0 deletions
|
@ -4940,6 +4940,20 @@ function phpbb_quoteattr($data, $entities = null)
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts query string (GET) parameters in request into hidden fields.
|
||||||
|
*
|
||||||
|
* Useful for forwarding GET parameters when submitting forms with GET method.
|
||||||
|
*
|
||||||
|
* It is possible to omit some of the GET parameters, which is useful if
|
||||||
|
* they are specified in the form being submitted.
|
||||||
|
*
|
||||||
|
* sid is always omitted.
|
||||||
|
*
|
||||||
|
* @param phpbb_request $request Request object
|
||||||
|
* @param array $exclude A list of variable names that should not be forwarded
|
||||||
|
* @return string HTML with hidden fields
|
||||||
|
*/
|
||||||
function phpbb_build_hidden_fields_for_query_params($request, $exclude = null)
|
function phpbb_build_hidden_fields_for_query_params($request, $exclude = null)
|
||||||
{
|
{
|
||||||
$names = $request->variable_names(phpbb_request_interface::GET);
|
$names = $request->variable_names(phpbb_request_interface::GET);
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?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.php';
|
||||||
|
|
||||||
|
class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function build_hidden_fields_for_query_params_test_data()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// get
|
||||||
|
// post
|
||||||
|
// exclude
|
||||||
|
// expected
|
||||||
|
array(
|
||||||
|
array('foo' => 'bar'),
|
||||||
|
array(),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('foo' => 'bar', 'a' => 'b'),
|
||||||
|
array(),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('a' => 'quote"', 'b' => '<less>'),
|
||||||
|
array(),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('a' => "quotes'\""),
|
||||||
|
array(),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"a\" value=\"quotes'"\" />",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array('foo' => 'bar', 'a' => 'b'),
|
||||||
|
array('a' => 'c'),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||||
|
),
|
||||||
|
// strict equality check
|
||||||
|
array(
|
||||||
|
array('foo' => 'bar', 'a' => '0'),
|
||||||
|
array('a' => ''),
|
||||||
|
array(),
|
||||||
|
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider build_hidden_fields_for_query_params_test_data
|
||||||
|
*/
|
||||||
|
public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected)
|
||||||
|
{
|
||||||
|
$request = new phpbb_mock_request($get, $post);
|
||||||
|
$result = phpbb_build_hidden_fields_for_query_params($request, $exclude);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue