mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-09-26 04:02:51 +02:00
test(core): unit tests for Util/Database/Enum pure logic (+44 tests)
Adds tests for Encryption, TimeUtils, QueryHelper, AdminHelpers, ImageUtils, StreamUtils and BootContext/ServerEnvironment enums. 242 -> 286 tests, all green.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers QueryHelper
|
||||
*/
|
||||
final class QueryHelperTest extends TestCase {
|
||||
|
||||
public function testPrepareColumnSanitizesToSafeIdentifier() {
|
||||
$this->assertSame('foobar23', QueryHelper::prepareColumn('Foo Bar!23'));
|
||||
$this->assertSame('user_id', QueryHelper::prepareColumn('user_id'));
|
||||
$this->assertSame('droptable', QueryHelper::prepareColumn('drop;table'));
|
||||
}
|
||||
|
||||
public function testPrepareArrayBuildsColumnsPlaceholdersAndData() {
|
||||
$result = QueryHelper::prepareArray(array('name' => 'x', 'age' => 5));
|
||||
|
||||
$this->assertSame('`name`,`age`', $result['columns']);
|
||||
$this->assertSame('?,?', $result['placeholder']);
|
||||
$this->assertSame(array('x', 5), $result['data']);
|
||||
$this->assertSame('`name` = ?,`age` = ?', $result['update']);
|
||||
}
|
||||
|
||||
public function testPrepareArrayJsonEncodesArrayValues() {
|
||||
$result = QueryHelper::prepareArray(array('tags' => array(1, 2, 3)));
|
||||
$this->assertSame('[1,2,3]', $result['data'][0]);
|
||||
}
|
||||
|
||||
public function testPrepareArrayNormalizesNullValues() {
|
||||
$result = QueryHelper::prepareArray(array('a' => null, 'b' => 'null'));
|
||||
$this->assertNull($result['data'][0]);
|
||||
$this->assertNull($result['data'][1]);
|
||||
}
|
||||
|
||||
public function testPrepareArraySanitizesColumnNames() {
|
||||
$result = QueryHelper::prepareArray(array('na me!' => 'v'));
|
||||
$this->assertSame('`name`', $result['columns']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user