aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Lib/ActivityTest.php7
-rw-r--r--tests/unit/Lib/JcsEddsa2022Test.php8
-rw-r--r--tests/unit/includes/AccountTest.php21
-rw-r--r--tests/unit/includes/BBCodeTest.php24
4 files changed, 55 insertions, 5 deletions
diff --git a/tests/unit/Lib/ActivityTest.php b/tests/unit/Lib/ActivityTest.php
index 1857487c8..46f53ecd9 100644
--- a/tests/unit/Lib/ActivityTest.php
+++ b/tests/unit/Lib/ActivityTest.php
@@ -274,4 +274,11 @@ class ActivityTest extends UnitTestCase {
];
}
+ public function testBuildPacketWithEmptyChannel(): void {
+ $data = [ 'aKey' => 'aValue' ];
+ $packet = json_decode(Activity::build_packet($data, []), true);
+
+ $this->assertArrayHasKey('aKey', $packet);
+ $this->assertEquals('aValue', $packet['aKey']);
+ }
}
diff --git a/tests/unit/Lib/JcsEddsa2022Test.php b/tests/unit/Lib/JcsEddsa2022Test.php
index d18ad01ce..7cdc655f8 100644
--- a/tests/unit/Lib/JcsEddsa2022Test.php
+++ b/tests/unit/Lib/JcsEddsa2022Test.php
@@ -3,6 +3,7 @@
namespace Zotlabs\Tests\Unit\Lib;
use Zotlabs\Lib\JcsEddsa2022;
+use Zotlabs\Lib\JcsEddsa2022SignException;
use Zotlabs\Tests\Unit\UnitTestCase;
class JcsEddsa2022Test extends UnitTestCase {
@@ -171,4 +172,11 @@ class JcsEddsa2022Test extends UnitTestCase {
$this->assertTrue($verified, 'Verify encode and decode eddsa-jcs-2022');
}
+
+ public function testSignWithInvalidChannelShouldBeRejected(): void {
+ $this->expectException(JcsEddsa2022SignException::class);
+
+ $alg = new JcsEddsa2022();
+ $res = $alg->sign([], []);
+ }
}
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 50475efea..982ef4eb9 100644
--- a/tests/unit/includes/BBCodeTest.php
+++ b/tests/unit/includes/BBCodeTest.php
@@ -142,20 +142,36 @@ class BBCodeTest extends UnitTestCase {
],
'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>'
+ '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.',
+ '<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.',
+ '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>'
+ ],
];
}
@@ -206,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]',