summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2020-06-26 07:55:33 +0200
committerChristian Schneider2020-06-26 07:55:33 +0200
commitcd76f06c9d8240cec15c51f33a2b8b09946c3e53 (patch)
treed5f63fd51d1e6cc0a7885afd790a4d52e8dfe1f2
parent5555b40c2a126cecc1d85d992c6862e53fee1c60 (diff)
downloaditools-cd76f06c9d8240cec15c51f33a2b8b09946c3e53.tar.gz
itools-cd76f06c9d8240cec15c51f33a2b8b09946c3e53.tar.bz2
itools-cd76f06c9d8240cec15c51f33a2b8b09946c3e53.zip
Leave _data unchanged by __read_postprocess as update() needs that and add test for it
-rw-r--r--it_dbi.class2
-rwxr-xr-xtest/it_dbi.t17
2 files changed, 14 insertions, 5 deletions
diff --git a/it_dbi.class b/it_dbi.class
index ceb5241..6d0cdeb 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -730,7 +730,7 @@ function iterate()
unset($this->_data['dyncols']);
foreach (static::_read_postprocess($this->_data) as $field => $value)
- $this->$field = $this->_data[$field] = (isset($value) && $this->_convertfunc[$field]) ? $this->_convertfunc[$field]($value) : $value;
+ $this->$field = (isset($value) && $this->_convertfunc[$field]) ? ($this->_data[$field] = $this->_convertfunc[$field]($value)) : $value;
if ($localizedfields)
{
diff --git a/test/it_dbi.t b/test/it_dbi.t
index b09cdbb..45f70d4 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -432,12 +432,16 @@ class my_dbi_test extends it_dbi_test
static function _read_postprocess($data)
{
$data['x']--;
+ $data['foo'] = json_decode($data['foo'], true);
return $data;
}
static function _write_preprocess($data)
{
- $data['x']++;
+ if (isset($data['x']))
+ $data['x']++;
+ if (isset($data['foo']))
+ $data['foo'] = json_encode($data['foo']);
return $data;
}
@@ -445,12 +449,17 @@ static function _write_preprocess($data)
$record = new my_dbi_test;
$record->delete(['WHERE 1' ]);
-$record->upsert(['ID' => 1, 'x' => 42, 'foo' => "a"]);
+$record->upsert(['ID' => 1, 'x' => 42, 'foo' => ['value' => "a"]]);
$record->read(1);
is($record->x, 42, 'value of x after reading with _read_postprocess');
-is($record->_data, ["ID" => 1, "x" => 42, 'foo' => "a"], 'data after reading with _read_postprocess');
+is($record->_data, ["ID" => 1, "x" => 42, 'foo' => '{"value":"a"}'], 'data after reading with _read_postprocess');
+is($record->foo, ['value' => "a"], 'field after reading with _read_postprocess');
$record2 = new it_dbi_test;
$record2->read(1);
is($record2->x, 43, 'raw value of x after writing with _write_preprocess');
-is($record2->_data, ["ID" => 1, "x" => 43, 'foo' => "a"], 'raw data after writing with _write_preprocess');
+is($record2->_data, ["ID" => 1, "x" => 43, 'foo' => '{"value":"a"}'], 'raw data after writing with _write_preprocess');
+
+$record->update(['foo' => ['value' => "b"]]);
+is($record->_data, ["ID" => 1, "x" => 42, 'foo' => '{"value":"b"}'], 'raw data after updating with _write_preprocess');
+is($record->foo, ['value' => "b"], 'field data after updating with _write_preprocess');