From b20018928d9500faba89d5f3af0fc483f866d4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 1 Jul 2014 18:03:32 +0200 Subject: [PATCH] add unit test --- tests/lib/db.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/lib/db.php b/tests/lib/db.php index 2fca67b563..5f65e88c3b 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -125,6 +125,28 @@ class Test_DB extends PHPUnit_Framework_TestCase { $this->assertEquals(4, count($result->fetchAll())); } + public function testInsertIfNotExistNull() { + $categoryentries = array( + array('addressbookid' => 123, 'fullname' => null, 'expectedResult' => 1), + array('addressbookid' => 123, 'fullname' => null, 'expectedResult' => 0), + array('addressbookid' => 123, 'fullname' => 'test', 'expectedResult' => 1), + ); + + foreach($categoryentries as $entry) { + $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2, + array( + 'addressbookid' => $entry['addressbookid'], + 'fullname' => $entry['fullname'], + )); + $this->assertEquals($entry['expectedResult'], $result); + } + + $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table2.'`'); + $result = $query->execute(); + $this->assertTrue((bool)$result); + $this->assertEquals(2, count($result->fetchAll())); + } + public function testinsertIfNotExistDontOverwrite() { $fullname = 'fullname test'; $uri = 'uri_1';