summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/it_dbi.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index cec097e..b29b164 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -327,3 +327,38 @@ $record->update(['-key3' => "2*2"]); is($record->key1, "val1"); is($
$record->update(['key1' => "val0"]); is($record->key1, "val0"); is($record->key2, "val2"); is($record->key3, 4);
$record->replace(['ID' => 6, 'key4' => "val4"]); is($record->key4, "val4");
$record->select(['key2' => "val2"]); is($record->key2, "val2"); is($record->key4, null, "clear previous fields");
+
+#
+# Test tracked update
+#
+function allrecs()
+{
+ foreach (new it_dbi_test() as $r)
+ $result[] = ['ID' => $r->ID, 'foo' => $r->foo];
+ return json_encode($result);
+}
+
+$record = new it_dbi_test;
+$record->delete(['WHERE 1' ]);
+$record->upsert(['ID' => 1, 'foo' => "a"]);
+$record->upsert(['ID' => 2, 'foo' => "b"]);
+$record->upsert(['ID' => 2, 'foo' => "B"]);
+is($record->delete_untouched(), 0, 'delete_untouched');
+is(allrecs(), '[{"ID":1,"foo":"a"},{"ID":2,"foo":"B"}]', 'data after delete_untouched');
+
+$record->upsert(['ID' => 1, 'foo' => "A"]);
+$record->upsert(['ID' => 3, 'foo' => "c"]);
+is($record->delete_untouched([ 'ID >' => 2 ]), 0, 'delete_untouched with query');
+is(allrecs(), '[{"ID":1,"foo":"A"},{"ID":2,"foo":"B"},{"ID":3,"foo":"c"}]', 'data after delete_untouched with query');
+
+$record->upsert(['ID' => 3, 'foo' => "C"]);
+is($record->delete_untouched(), 2, 'delete_untouched with query');
+is(allrecs(), '[{"ID":3,"foo":"C"}]', 'data after delete_untouched with query');
+
+$record->replace(['ID' => 4, 'foo' => "C"]);
+is($record->delete_untouched(), 1, 'delete_untouched after replace');
+is(allrecs(), '[{"ID":4,"foo":"C"}]', 'data after delete_untouched after replace');
+
+$record->upsert(['ID' => 4, 'foo' => "C"]);
+is($record->delete_untouched(), 0, 'delete_untouched after upsert without changes');
+is(allrecs(), '[{"ID":4,"foo":"C"}]', 'data after delete_untouched after upsert without changes');