Skip to content
Browse files

Fix a regression from #791.

  • Loading branch information...
1 parent d8108cf commit 59d1321357dbfed8ae137269facaa8db61ad3eef @realityking realityking committed Feb 29, 2012
View
20 libraries/joomla/input/input.php
@@ -209,6 +209,26 @@ public function set($name, $value)
}
/**
+ * Define a value. The value will only be set if there's no value for the name or if it is null.
+ *
+ * @param string $name Name of the value to define.
+ * @param mixed $value Value to assign to the input.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function def($name, $value)
+ {
+ if (isset($this->data[$name]))
+ {
+ return;
+ }
+
+ $this->data[$name] = $value;
+ }
+
+ /**
* Magic method to get filtered input data.
*
* @param mixed $name Name of the value to get.
View
2 libraries/legacy/application/application.php
@@ -271,7 +271,7 @@ public function route()
foreach ($result as $key => $value)
{
- $this->input->set($key, $value);
+ $this->input->def($key, $value);
}
// Trigger the onAfterRoute event.
View
59 tests/suite/joomla/input/JInputTest.php
@@ -98,6 +98,53 @@ public function testGet()
}
/**
+ * Test the JInput::def method.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function testDef()
+ {
+ $_REQUEST['foo'] = 'bar';
+
+ $this->class->def('foo', 'nope');
+
+ $this->assertThat(
+ $_REQUEST['foo'],
+ $this->equalTo('bar'),
+ 'Line: '.__LINE__.'.'
+ );
+
+ $this->class->def('Joomla', 'is great');
+
+ $this->assertThat(
+ $_REQUEST['Joomla'],
+ $this->equalTo('is great'),
+ 'Line: '.__LINE__.'.'
+ );
+ }
+
+ /**
+ * Test the JInput::set method.
+ *
+ * @return void
+ *
+ * @since 12.1
+ */
+ public function testSet()
+ {
+ $_REQUEST['foo'] = 'bar2';
+ $this->class->set('foo', 'bar');
+
+ $this->assertThat(
+ $_REQUEST['foo'],
+ $this->equalTo('bar'),
+ 'Line: '.__LINE__.'.'
+ );
+ }
+
+ /**
* Test the JInput::get method.
*
* @return void
@@ -256,18 +303,6 @@ public function testSerialize()
}
/**
- * Test the JInput::set method.
- *
- * @return void
- *
- * @since 12.1
- */
- public function testSet()
- {
- $this->markTestIncomplete();
- }
-
- /**
* Test the JInput::unserialize method.
*
* @return void

0 comments on commit 59d1321

Please sign in to comment.
Something went wrong with that request. Please try again.