Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Merge pull request #1201 from chdemko/input
Browse files Browse the repository at this point in the history
Passing input array by reference
  • Loading branch information
LouisLandry committed May 12, 2012
2 parents 17e17d1 + cfc4750 commit 917d160
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions libraries/joomla/input/input.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class JInput implements Serializable
/**
* Constructor.
*
* @param array $source Source data (Optional, default is $_REQUEST)
* @param array &$source Source data (Optional, default is $_REQUEST)
* @param array $options Array of configuration parameters (Optional)
*
* @since 11.1
*/
public function __construct($source = null, array $options = array())
public function __construct(&$source = null, array $options = array())
{
if (isset($options['filter']))
{
Expand Down
42 changes: 31 additions & 11 deletions tests/suites/unit/joomla/input/JInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public function test__call()
*/
public function test__get()
{
$_POST['foo'] = 'bar';

// Test the get method.
$this->assertThat(
$this->class->post->get('foo'),
$this->equalTo('bar'),
'Line: '.__LINE__.'.'
);

// Test the set method.
$this->class->post->set('foo', 'notbar');
$this->assertThat(
$_POST['foo'],
$this->equalTo('notbar'),
'Line: '.__LINE__.'.'
);

$this->markTestIncomplete();
}

Expand Down Expand Up @@ -155,12 +172,13 @@ public function testGetArray()
{
$filterMock = new JFilterInputMockTracker();

$array = array(
'var1' => 'value1',
'var2' => 34,
'var3' => array('test')
);
$input = new JInput(
array(
'var1' => 'value1',
'var2' => 34,
'var3' => array('test')
),
$array,
array('filter' => $filterMock)
);

Expand Down Expand Up @@ -202,12 +220,13 @@ public function testGetArrayNested()
{
$filterMock = new JFilterInputMockTracker();

$array = array(
'var2' => 34,
'var3' => array('var2' => 'test'),
'var4' => array('var1' => array('var2' => 'test'))
);
$input = new JInput(
array(
'var2' => 34,
'var3' => array('var2' => 'test'),
'var4' => array('var1' => array('var2' => 'test'))
),
$array,
array('filter' => $filterMock)
);

Expand Down Expand Up @@ -343,6 +362,7 @@ protected function setUp()
include_once __DIR__ . '/stubs/JFilterInputMock.php';
include_once __DIR__ . '/stubs/JFilterInputMockTracker.php';

$this->class = new JInputInspector(null, array('filter' => new JFilterInputMock()));
$array = null;
$this->class = new JInputInspector($array, array('filter' => new JFilterInputMock()));
}
}

0 comments on commit 917d160

Please sign in to comment.