diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-10-31 16:51:36 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-10-31 16:51:36 +0100 |
commit | b434c20c18a389521bb0a30fa7c0c025bb6dd50c (patch) | |
tree | 4b383383615104692bffdad90583b52744fa82f1 /tests | |
parent | 5fc0c89a735229036a922629c5791444f8ab215f (diff) | |
download | nextcloud-server-b434c20c18a389521bb0a30fa7c0c025bb6dd50c.tar.gz nextcloud-server-b434c20c18a389521bb0a30fa7c0c025bb6dd50c.zip |
Added unit test testinsertIfNotExistDontOverwrite.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/db.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/lib/db.php b/tests/lib/db.php index 5d30f6ac46c..ead4b19b38e 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -93,4 +93,41 @@ class Test_DB extends UnitTestCase { $this->assertTrue($result); $this->assertEqual($result->numRows(), '4'); } + + public function testinsertIfNotExistDontOverwrite() { + $fullname = 'fullname test'; + $uri = 'uri_1'; + $carddata = 'This is a vCard'; + + // Normal test to have same known data inserted. + $query = OC_DB::prepare('INSERT INTO *PREFIX*'.$this->table2.' (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)'); + $result = $query->execute(array($fullname, $uri, $carddata)); + $this->assertTrue($result); + $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array($uri)); + $this->assertTrue($result); + $row = $result->fetchRow(); + $this->assertArrayHasKey('carddata', $row); + $this->assertEqual($row['carddata'], $carddata); + $this->assertEqual($result->numRows(), '1'); + + // Try to insert a new row + $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2, + array( + 'fullname' => $fullname, + 'uri' => $uri, + )); + $this->assertTrue($result); + + $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'.$this->table2.' WHERE `uri` = ?'); + $result = $query->execute(array($uri)); + $this->assertTrue($result); + $row = $result->fetchRow(); + $this->assertArrayHasKey('carddata', $row); + // Test that previously inserted data isn't overwritten + $this->assertEqual($row['carddata'], $carddata); + // And that a new row hasn't been inserted. + $this->assertEqual($result->numRows(), '1'); + + } } |