Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2022-06-18 15:11:35 +0300
committerAleksander Machniak <alec@alec.pl>2022-06-18 15:11:35 +0300
commit1e5d87c97cccbf476d097c7104918bd8a98b2deb (patch)
treee8793ad25b2a5e5b612ed2eb7fdeea3778276947 /tests
parentb381d992306eeefed14994d020026959937870a3 (diff)
Fix support for DSN specification without host e.g. pgsql:///dbname (#8558)
Diffstat (limited to 'tests')
-rw-r--r--tests/Framework/DB.php23
-rw-r--r--tests/Framework/DBPgsql.php20
2 files changed, 37 insertions, 6 deletions
diff --git a/tests/Framework/DB.php b/tests/Framework/DB.php
index 39882ff19..09d40eac1 100644
--- a/tests/Framework/DB.php
+++ b/tests/Framework/DB.php
@@ -180,12 +180,23 @@ class Framework_DB extends PHPUnit\Framework\TestCase
$result = rcube_db::parse_dsn($dsn);
- $this->assertSame('mysql', $result['phptype'], "DSN parser: phptype");
- $this->assertSame('USERNAME', $result['username'], "DSN parser: username");
- $this->assertSame('PASSWORD', $result['password'], "DSN parser: password");
- $this->assertSame('3306', $result['port'], "DSN parser: port");
- $this->assertSame('HOST', $result['hostspec'], "DSN parser: hostspec");
- $this->assertSame('DATABASE', $result['database'], "DSN parser: database");
+ $this->assertSame('mysql', $result['phptype']);
+ $this->assertSame('USERNAME', $result['username']);
+ $this->assertSame('PASSWORD', $result['password']);
+ $this->assertSame('3306', $result['port']);
+ $this->assertSame('HOST', $result['hostspec']);
+ $this->assertSame('DATABASE', $result['database']);
+
+ $dsn = "pgsql:///DATABASE";
+
+ $result = rcube_db::parse_dsn($dsn);
+
+ $this->assertSame('pgsql', $result['phptype']);
+ $this->assertTrue(!array_key_exists('username', $result));
+ $this->assertTrue(!array_key_exists('password', $result));
+ $this->assertTrue(!array_key_exists('port', $result));
+ $this->assertTrue(!array_key_exists('hostspec', $result));
+ $this->assertSame('DATABASE', $result['database']);
}
/**
diff --git a/tests/Framework/DBPgsql.php b/tests/Framework/DBPgsql.php
index c2ba45238..86f30a8ff 100644
--- a/tests/Framework/DBPgsql.php
+++ b/tests/Framework/DBPgsql.php
@@ -71,4 +71,24 @@ class Framework_DBPgsql extends PHPUnit\Framework\TestCase
$this->assertSame($output[$idx], $res, "Test case $idx");
}
}
+
+ /**
+ * Test converting config DSN string into PDO connection string
+ */
+ function test_dsn_string()
+ {
+ $db = new rcube_db_pgsql('test');
+
+ $dsn = $db->parse_dsn("pgsql://USERNAME:PASSWORD@HOST:5432/DATABASE");
+ $result = invokeMethod($db, 'dsn_string', [$dsn]);
+ $this->assertSame("pgsql:host=HOST;port=5432;dbname=DATABASE", $result);
+
+ $dsn = $db->parse_dsn("pgsql:///DATABASE");
+ $result = invokeMethod($db, 'dsn_string', [$dsn]);
+ $this->assertSame("pgsql:dbname=DATABASE", $result);
+
+ $dsn = $db->parse_dsn("pgsql://user@unix(/var/run/postgresql)/roundcubemail?sslmode=verify-full");
+ $result = invokeMethod($db, 'dsn_string', [$dsn]);
+ $this->assertSame("pgsql:host=/var/run/postgresql;dbname=roundcubemail;sslmode=verify-full", $result);
+ }
}