diff options
Diffstat (limited to 'tests/lib/DB/LegacyDBTest.php')
-rw-r--r-- | tests/lib/DB/LegacyDBTest.php | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/tests/lib/DB/LegacyDBTest.php b/tests/lib/DB/LegacyDBTest.php index 3cf40228225..578d28139bc 100644 --- a/tests/lib/DB/LegacyDBTest.php +++ b/tests/lib/DB/LegacyDBTest.php @@ -134,140 +134,6 @@ class LegacyDBTest extends \Test\TestCase { // now we can check if the two ids are in correct order $this->assertGreaterThan($id1, $id2); } - - public function testinsertIfNotExist() { - $categoryEntries = array( - array('user' => 'test', 'type' => 'contact', 'category' => 'Family', 'expectedResult' => 1), - array('user' => 'test', 'type' => 'contact', 'category' => 'Friends', 'expectedResult' => 1), - array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers', 'expectedResult' => 1), - array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers', 'expectedResult' => 0), - array('user' => 'test', 'type' => 'contact', 'category' => 'School', 'expectedResult' => 1), - ); - - foreach($categoryEntries as $entry) { - $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table3, - array( - 'uid' => $entry['user'], - 'type' => $entry['type'], - 'category' => $entry['category'], - )); - $this->assertEquals($entry['expectedResult'], $result); - } - - $query = OC_DB::prepare('SELECT * FROM `*PREFIX*'.$this->table3.'`'); - $result = $query->execute(); - $this->assertTrue((bool)$result); - $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 = \OCP\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'; - $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->assertEquals(1, $result); - $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array($uri)); - $this->assertTrue((bool)$result); - $rowset = $result->fetchAll(); - $this->assertEquals(1, count($rowset)); - $this->assertArrayHasKey('carddata', $rowset[0]); - $this->assertEquals($carddata, $rowset[0]['carddata']); - - // Try to insert a new row - $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table2, - array( - 'fullname' => $fullName, - 'uri' => $uri, - )); - $this->assertEquals(0, $result); - - $query = OC_DB::prepare('SELECT `fullname`, `uri`, `carddata` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(array($uri)); - $this->assertTrue((bool)$result); - // Test that previously inserted data isn't overwritten - // And that a new row hasn't been inserted. - $rowset = $result->fetchAll(); - $this->assertEquals(1, count($rowset)); - $this->assertArrayHasKey('carddata', $rowset[0]); - $this->assertEquals($carddata, $rowset[0]['carddata']); - } - - public function testInsertIfNotExistsViolating() { - $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() - ),['storage', 'path_hash']); - - $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}"; |