diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml index 03d7502c44..8a80819adf 100644 --- a/tests/data/db_structure.xml +++ b/tests/data/db_structure.xml @@ -135,4 +135,88 @@ + + + *dbprefix*vcategory + + + + + id + integer + 0 + true + 1 + true + 4 + + + + uid + text + + true + 64 + + + + type + text + + true + 64 + + + + category + text + + true + 255 + + + + uid_index + + uid + ascending + + + + + type_index + + type + ascending + + + + + category_index + + category + ascending + + + + + uid_type_category_index + true + + uid + ascending + + + type + ascending + + + category + ascending + + + + +
+ diff --git a/tests/lib/db.php b/tests/lib/db.php index 2344f7d8ec..5d30f6ac46 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -24,6 +24,7 @@ class Test_DB extends UnitTestCase { $this->test_prefix = $r; $this->table1 = $this->test_prefix.'contacts_addressbooks'; $this->table2 = $this->test_prefix.'contacts_cards'; + $this->table3 = $this->test_prefix.'vcategory'; } public function tearDown() { @@ -67,4 +68,29 @@ class Test_DB extends UnitTestCase { $result = $query->execute(array('uri_3')); $this->assertTrue($result); } + + public function testinsertIfNotExist() { + $categoryentries = array( + array('user' => 'test', 'type' => 'contact', 'category' => 'Family'), + array('user' => 'test', 'type' => 'contact', 'category' => 'Friends'), + array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'), + array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'), + array('user' => 'test', 'type' => 'contact', 'category' => 'School'), + ); + + foreach($categoryentries as $entry) { + $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table3, + array( + 'uid' => $entry['user'], + 'type' => $entry['type'], + 'category' => $entry['category'], + )); + $this->assertTrue($result); + } + + $query = OC_DB::prepare('SELECT * FROM *PREFIX*'.$this->table3); + $result = $query->execute(); + $this->assertTrue($result); + $this->assertEqual($result->numRows(), '4'); + } }