Skip to content

Commit

Permalink
tests: added complex test for %like
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 22, 2018
1 parent 4abe874 commit 0fb63f3
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/dibi/Translator.like.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

use Tester\Assert;

require __DIR__ . '/bootstrap.php';


$conn = new Dibi\Connection($config);

// starts with
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'a', 'b'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'baa', 'aa'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', 'aab', 'aa'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'bba', '%a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', '%ba', '%a'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', '%ab', '%a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'aa', '_a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', '_b', '_a'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', '_ab', '_a'));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', 'a"a', 'a"'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'b"', '%"'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', '%"', '%"'));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', "a'a", "a'"));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', "b'", "%'"));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', "%'", "%'"));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', 'a\\a', 'a\\'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'b\\', '%\\'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', '%\\', '%\\'));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', 'a[a', 'a['));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %like~', 'b[', '%['));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %like~', '%[', '%['));


// ends with
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', 'a', 'b'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', 'baa', 'aa'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', 'aab', 'aa'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', 'bba', '%a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', 'a%b', '%a'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', 'b%a', '%a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', 'aa', '_a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', '_b', '_a'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', 'b_a', '_a'));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', 'a"a', '"a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', '"b', '"%'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', '"%', '"%'));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', "a'a", "'a"));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', "'b", "'%"));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', "'%", "'%"));

Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', 'a\\a', '\\a'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like', '\\b', '\\%'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like', '\\%', '\\%'));


// contains
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like~', 'a', 'b'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like~', 'baa', 'aa'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like~', 'aab', 'aa'));
Assert::same(0, $conn->fetchSingle('SELECT ? LIKE %~like~', 'bba', '%a'));
Assert::same(1, $conn->fetchSingle('SELECT ? LIKE %~like~', 'b%a', '%a'));

4 comments on commit 0fb63f3

@jan-oliva
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test jsem nepsal, jen jsem to testoval hlavně v souvislosti s ublaboo datagridem a DIBI datasource a nic chybného v LIKE mi to negenerovalo. Zkoušel jsem dost možností a ten escape \

@dg
Copy link
Owner Author

@dg dg commented on 0fb63f3 Aug 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tak zkus, jestli funguje i s Firebirdem.

@jan-oliva
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testoval jsem to přímo na Firebird 2.5 . Verzi 3x nikde zatím nikde nemám instalovanou.
Samotný LIKE nevykazoval žádné anomálie.

Spíš ten myslím, že DIBI datasource pro ublaboo se nad firebirdem chová trochu nestandardně, myslím dává názvy sloupců do "", ale když udělám dotaz přímo nad DIBI fluentu taj je to OK.

@jan-oliva
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nezkoušel jsem spuštěním toho testu, zatím jen v aplikaci s napojením na Firebird 2.5.

Please sign in to comment.