1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
<?php
namespace Illuminate\Tests\Integration\Database\Sqlite;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;
use RuntimeException;
class EscapeTest extends DatabaseTestCase
{
protected function getEnvironmentSetUp($app)
{
if (getenv('DB_CONNECTION') !== 'testing') {
$this->markTestSkipped('Test requires a Sqlite connection.');
}
$app['config']->set('database.default', 'conn1');
$app['config']->set('database.connections.conn1', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}
public function testEscapeInt()
{
$this->assertSame('42', $this->app['db']->escape(42));
$this->assertSame('-6', $this->app['db']->escape(-6));
}
public function testEscapeFloat()
{
$this->assertSame('3.14159', $this->app['db']->escape(3.14159));
$this->assertSame('-3.14159', $this->app['db']->escape(-3.14159));
}
public function testEscapeBool()
{
$this->assertSame('1', $this->app['db']->escape(true));
$this->assertSame('0', $this->app['db']->escape(false));
}
public function testEscapeNull()
{
$this->assertSame('null', $this->app['db']->escape(null));
$this->assertSame('null', $this->app['db']->escape(null, true));
}
public function testEscapeBinary()
{
$this->assertSame("x'dead00beef'", $this->app['db']->escape(hex2bin('dead00beef'), true));
}
public function testEscapeString()
{
$this->assertSame("'2147483647'", $this->app['db']->escape('2147483647'));
$this->assertSame("'true'", $this->app['db']->escape('true'));
$this->assertSame("'false'", $this->app['db']->escape('false'));
$this->assertSame("'null'", $this->app['db']->escape('null'));
$this->assertSame("'Hello''World'", $this->app['db']->escape("Hello'World"));
}
public function testEscapeStringInvalidUtf8()
{
$this->expectException(RuntimeException::class);
$this->app['db']->escape("I am hiding an invalid \x80 utf-8 continuation byte");
}
public function testEscapeStringNullByte()
{
$this->expectException(RuntimeException::class);
$this->app['db']->escape("I am hiding a \00 byte");
}
public function testEscapeArray()
{
$this->expectException(RuntimeException::class);
$this->app['db']->escape(['a', 'b']);
}
}
|