aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-06-27 11:19:12 +0200
committerGitHub <noreply@github.com>2024-06-27 11:19:12 +0200
commit2482688fa09d7dc477ad0d23049d55b62d5b3d6c (patch)
tree6068af538f743ef4ae560e9508ac144c0806bd19 /tests
parentec39228b89363e378fc4f851c9182985aa174878 (diff)
parentb7243681dd70b25fdefc9fe62c63bab840691c94 (diff)
downloadnextcloud-server-2482688fa09d7dc477ad0d23049d55b62d5b3d6c.tar.gz
nextcloud-server-2482688fa09d7dc477ad0d23049d55b62d5b3d6c.zip
Merge pull request #45655 from nextcloud/feat/mysql_ignore_conflics
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/DB/AdapterTest.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/lib/DB/AdapterTest.php b/tests/lib/DB/AdapterTest.php
new file mode 100644
index 00000000000..99b7cf4e099
--- /dev/null
+++ b/tests/lib/DB/AdapterTest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\DB;
+
+use Test\TestCase;
+
+class AdapterTest extends TestCase {
+ private string $appId;
+ private $connection;
+
+ public function setUp(): void {
+ $this->connection = \OC::$server->getDatabaseConnection();
+ $this->appId = uniqid('test_db_adapter', true);
+ }
+
+ public function tearDown(): void {
+ $qb = $this->connection->getQueryBuilder();
+
+ $qb->delete('appconfig')
+ ->from('appconfig')
+ ->where($qb->expr()->eq('appid', $qb->createNamedParameter($this->appId)))
+ ->execute();
+ }
+
+ public function testInsertIgnoreOnConflictDuplicate(): void {
+ $configKey = uniqid('key', true);
+ $expected = [
+ [
+ 'configkey' => $configKey,
+ 'configvalue' => '1',
+ ]
+ ];
+ $result = $this->connection->insertIgnoreConflict('appconfig', [
+ 'appid' => $this->appId,
+ 'configkey' => $configKey,
+ 'configvalue' => '1',
+ ]);
+ $this->assertEquals(1, $result);
+ $rows = $this->getRows($configKey);
+ $this->assertSame($expected, $rows);
+
+
+ $result = $this->connection->insertIgnoreConflict('appconfig', [
+ 'appid' => $this->appId,
+ 'configkey' => $configKey,
+ 'configvalue' => '2',
+ ]);
+ $this->assertEquals(0, $result);
+ $rows = $this->getRows($configKey);
+ $this->assertSame($expected, $rows);
+ }
+
+ private function getRows(string $configKey): array {
+ $qb = $this->connection->getQueryBuilder();
+ return $qb->select(['configkey', 'configvalue'])
+ ->from('appconfig')
+ ->where($qb->expr()->eq('appid', $qb->createNamedParameter($this->appId)))
+ ->andWhere($qb->expr()->eq('configkey', $qb->createNamedParameter($configKey)))
+ ->execute()
+ ->fetchAll();
+ }
+}