diff --git a/tests/dibi/DibiConnection.substitutions.phpt b/tests/dibi/DibiConnection.substitutions.phpt index 236c860a..caa4b782 100644 --- a/tests/dibi/DibiConnection.substitutions.phpt +++ b/tests/dibi/DibiConnection.substitutions.phpt @@ -11,16 +11,46 @@ $conn = new DibiConnection($config); $conn->getSubstitutes()->blog = 'wp_'; Assert::same( - reformat('UPDATE wp_items SET [text]=\'Hello World\''), - $conn->translate("UPDATE :blog:items SET [text]='Hello World'") + reformat('UPDATE wp_items SET [val]=1'), + $conn->translate('UPDATE :blog:items SET [val]=1') ); Assert::same( - reformat('UPDATE \'wp_\' SET [text]=\'Hello World\''), - $conn->translate("UPDATE :blog: SET [text]='Hello World'") + reformat('UPDATE [wp_items] SET [val]=1'), + $conn->translate('UPDATE [:blog:items] SET [val]=1') ); Assert::same( - reformat('UPDATE \':blg:\' SET [text]=\'Hello World\''), - $conn->translate("UPDATE :blg: SET [text]='Hello World'") + reformat("UPDATE 'wp_' SET [val]=1"), + $conn->translate('UPDATE :blog: SET [val]=1') +); + +Assert::same( + reformat("UPDATE ':blg:' SET [val]=1"), + $conn->translate('UPDATE :blg: SET [val]=1') +); + +Assert::same( + reformat("UPDATE table SET [text]=':blog:a'"), + $conn->translate("UPDATE table SET [text]=':blog:a'") +); + + +// create new substitution :: (empty) ==> my_ +$conn->getSubstitutes()->{''} = 'my_'; + +Assert::same( + reformat('UPDATE my_table SET [val]=1'), + $conn->translate('UPDATE ::table SET [val]=1') +); + + +// create substitutions using fallback callback +$conn->getSubstitutes()->setCallback(function ($expr) { + return '_' . $expr . '_'; +}); + +Assert::same( + reformat('UPDATE _account_user SET [val]=1'), + $conn->translate('UPDATE :account:user SET [val]=1') );