aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/includes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/includes')
-rw-r--r--tests/unit/includes/AccountTest.php21
-rw-r--r--tests/unit/includes/BBCodeTest.php51
-rw-r--r--tests/unit/includes/DatetimeTest.php53
-rw-r--r--tests/unit/includes/ItemsTest.php132
-rw-r--r--tests/unit/includes/LanguageTest.php8
-rw-r--r--tests/unit/includes/MarkdownTest.php35
-rw-r--r--tests/unit/includes/NetworkTest.php58
-rw-r--r--tests/unit/includes/PhotodriverTest.php58
-rw-r--r--tests/unit/includes/dba/DbaPdoTest.php140
-rw-r--r--tests/unit/includes/dba/_files/account.yml17
-rw-r--r--tests/unit/includes/dba/_files/register.yml20
11 files changed, 575 insertions, 18 deletions
diff --git a/tests/unit/includes/AccountTest.php b/tests/unit/includes/AccountTest.php
index 3978f9d04..66c761ef5 100644
--- a/tests/unit/includes/AccountTest.php
+++ b/tests/unit/includes/AccountTest.php
@@ -1,9 +1,28 @@
<?php
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+
/**
* Tests for account handling helper functions.
*/
+class AccountTest extends UnitTestCase {
+
+ /**
+ * Test the `get_account_id()` function.
+ */
+ public function test_get_account_id() {
+ App::set_account(null);
+ unset($_SESSION['account_id']);
+
+ $this->assertEquals(false, get_account_id(), 'get_account_id() should return false if not authenticated');
+
+ App::set_account(['account_id' => 36]);
+ $this->assertEquals(36, get_account_id(), 'get_account_id() should return account from global App object');
+
+ $_SESSION['account_id'] = 42;
+ $this->assertEquals(42, get_account_id(), 'get_account_id() should return the account from the session');
+ }
-class AccountTest extends Zotlabs\Tests\Unit\UnitTestCase {
public function test_get_account_by_id_returns_existing_account() {
$account = get_account_by_id(42);
$this->assertNotFalse($account);
diff --git a/tests/unit/includes/BBCodeTest.php b/tests/unit/includes/BBCodeTest.php
index daa66bf72..982ef4eb9 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -23,6 +23,7 @@
namespace Zotlabs\Tests\Unit\includes;
+use App;
use Zotlabs\Tests\Unit\UnitTestCase;
class BBCodeTest extends UnitTestCase {
@@ -42,7 +43,7 @@ class BBCodeTest extends UnitTestCase {
*/
public function test_bbcode_observer(string $src, bool $logged_in, string $lang, string $expected): void {
if ($logged_in) {
- \App::$observer = [
+ App::set_observer([
'xchan_addr' => '',
'xchan_name' => '',
'xchan_connurl' => '',
@@ -50,9 +51,9 @@ class BBCodeTest extends UnitTestCase {
// port required in xchan url due to bug in get_rpost_path
'xchan_url' => 'https://example.com:666',
- ];
+ ]);
} else {
- \App::$observer = null;
+ App::set_observer(null);
}
\App::$language = $lang;
@@ -138,7 +139,39 @@ class BBCodeTest extends UnitTestCase {
'del tag' => [
'some [s]strike through[/s] text',
'some <del>strike through</del> text'
- ]
+ ],
+ 'naked url is converted to link' => [
+ 'example url: https://example.com',
+ 'example url: <a href="https://example.com" target="_blank" rel="nofollow noopener">https://example.com</a>'
+ ],
+ 'naked url followed by newline' => [
+ "https://www.example.com\nhave a great day.",
+ '<a href="https://www.example.com" target="_blank" rel="nofollow noopener">https://www.example.com</a><br />have a great day.',
+ ],
+ 'inline naked url' => [
+ "This is a link https://example.com/some/path more info.",
+ 'This is a link <a href="https://example.com/some/path" target="_blank" rel="nofollow noopener">https://example.com/some/path</a> more info.',
+ ],
+ 'naked url within code block is not converted to link' => [
+ "[code]\nhttp://example.com\n[/code]",
+ "<pre><code>http://example.com</code></pre>"
+ ],
+ 'geo uri is converted to link' => [
+ 'example url: [url]geo:37.786971,-122.399677;u=35[/url]',
+ 'example url: <a href="geo:37.786971,-122.399677;u=35" target="_blank" rel="nofollow noopener">geo:37.786971,-122.399677;u=35</a>'
+ ],
+ 'geo uri with label is converted to link' => [
+ 'example url: [url=geo:37.786971,-122.399677;u=35(Wikimedia+Foundation)]Wikimedia Foundation[/url]',
+ 'example url: <a href="geo:37.786971,-122.399677;u=35(Wikimedia+Foundation)" target="_blank" rel="nofollow noopener">Wikimedia Foundation</a>'
+ ],
+ 'naked geo uri is converted to link' => [
+ 'example url: geo:37.786971,-122.399677;u=35',
+ 'example url: <a href="geo:37.786971,-122.399677;u=35" target="_blank" rel="nofollow noopener">geo:37.786971,-122.399677;u=35</a>'
+ ],
+ 'naked geo uri with label is converted to link' => [
+ 'example url: geo:37.78918,-122.40335(Wikimedia+Foundation)',
+ 'example url: <a href="geo:37.78918,-122.40335(Wikimedia+Foundation)" target="_blank" rel="nofollow noopener">📍Wikimedia Foundation</a>'
+ ],
];
}
@@ -189,7 +222,7 @@ class BBCodeTest extends UnitTestCase {
'[rpost=a title]This is the body[/rpost]',
true,
'en',
- '<a href="https://example.com:666/rpost?f=&title=a+title&body=This+is+the+body" target="_blank" rel="nofollow noopener">https://example.com:666/rpost?f=&title=a+title&body=This+is+the+body</a>',
+ '<a href="https://example.com:666/rpost?f=&title=a+title&body=This+is+the+body" target="_blank" rel="nofollow noopener">https://example.com:666/rpost?f=&title=a+title&body=This+is+the+body</a>',
],
'unauthenticated observer rpost' => [
'[rpost=a title]This is the body[/rpost]',
@@ -223,6 +256,10 @@ class BBCodeTest extends UnitTestCase {
"<pre><code>some\n indented\ncode</code></pre>",
"[code]some\n indented\ncode[/code]"
],
+ 'code block with URL' => [
+ '<pre><code>\nproxy_pass http://example.com\n</code></pre>',
+ '[code]\nproxy_pass http://example.com\n[/code]'
+ ],
'paragraph with a mention and some text' => [
'<p><span class="h-card" translate="no"><a href="https://example.org/@profile" class="u-url mention">@<span>profile</span></a></span> some content</p>',
'[url=https://example.org/@profile]@profile[/url] some content'
@@ -266,6 +303,10 @@ class BBCodeTest extends UnitTestCase {
'del tag' => [
'some <del>strike through</del> text',
'some [s]strike through[/s] text'
+ ],
+ 'table' => [
+ '<table><tr><td>row1, col1</td><td>row1, col2</td></tr><tr><td>row2, col1</td><td>row2, col2</td></tr></table>',
+ '[table][tr][td]row1, col1[/td][td]row1, col2[/td][/tr][tr][td]row2, col1[/td][td]row2, col2[/td][/tr][/table]'
]
];
}
diff --git a/tests/unit/includes/DatetimeTest.php b/tests/unit/includes/DatetimeTest.php
new file mode 100644
index 000000000..f8c480449
--- /dev/null
+++ b/tests/unit/includes/DatetimeTest.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * tests function from include/datetime.php
+ *
+ * @package test.util
+ */
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+
+class DatetimeTest extends UnitTestCase {
+
+ // Test when the timestamp is in the past
+ public function test_relative_time_past() {
+ $now = new DateTime('2024-12-07 00:00:00');
+ $timestamp = datetime_convert(date_default_timezone_get(), 'UTC', '2023-12-05 10:30:00');
+ $result = relative_time($timestamp, $now);
+ $this->assertEquals('1 year ago', $result);
+ }
+
+ // Test when the timestamp is in the future
+ public function test_relative_time_future() {
+ $now = new DateTime('2024-12-07 00:00:00');
+ $timestamp = datetime_convert(date_default_timezone_get(), 'UTC', '2024-12-09 12:00:00');
+ $result = relative_time($timestamp, $now);
+ $this->assertEquals('in 2 days', $result);
+ }
+
+ // Test for "now" case (timestamp exactly equal to current time)
+ public function test_relative_time_now() {
+ $now = new DateTime('2024-12-07 00:00:00');
+ $timestamp = datetime_convert(date_default_timezone_get(), 'UTC', '2024-12-07 00:00:00');
+ $result = relative_time($timestamp, $now);
+ $this->assertEquals('now', $result);
+ }
+
+ // Test for future time with smaller units (e.g., minutes)
+ public function test_relative_time_future_minutes() {
+ $now = new DateTime('2024-12-07 10:30:00');
+ $timestamp = datetime_convert(date_default_timezone_get(), 'UTC', '2024-12-07 10:35:00');
+ $result = relative_time($timestamp, $now);
+ $this->assertEquals('in 5 minutes', $result);
+ }
+
+ // Test for past time with smaller units (e.g., seconds)
+ public function test_relative_time_past_seconds() {
+ $now = new DateTime('2024-12-07 10:30:00');
+ $timestamp = datetime_convert(date_default_timezone_get(), 'UTC', '2024-12-07 10:29:58');
+ $result = relative_time($timestamp, $now);
+ $this->assertEquals('2 seconds ago', $result);
+ }
+}
+
+
diff --git a/tests/unit/includes/ItemsTest.php b/tests/unit/includes/ItemsTest.php
new file mode 100644
index 000000000..1c2fb6725
--- /dev/null
+++ b/tests/unit/includes/ItemsTest.php
@@ -0,0 +1,132 @@
+<?php
+/**
+ * tests function from include/items.php
+ *
+ * @package test.util
+ */
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+
+class ItemsTest extends UnitTestCase {
+ /**
+ * Data provider for item_forwardable function.
+ *
+ * @return array
+ */
+ public static function itemForwardableDataProvider()
+ {
+ return [
+ // Test case: item is unpublished
+ [
+ [
+ 'item_unpublished' => 1,
+ 'item_delayed' => 0,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => '']
+ ],
+ false // Expected result
+ ],
+ // Test case: item is delayed
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 1,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => '']
+ ],
+ false
+ ],
+ // Test case: item is blocked
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 0,
+ 'item_blocked' => 1,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => '']
+ ],
+ false
+ ],
+ // Test case: verb is 'Follow' (forbidden verb)
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 0,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Follow',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => '']
+ ],
+ false
+ ],
+ // Test case: postopts contains 'nodeliver'
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 0,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => 'nodeliver',
+ 'author' => ['xchan_network' => '']
+ ],
+ false
+ ],
+ // Test case: actor's network is 'rss' (restricted network)
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 0,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => 'rss']
+ ],
+ false
+ ],
+ // Test case: no conditions met (should forward)
+ [
+ [
+ 'item_unpublished' => 0,
+ 'item_delayed' => 0,
+ 'item_blocked' => 0,
+ 'item_hidden' => 0,
+ 'item_restrict' => 0,
+ 'verb' => 'Create',
+ 'postopts' => '',
+ 'author' => ['xchan_network' => 'other']
+ ],
+ true
+ ]
+ ];
+ }
+
+ /**
+ * Test item_forwardable with various data.
+ *
+ * @dataProvider itemForwardableDataProvider
+ */
+ public function testItemForwardable($item, $expected)
+ {
+ $this->assertSame($expected, item_forwardable($item));
+ }
+
+}
+
+
diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php
index 8f62e71e2..90249c5c8 100644
--- a/tests/unit/includes/LanguageTest.php
+++ b/tests/unit/includes/LanguageTest.php
@@ -86,16 +86,16 @@ class LanguageTest extends UnitTestCase {
'en-gb',
'British English',
[
- 'de' => 'Englisch (Vereinigtes Königreich)',
- 'nb' => 'engelsk (Storbritannia)'
+ 'de' => 'British English', // should be Englisch (Vereinigtes Königreich), seems to be a bug upstream
+ 'nb' => 'British English' // should be engelsk (Storbritannia), seems to be a bug upstream
]
],
'en-au' => [
'en-au',
'Australian English',
[
- 'de' => 'Englisch (Australien)',
- 'nb' => 'engelsk (Australia)'
+ 'de' => 'Australian English', // should be Englisch (Australien), seems to be a bug upstream
+ 'nb' => 'Australian English' // should be engelsk (Australia), , seems to be a bug upstream
]
],
'nb' => [
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
index 310130bf1..55dbb4445 100644
--- a/tests/unit/includes/MarkdownTest.php
+++ b/tests/unit/includes/MarkdownTest.php
@@ -36,7 +36,7 @@ class MarkdownTest extends UnitTestCase {
* @dataProvider markdown_to_bbcode_provider
*/
public function test_markdown_to_bbcode(string $expected, string $src): void {
- $this->assertEquals($expected, markdown_to_bb($src));
+ $this->assertEquals($expected, markdown_to_bb($src, true, ['preserve_lf' => true]));
}
public static function markdown_to_bbcode_provider(): array {
@@ -54,11 +54,14 @@ class MarkdownTest extends UnitTestCase {
'This is a test of **bold text**, *italic text* and ***bold and italic text***'
],
'multiline text' => [
- 'This text is text wrapped over multiple lines.',
+ // This is not as expected in markdown, but may be needed
+ // for compatibility with bbcode behaviour.
+ "This text is\ntext wrapped\nover multiple\nlines.",
"This text is\ntext wrapped\nover multiple\nlines."
],
'text with hard linebreak' => [
- "Line one\nLine two",
+ // An extra line break is inserted here...
+ "Line one\n\nLine two",
"Line one \nLine two"
],
'paragraphs' => [
@@ -78,21 +81,39 @@ class MarkdownTest extends UnitTestCase {
'`some code`'
],
'inline code with wrapped text' => [
- '[code]some code unwrapped[/code]',
+ // Not sure if the newline should be preseved here?
+ "[code]some code\nunwrapped[/code]",
"`some code\n unwrapped`"
],
'code block no language' => [
- "[code]some code\nover multiple lines[/code]",
+ "[code]some code\nover multiple lines\n[/code]",
"```\nsome code\nover multiple lines\n```"
],
'code block no language indented' => [
- "[code]some code\n over multiple lines\n with indentation[/code]",
+ // For some reason one space char is eaten on indented lines.
+ "[code]some code\n over multiple lines\n with indentation\n[/code]",
"```\nsome code\n over multiple lines\n with indentation\n```"
],
'code block with language' => [
- "[code=php]&lt;?php\necho phpinfo();[/code]",
+ "[code=php]&lt;?php\necho phpinfo();\n[/code]",
"```php\n<?php\necho phpinfo();\n```"
],
+ 'code block with URL' => [
+ "[code]an example url https://example.com\n[/code]",
+ "```\nan example url https://example.com\n```"
+ ],
+ 'bbcode code block with URL' => [
+ "[code]\nproxy_pass http://example.com;\n[/code]",
+ "[code]\nproxy_pass http://example.com;\n[/code]"
+ ],
+ 'naked url followed by newline' => [
+ "https://example.com\nhave a great day.",
+ "https://example.com\nhave a great day.",
+ ],
+ 'inline naked url' => [
+ 'This is a link https://example.com/some/path more info.',
+ 'This is a link https://example.com/some/path more info.',
+ ],
];
}
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php
index a41075f25..0d99fc9c3 100644
--- a/tests/unit/includes/NetworkTest.php
+++ b/tests/unit/includes/NetworkTest.php
@@ -60,7 +60,63 @@ class NetworkTest extends Zotlabs\Tests\Unit\UnitTestCase {
['some.email@example.cancerresearch', true],
// And internationalized TLD's
- ['some.email@example.شبكة', true]
+ ['some.email@example.شبكة', true],
+
+ // Allow plus/minus addressing
+ ['address+tag@example.com', true],
+ ['address-tag@example.com', true],
+ ];
+ }
+
+ /**
+ * Test the unparse_url function.
+ *
+ */
+ public function test_unparse_url_full()
+ {
+ $parsed_url = [
+ 'scheme' => 'https',
+ 'host' => 'www.example.com',
+ 'port' => '8080',
+ 'user' => 'username',
+ 'pass' => 'password',
+ 'path' => '/path',
+ 'query' => 'param=value',
+ 'fragment' => 'section'
+ ];
+
+ $expected = 'https://username:password@www.example.com:8080/path?param=value#section';
+ $this->assertEquals($expected, unparse_url($parsed_url));
+ }
+
+ public function test_unparse_url_partial()
+ {
+ $parsed_url = [
+ 'scheme' => 'http',
+ 'host' => 'example.com',
+ 'path' => '/index.php'
];
+
+ $expected = 'http://example.com/index.php';
+ $this->assertEquals($expected, unparse_url($parsed_url));
+ }
+
+ public function test_unparse_url_custom()
+ {
+ $parsed_url = [
+ 'scheme' => 'https',
+ 'host' => 'www.example.com',
+ 'port' => '443',
+ 'path' => '/api'
+ ];
+
+ $parts = ['scheme', 'host'];
+ $expected = 'https://www.example.com';
+ $this->assertEquals($expected, unparse_url($parsed_url, $parts));
+ }
+
+ public function test_unparse_url_empty()
+ {
+ $this->assertEquals('', unparse_url([]));
}
}
diff --git a/tests/unit/includes/PhotodriverTest.php b/tests/unit/includes/PhotodriverTest.php
index 34dc058b7..db9883589 100644
--- a/tests/unit/includes/PhotodriverTest.php
+++ b/tests/unit/includes/PhotodriverTest.php
@@ -20,4 +20,62 @@ class PhotodriverTest extends UnitTestCase {
$photo = \photo_factory(file_get_contents('images/hz-16.png'), 'image/png');
$this->assertInstanceOf('Zotlabs\Photo\PhotoGd', $photo);
}
+
+ // Helper to create a temporary image file
+ private function createTempImage($type = 'jpeg'): string
+ {
+ $tmp = tempnam(sys_get_temp_dir(), 'img');
+ switch ($type) {
+ case 'png':
+ $im = imagecreatetruecolor(10, 10);
+ imagepng($im, $tmp);
+ imagedestroy($im);
+ break;
+ case 'jpeg':
+ default:
+ $im = imagecreatetruecolor(10, 10);
+ imagejpeg($im, $tmp);
+ imagedestroy($im);
+ break;
+ }
+ return $tmp;
+ }
+
+ public function testGuessImageTypeFromRawData()
+ {
+ $filename = 'irrelevant';
+ $data = [
+ 'body' => file_get_contents($this->createTempImage('jpeg'))
+ ];
+ $result = guess_image_type($filename, $data);
+ $this->assertEquals('image/jpeg', $result);
+ }
+
+ public function testGuessImageTypeFromLocalFile()
+ {
+ $file = $this->createTempImage('png');
+ $result = guess_image_type($file);
+ $this->assertEquals('image/png', $result);
+ unlink($file);
+ }
+
+ public function testGuessImageTypeFromHeaders()
+ {
+ $filename = 'irrelevant';
+ $data = [
+ 'header' => "Content-Type: image/jpeg\nOther: value"
+ ];
+ $result = guess_image_type($filename, $data);
+ $this->assertEquals('image/jpeg', $result);
+ }
+
+ public function testGuessImageTypeUnknownTypeReturnsNull()
+ {
+ $filename = 'not_an_image.txt';
+ $data = [
+ 'body' => 'not an image'
+ ];
+ $result = guess_image_type($filename, $data);
+ $this->assertNull($result);
+ }
}
diff --git a/tests/unit/includes/dba/DbaPdoTest.php b/tests/unit/includes/dba/DbaPdoTest.php
new file mode 100644
index 000000000..8a1a2b197
--- /dev/null
+++ b/tests/unit/includes/dba/DbaPdoTest.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * Tests for `includes/dba_pdo.php`.
+ *
+ * SPDX-FileCopyrightText: 2024 Hubzilla Community
+ * SPDX-FileContributor: Harald Eilertsen
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use DBA;
+use PDO;
+use PDOStatement;
+use PHPUnit\Framework\Attributes\DataProvider;
+use Zotlabs\Tests\Unit\UnitTestCase;
+
+class DbaPdoTest extends UnitTestCase
+{
+ public function testInsertingRowWithRturningClauseReturnsInsertedRow(): void
+ {
+ // MySQL does not support the `returning` clause, so we skip the test
+ // for that DB backend.
+ $this->skipIfMySQL();
+
+ // Let's manually insert a row in the config table.
+ // This is just because it's a conventient table to test
+ // against
+ $res = q(<<<SQL
+ INSERT INTO config (cat, k, v)
+ VALUES ('test', 'a key', 'A value')
+ RETURNING *
+ SQL);
+
+ $this->assertIsArray($res);
+ $this->assertIsArray($res[0]);
+ $this->assertTrue($res[0]['id'] > 0);
+ $this->assertEquals('test', $res[0]['cat']);
+ $this->assertEquals('a key', $res[0]['k']);
+ $this->assertEquals('A value', $res[0]['v']);
+ }
+
+ #[DataProvider('insertRowProvider')]
+ public function testInsertRow(string $table, array $data, string $id): void
+ {
+ $res = DBA::$dba->insert($table, $data, $id);
+
+ $this->assertIsArray($res);
+
+ // Make sure the result contains the expected id
+ $this->assertArrayHasKey($id, $res);
+
+ foreach ($data as $key => $value) {
+ $this->assertEquals($value, $res[$key]);
+ }
+ }
+
+ #[DataProvider('insertRowProvider')]
+ public function testInsertShouldReturnFalseIfInsertFails(
+ string $table,
+ array $data,
+ string $id
+ ): void
+ {
+ $res1 = DBA::$dba->insert($table, $data, $id);
+ $this->assertIsArray($res1);
+
+ // Inserting the same row again should fail.
+ $res2 = DBA::$dba->insert($table, $data, $id);
+ $this->assertFalse($res2);
+ }
+
+ /**
+ * Dataprovider for testInertRow.
+ *
+ * @return array An array of [ $table, $data, $id ] elements.
+ */
+ public static function insertRowProvider(): array
+ {
+ return [
+ 'table with numeric primary id' => [
+ 'config',
+ [ 'cat' => 'test', 'k' => 'a key', 'v' => 'A value' ],
+ 'id',
+ ],
+ 'table with text primary id' => [
+ 'cache',
+ [ 'k' => 'some key', 'v' => 'cached value', 'updated' => date('Y-m-d H:i:s')],
+ 'k',
+ ],
+ ];
+ }
+
+ public function testUpdateRow(): void
+ {
+ // Let's fetch a row from the config table
+ $res = q("SELECT * FROM config WHERE cat = 'system' AND k = 'baseurl'");
+
+ $this->assertIsArray($res);
+ $this->assertIsArray($res[0]);
+
+ $row = $res[0];
+
+ // Update the baseurl
+ $updated = DBA::$dba->update(
+ 'config',
+ [ 'v' => 'https://some.other_site.test/' ],
+ 'id',
+ $row['id']
+ );
+
+ $this->assertTrue($updated);
+
+ // Verify that the record was updated
+ $updated_res = q("SELECT * FROM config WHERE cat = 'system' AND k = 'baseurl'");
+ $this->assertIsArray($updated_res);
+
+ $updated_row = $updated_res[0];
+
+ $this->assertIsArray($updated_row);
+ $this->assertEquals($row['id'], $updated_row['id']);
+ $this->assertEquals('system', $updated_row['cat']);
+ $this->assertEquals('baseurl', $updated_row['k']);
+ $this->assertEquals('https://some.other_site.test/', $updated_row['v']);
+ }
+
+ /**
+ * Mark the test as skipped if the current db is MySQL.
+ */
+ private function skipIfMySQL(): void {
+ $driver = DBA::$dba->db->getAttribute(PDO::ATTR_DRIVER_NAME);
+ $version = DBA::$dba->db->getAttribute(PDO::ATTR_SERVER_VERSION);
+
+ if ($driver === 'mysql' && stripos($version, 'mariadb') === false) {
+ $this->markTestSkipped("RETURNING clause not supported for {$driver}");
+ }
+
+ }
+}
diff --git a/tests/unit/includes/dba/_files/account.yml b/tests/unit/includes/dba/_files/account.yml
index 88e59056e..9c3d00ec8 100644
--- a/tests/unit/includes/dba/_files/account.yml
+++ b/tests/unit/includes/dba/_files/account.yml
@@ -3,9 +3,26 @@ account:
account_id: 42
account_email: "hubzilla@example.com"
account_language: "no"
+ account_level: 5
account_flags: 0
-
account_id: 43
account_email: "hubzilla@example.org"
account_language: "de"
+ account_level: 5
account_flags: 1
+ -
+ account_id: 44
+ account_email: "blocked@example.org"
+ account_level: 5
+ account_flags: 2
+ -
+ account_id: 45
+ account_email: "pending@example.org"
+ account_level: 5
+ account_flags: 0x10
+ -
+ account_id: 46
+ account_email: "unverified@example.org"
+ account_level: 5
+ account_flags: 0x11
diff --git a/tests/unit/includes/dba/_files/register.yml b/tests/unit/includes/dba/_files/register.yml
new file mode 100644
index 000000000..2ef1a5365
--- /dev/null
+++ b/tests/unit/includes/dba/_files/register.yml
@@ -0,0 +1,20 @@
+---
+register:
+ -
+ reg_vital: 1
+ reg_flags: 0x10
+ reg_did2: 'verified@example.com'
+ reg_email: 'verified@example.com'
+ reg_hash: '123'
+ reg_uid: 45
+ reg_pass: 'verify'
+ reg_stuff: ''
+ -
+ reg_vital: 1
+ reg_flags: 0x11
+ reg_did2: 'unverified@example.com'
+ reg_email: 'unverified@example.com'
+ reg_hash: '666'
+ reg_uid: 46
+ reg_pass: 'verify'
+ reg_stuff: ''