initial commit
This commit is contained in:
commit
5ebc506921
975 changed files with 154341 additions and 0 deletions
91
tests/unit_tests/01_basic/db.php
Normal file
91
tests/unit_tests/01_basic/db.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
use KD2\Test;
|
||||
|
||||
const DB_FILE = ':memory:';
|
||||
const INSTALL_PROCESS = true;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
// test exec
|
||||
Test::assert($db->exec('CREATE TABLE test (a, b);'));
|
||||
|
||||
// test insert
|
||||
Test::assert($db->insert('test', ['a' => 1, 'b' => 2]));
|
||||
Test::assert($db->insert('test', ['a' => 3, 'b' => 4]));
|
||||
|
||||
// test insert object
|
||||
Test::assert($db->insert('test', (object) ['a' => 9, 'b' => 10]));
|
||||
|
||||
// test fetch
|
||||
Test::equals((object)['a' => 1, 'b' => 2], $db->first('SELECT a, b FROM test;'));
|
||||
Test::assert(is_object($db->first('SELECT a, b FROM test;')));
|
||||
Test::equals(1, $db->firstColumn('SELECT a, b FROM test;'));
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test update
|
||||
Test::assert($db->update('test', ['a' => 5, 'b' => 6], 'a = :a AND b = :b', ['a' => 3, 'b' => 4]));
|
||||
|
||||
// test update with mixed type bindings
|
||||
try {
|
||||
$db->update('test', ['a' => 5, 'b' => 6], 'a = ? AND b = ?', [3, 4]);
|
||||
$failed = false;
|
||||
}
|
||||
catch (\LogicException $e) {
|
||||
$failed = true;
|
||||
}
|
||||
|
||||
Test::assert($failed === true);
|
||||
|
||||
// test if update worked
|
||||
Test::equals((object)['a' => 5, 'b' => 6], $db->first('SELECT a, b FROM test LIMIT 1, 1;'));
|
||||
|
||||
// test delete
|
||||
Test::assert($db->delete('test', 'a = ? AND b = ?', 5, 6));
|
||||
|
||||
// test if delete worked
|
||||
Test::equals(2, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test insert again
|
||||
Test::assert(is_bool($db->insert('test', ['a' => 3, 'b' => 4])));
|
||||
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// Test bindings
|
||||
Test::equals(1, $db->firstColumn('SELECT a, b FROM test WHERE a = :a;', ['a' => 1]));
|
||||
Test::equals((object) ['a' => 1, 'b' => 2], $db->first('SELECT a, b FROM test WHERE a = ?;', 1));
|
||||
|
||||
// test SELECT
|
||||
$expected = [(object)['a' => 1, 'b' => 2], (object)['a' => 9, 'b' => 10]];
|
||||
Test::equals($expected, $db->get('SELECT * FROM test LIMIT 2;'));
|
||||
|
||||
$expected = [1 => 2, 9 => 10];
|
||||
Test::equals($expected, $db->getAssoc('SELECT * FROM test LIMIT 2;'));
|
||||
|
||||
$expected = [1 => (object) ['a' => 1, 'b' => 2], 9 => (object) ['a' => 9, 'b' => 10]];
|
||||
Test::equals(json_encode($expected), json_encode($db->getGrouped('SELECT * FROM test LIMIT 2;')));
|
||||
|
||||
// test transactions
|
||||
Test::assert($db->begin());
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 42, 'b' => 43]));
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 44, 'b' => 45]));
|
||||
|
||||
// test rollback
|
||||
Test::assert($db->rollback());
|
||||
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test successful commit
|
||||
Test::assert($db->begin());
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 42, 'b' => 43]));
|
||||
|
||||
Test::assert($db->commit());
|
||||
|
||||
Test::equals(4, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
15
tests/unit_tests/01_basic/paths.php
Normal file
15
tests/unit_tests/01_basic/paths.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::assert(defined('Garradin\ROOT'));
|
||||
Test::assert(is_readable(ROOT));
|
||||
|
||||
Test::assert(defined('Garradin\PLUGINS_ROOT'));
|
||||
|
||||
Test::assert(defined('Garradin\DATA_ROOT'));
|
||||
|
||||
Test::assert(defined('Garradin\CACHE_ROOT'));
|
||||
9
tests/unit_tests/01_basic/version.php
Normal file
9
tests/unit_tests/01_basic/version.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::assert(function_exists('Garradin\paheko_version'));
|
||||
Test::assert(paheko_version());
|
||||
18
tests/unit_tests/02_accounting/money.php
Normal file
18
tests/unit_tests/02_accounting/money.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::strictlyEquals(500, Utils::moneyToInteger('5'));
|
||||
Test::strictlyEquals(442, Utils::moneyToInteger('4,42'));
|
||||
Test::strictlyEquals(442, Utils::moneyToInteger('4.42'));
|
||||
Test::strictlyEquals(4, Utils::moneyToInteger('0,04'));
|
||||
Test::strictlyEquals(30, Utils::moneyToInteger('0,3'));
|
||||
Test::strictlyEquals(202034, Utils::moneyToInteger('2020,34'));
|
||||
|
||||
Test::strictlyEquals('5,50', Utils::money_format(550));
|
||||
Test::strictlyEquals('0,05', Utils::money_format(5));
|
||||
Test::strictlyEquals('0,50', Utils::money_format(50));
|
||||
Test::strictlyEquals('1 000,50', Utils::money_format(100050));
|
||||
Loading…
Add table
Add a link
Reference in a new issue