Commit 1117d36b authored by Carsten  Rose's avatar Carsten Rose
Browse files

#3875 / FormElement 'extra': Fehler bei neuen Records.

QFQ complains that the given SIP parameter is already defined. Problem is the pre filling of Store SIP, which normally happens only during form load. But the new 'saving a new record (r=0) and redirecting the browser to the same page with the new record id', requires a new SIP. That SIP is calculated before form-load and causes the exception. Fix: defined parameter in a store, which will be redefined with the same value, wont' throw an exception anymore.
Store.php: compare old and new value and only if they differ throw an exception.
parent a0243d9f
......@@ -1859,9 +1859,6 @@ abstract class AbstractBuildForm {
public function buildExtra(array $formElement, $htmlFormElementName, $value, array &$json, $mode = FORM_LOAD) {
if ($mode === FORM_LOAD) {
// Split 'grId:0' in 'grId' and '0'
// $name = explode(':', $htmlFormElementName, 2);
// $this->store->setVar($name[0], $value, STORE_SIP, false);
$this->store->setVar($formElement[FE_NAME], $value, STORE_SIP, false);
}
}
......
......@@ -577,7 +577,8 @@ class Store {
if ($store === STORE_ZERO)
throw new CodeException("setVar() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);
if ($overWrite === false && isset(self::$raw[$store][$key])) {
// Complain if already set and different.
if ($overWrite === false && isset(self::$raw[$store][$key]) && self::$raw[$store][$key] != $value) {
throw new UserFormException("Value of '$key' already set in store '$store'.", ERROR_STORE_KEY_EXIST);
}
......
......@@ -176,6 +176,29 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(false, $this->store->getVar('apple', STORE_RECORD), "Retrieve a value from store.");
}
public function testSetVar() {
$this->store = Store::getInstance('', true);
foreach ([STORE_SIP, STORE_CLIENT, STORE_EXTRA] AS $store) {
// initial set
$this->store->setVar('unitTest', '123', $store);
$this->assertEquals('123', $this->store->getVar('unitTest', $store), "Retrieve var.");
// redefine, using default 'overwrite=true'
$this->store->setVar('unitTest', '1234', $store);
$this->assertEquals('1234', $this->store->getVar('unitTest', $store), "Retrieve var.");
// redefine, using explicit 'overwrite=true'
$this->store->setVar('unitTest', '12345', $store, true);
$this->assertEquals('12345', $this->store->getVar('unitTest', $store), "Retrieve var.");
// redefine, using explicit 'overwrite=false' but with the same value (that is ok)
$this->store->setVar('unitTest', '12345', $store, false);
$this->assertEquals('12345', $this->store->getVar('unitTest', $store), "Retrieve var.");
}
}
/**
* @expectedException \qfq\UserFormException
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment