]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add test for UniqueConstraintViolationException on wrong key
authorJoas Schilling <nickvergessen@owncloud.com>
Tue, 10 Mar 2015 08:26:45 +0000 (09:26 +0100)
committerJoas Schilling <nickvergessen@owncloud.com>
Tue, 10 Mar 2015 08:26:45 +0000 (09:26 +0100)
tests/lib/db.php

index 056ce535436fee59ace0dbc087734982142ecf2a..1fb384ca9c617b1d840fc5689576a19f32fa9370 100644 (file)
@@ -217,6 +217,38 @@ class Test_DB extends \Test\TestCase {
                $this->assertEquals(0, $result);
        }
 
+       public function insertIfNotExistsViolatingThrows() {
+               return [
+                       [null],
+                       [['etag']],
+               ];
+       }
+
+       /**
+        * @dataProvider insertIfNotExistsViolatingThrows
+        * @expectedException \Doctrine\DBAL\Exception\UniqueConstraintViolationException
+        *
+        * @param array $compareKeys
+        */
+       public function testInsertIfNotExistsViolatingThrows($compareKeys) {
+               $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
+                       array(
+                               'storage' => 1,
+                               'path_hash' => md5('welcome.txt'),
+                               'etag' => $this->getUniqueID()
+                       ));
+               $this->assertEquals(1, $result);
+
+               $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
+                       array(
+                               'storage' => 1,
+                               'path_hash' => md5('welcome.txt'),
+                               'etag' => $this->getUniqueID()
+                       ), $compareKeys);
+
+               $this->assertEquals(0, $result);
+       }
+
        public function testUtf8Data() {
                $table = "*PREFIX*{$this->table2}";
                $expected = "ะ‹รถ้›™ๅ–œ\xE2\x80\xA2";