From f8d3b7cb6f5d08cac6ae160c749f923d62ef1378 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 12 Dec 2013 13:14:43 +0100 Subject: [PATCH 1/3] DB tests: Test whether we can insert and read UTF8 data. --- tests/lib/db.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/lib/db.php b/tests/lib/db.php index 1977025cf12..96be3ea909e 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -145,4 +145,17 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertEquals(1, $result->numRows()); } + + public function testUtf8Data() { + $table = "*PREFIX*{$this->table2}"; + $conn = OC_DB::getConnection(); + $data = array( + 'uri' => 'uri_1', + 'fullname' => "Ћö雙喜\xE2\x80\xA2", + 'carddata' => 'This is a vCard', + ); + $conn->insert($table, $data); + $row = $conn->fetchAssoc("SELECT * FROM $table"); + $this->assertSame($data['fullname'], $row['fullname']); + } } From 95dd58bfc079fd9a46b1928ce22d5fb3faad44bd Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 12 Dec 2013 15:24:35 +0100 Subject: [PATCH 2/3] Use old school query style that actually works. --- tests/lib/db.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/lib/db.php b/tests/lib/db.php index 96be3ea909e..6b6d6b91088 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -148,14 +148,13 @@ class Test_DB extends PHPUnit_Framework_TestCase { public function testUtf8Data() { $table = "*PREFIX*{$this->table2}"; - $conn = OC_DB::getConnection(); - $data = array( - 'uri' => 'uri_1', - 'fullname' => "Ћö雙喜\xE2\x80\xA2", - 'carddata' => 'This is a vCard', - ); - $conn->insert($table, $data); - $row = $conn->fetchAssoc("SELECT * FROM $table"); - $this->assertSame($data['fullname'], $row['fullname']); + $expected = "Ћö雙喜\xE2\x80\xA2"; + + $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); + $result = $query->execute(array($expected, 'uri_1', 'This is a vCard')); + $this->assertEquals(1, $result); + + $actual = OC_DB::prepare("SELECT `fullname` FROM $table")->execute()->fetchOne(); + $this->assertSame($expected, $actual); } } From ab4136f4329bf702e72e6eaa3fd1e32b1c1f1cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 17 Dec 2013 10:05:20 +0100 Subject: [PATCH 3/3] add missing quotes + field declarations --- tests/lib/db.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/lib/db.php b/tests/lib/db.php index 6b6d6b91088..3fcdf8a7dc6 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -12,6 +12,21 @@ class Test_DB extends PHPUnit_Framework_TestCase { protected static $schema_file = 'static://test_db_scheme'; protected $test_prefix; + /** + * @var string + */ + private $table1; + + /** + * @var string + */ + private $table2; + + /** + * @var string + */ + private $table3; + public function setUp() { $dbfile = OC::$SERVERROOT.'/tests/data/db_structure.xml'; @@ -154,7 +169,7 @@ class Test_DB extends PHPUnit_Framework_TestCase { $result = $query->execute(array($expected, 'uri_1', 'This is a vCard')); $this->assertEquals(1, $result); - $actual = OC_DB::prepare("SELECT `fullname` FROM $table")->execute()->fetchOne(); + $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne(); $this->assertSame($expected, $actual); } }