summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Bootstrap.php19
-rw-r--r--tests/codeigniter/database/DB_driver_test.php4
-rw-r--r--tests/codeigniter/database/DB_test.php4
-rw-r--r--tests/codeigniter/database/query_builder/escape_test.php54
-rwxr-xr-xtests/mocks/database/ci_test.sqlitebin19456 -> 19456 bytes
-rw-r--r--tests/mocks/database/schema/skeleton.php21
6 files changed, 95 insertions, 7 deletions
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
index 9f89d1be8..38615dd89 100644
--- a/tests/Bootstrap.php
+++ b/tests/Bootstrap.php
@@ -12,8 +12,25 @@ define('BASEPATH', PROJECT_BASE.'system/');
define('APPPATH', PROJECT_BASE.'application/');
define('VIEWPATH', PROJECT_BASE.'');
+// Get vfsStream either via PEAR or composer
+foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
+{
+ if (file_exists($path.DIRECTORY_SEPARATOR.'vfsStream/vfsStream.php'))
+ {
+ require_once 'vfsStream/vfsStream.php';
+ break;
+ }
+}
+
+if ( ! class_exists('vfsStream') && file_exists(PROJECT_BASE.'vendor/autoload.php'))
+{
+ include_once PROJECT_BASE.'vendor/autoload.php';
+ class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
+ class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
+ class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
+}
+
// Prep our test environment
-require_once 'vfsStream/vfsStream.php';
include_once $dir.'/mocks/core/common.php';
include_once $dir.'/mocks/autoloader.php';
spl_autoload_register('autoload');
diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php
index fb40f0608..9e16e29b4 100644
--- a/tests/codeigniter/database/DB_driver_test.php
+++ b/tests/codeigniter/database/DB_driver_test.php
@@ -2,8 +2,6 @@
class DB_driver_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_initialize()
{
$config = Mock_Database_DB::config(DB_DRIVER);
@@ -32,5 +30,5 @@ class DB_driver_test extends CI_TestCase {
{
return new Mock_Database_Drivers_Postgre($config);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php
index 9b93e223d..d5c0dea08 100644
--- a/tests/codeigniter/database/DB_test.php
+++ b/tests/codeigniter/database/DB_test.php
@@ -2,8 +2,6 @@
class DB_test extends CI_TestCase {
- // ------------------------------------------------------------------------
-
public function test_db_invalid()
{
$connection = new Mock_Database_DB(array(
@@ -45,5 +43,5 @@ class DB_test extends CI_TestCase {
$this->assertTrue($db instanceof CI_DB);
$this->assertTrue($db instanceof CI_DB_Driver);
}
-
+
} \ No newline at end of file
diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php
new file mode 100644
index 000000000..50685922a
--- /dev/null
+++ b/tests/codeigniter/database/query_builder/escape_test.php
@@ -0,0 +1,54 @@
+<?php
+
+class Escape_test extends CI_TestCase {
+
+ /**
+ * @var object Database/Query Builder holder
+ */
+ protected $db;
+
+ public function set_up()
+ {
+ $this->db = Mock_Database_Schema_Skeleton::init(DB_DRIVER);
+
+ Mock_Database_Schema_Skeleton::create_tables();
+ Mock_Database_Schema_Skeleton::create_data();
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_percent_sign()
+ {
+ $string = '\%foo'
+;
+ $this->db->select('value');
+ $this->db->from('misc');
+ $this->db->like('key', $string, 'after');
+ $res = $this->db->get();
+
+ // Check the result
+ $this->assertEquals(1, count($res->result_array()));
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see ./mocks/schema/skeleton.php
+ */
+ public function test_escape_like_backslash_sign()
+ {
+ $string = '\\';
+
+ $this->db->select('value');
+ $this->db->from('misc');
+ $this->db->like('key', $string, 'after');
+ $res = $this->db->get();
+
+ // Check the result
+ $this->assertEquals(2, count($res->result_array()));
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite
index 23a3de2a4..44dcef9ec 100755
--- a/tests/mocks/database/ci_test.sqlite
+++ b/tests/mocks/database/ci_test.sqlite
Binary files differ
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
index 671336cc4..05499f82f 100644
--- a/tests/mocks/database/schema/skeleton.php
+++ b/tests/mocks/database/schema/skeleton.php
@@ -88,6 +88,23 @@ class Mock_Database_Schema_Skeleton {
));
static::$forge->add_key('id', TRUE);
static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+
+ // Misc Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'key' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'value' => array(
+ 'type' => 'TEXT',
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('misc', (strpos(static::$driver, 'pgsql') === FALSE));
}
/**
@@ -111,6 +128,10 @@ class Mock_Database_Schema_Skeleton {
array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
),
+ 'misc' => array(
+ array('id' => 1, 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx'),
+ array('id' => 2, 'key' => '\\%foo456', 'value' => 'Entry with \\%'),
+ ),
);
foreach ($data as $table => $dummy_data)