aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Access/PermissionLimitsTest.php7
-rw-r--r--tests/unit/Access/PermissionRolesTest.php26
-rw-r--r--tests/unit/Access/PermissionsTest.php14
-rw-r--r--tests/unit/AntiXSSTest.php20
-rw-r--r--tests/unit/Photo/PhotoGdTest.php5
-rw-r--r--tests/unit/includes/FeedutilsTest.php2
-rw-r--r--tests/unit/includes/LanguageTest.php7
-rw-r--r--tests/unit/includes/MarkdownTest.php4
-rw-r--r--tests/unit/includes/NetworkTest.php33
9 files changed, 77 insertions, 41 deletions
diff --git a/tests/unit/Access/PermissionLimitsTest.php b/tests/unit/Access/PermissionLimitsTest.php
index 57ad42a19..0a90d11df 100644
--- a/tests/unit/Access/PermissionLimitsTest.php
+++ b/tests/unit/Access/PermissionLimitsTest.php
@@ -45,8 +45,8 @@ class PermissionLimitsTest extends UnitTestCase {
* @uses ::call_hooks
*/
public function testStd_Limits() {
- // There are 18 default perms
- $permsCount = 18;
+ // There are 17 default perms
+ $permsCount = 17;
// Create a stub for global function t() with expectation
$t = $this->getFunctionMock('Zotlabs\Access', 't');
@@ -69,10 +69,9 @@ class PermissionLimitsTest extends UnitTestCase {
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_comments']);
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_mail']);
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_like']);
- $this->assertEquals(PERMS_SPECIFIC, $stdlimits['tag_deliver']);
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['chat']);
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['republish']);
$this->assertEquals(PERMS_SPECIFIC, $stdlimits['delegate']);
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/Access/PermissionRolesTest.php b/tests/unit/Access/PermissionRolesTest.php
index dd55eb6e2..3d3cbbae5 100644
--- a/tests/unit/Access/PermissionRolesTest.php
+++ b/tests/unit/Access/PermissionRolesTest.php
@@ -40,7 +40,7 @@ class PermissionRolesTest extends UnitTestCase {
use PHPMock;
public function testVersion() {
- $expectedVersion = 2;
+ $expectedVersion = 3;
$this->assertEquals($expectedVersion, PermissionRoles::version());
@@ -58,23 +58,12 @@ class PermissionRolesTest extends UnitTestCase {
}
);
- $roles = PermissionRoles::roles();
+ $roles = PermissionRoles::channel_roles();
$r = new PermissionRoles();
- $this->assertEquals($roles, $r->roles());
+ $this->assertEquals($roles, $r->channel_roles());
- $socialNetworking = [
- 'social_federation' => 'Social - Federation',
- 'social' => 'Social - Mostly Public',
- 'social_restricted' => 'Social - Restricted',
- 'social_private' => 'Social - Private'
- ];
+ $this->assertCount(4, $roles, 'There should be 4 channel roles.');
- Assert::assertArraySubset(['Social Networking' => $socialNetworking], $roles);
- $this->assertEquals($socialNetworking, $roles['Social Networking']);
-
- $this->assertCount(5, $roles, 'There should be 5 permission groups.');
-
- $this->assertCount(1, $roles['Other'], "In the 'Other' group should be just one permission role");
}
@@ -88,12 +77,9 @@ class PermissionRolesTest extends UnitTestCase {
$t = $this->getFunctionMock('Zotlabs\Access', 't');
$t = $this->getFunctionMock('Zotlabs\Access', 'get_config');
- $rp_social = PermissionRoles::role_perms('social');
- $this->assertEquals('social', $rp_social['role']);
-
+ $rp_social = PermissionRoles::role_perms('personal');
+ $this->assertEquals('personal', $rp_social['role']);
- $rp_custom = PermissionRoles::role_perms('custom');
- $this->assertEquals(['role' => 'custom'], $rp_custom);
$rp_nonexistent = PermissionRoles::role_perms('nonexistent');
$this->assertEquals(['role' => 'nonexistent'], $rp_nonexistent);
diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php
index 40724fff8..3ab567ad0 100644
--- a/tests/unit/Access/PermissionsTest.php
+++ b/tests/unit/Access/PermissionsTest.php
@@ -37,7 +37,7 @@ class PermissionsTest extends UnitTestCase {
use PHPMock;
public function testVersion() {
- $expectedVersion = 2;
+ $expectedVersion = 3;
// static call
$this->assertEquals($expectedVersion, Permissions::version());
@@ -60,8 +60,8 @@ class PermissionsTest extends UnitTestCase {
* @uses ::call_hooks
*/
public function testPerms() {
- // There are 18 default perms
- $permsCount = 18;
+ // There are 17 default perms
+ $permsCount = 17;
// Create a stub for global function t() with expectation
$t = $this->getFunctionMock('Zotlabs\Access', 't');
@@ -94,8 +94,8 @@ class PermissionsTest extends UnitTestCase {
* @uses ::call_hooks
*/
public function testPermsFilter() {
- // There are 18 default perms
- $permsCount = 18;
+ // There are 17 default perms
+ $permsCount = 17;
// Create a stub for global function t() with expectation
$t = $this->getFunctionMock('Zotlabs\Access', 't');
@@ -154,7 +154,6 @@ class PermissionsTest extends UnitTestCase {
'post_comments' => 0,
'post_mail' => 0,
'post_like' => 0,
- 'tag_deliver' => 0,
'chat' => 0,
'republish' => 0,
'delegate' => 0
@@ -177,7 +176,6 @@ class PermissionsTest extends UnitTestCase {
'post_comments' => 0,
'post_mail' => 0,
'post_like' => 0,
- 'tag_deliver' => 0,
'chat' => 0,
'republish' => 0,
'delegate' => 0
@@ -200,7 +198,6 @@ class PermissionsTest extends UnitTestCase {
'post_comments' => 0,
'post_mail' => 0,
'post_like' => 0,
- 'tag_deliver' => 0,
'chat' => 0,
'republish' => 0,
'delegate' => 0
@@ -234,7 +231,6 @@ class PermissionsTest extends UnitTestCase {
'post_comments' => 0,
'post_mail' => 0,
'post_like' => 0,
- 'tag_deliver' => 0,
'chat' => 0,
'republish' => 0,
'delegate' => 0
diff --git a/tests/unit/AntiXSSTest.php b/tests/unit/AntiXSSTest.php
index b45042a1e..09642726f 100644
--- a/tests/unit/AntiXSSTest.php
+++ b/tests/unit/AntiXSSTest.php
@@ -24,6 +24,26 @@ class AntiXSSTest extends TestCase {
$this->assertEquals("<submit type="button" onclick="alert('failed!');" />", $escapedString);
}
+ /**
+ * @dataProvider urlTestProvider
+ */
+ public function testEscapeURL($url, $expected) : void {
+ $this->assertEquals($expected, escape_url($url));
+ }
+
+ public function urlTestProvider() : array {
+ return [
+ [
+ "https://example.com/settings/calendar/?f=&rpath=https://example.com/cdav/calendar'><script>alert('boom')</script>",
+ "https://example.com/settings/calendar/?f=&amp;rpath=https://example.com/cdav/calendar&apos;&gt;&lt;script&gt;alert(&apos;boom&apos;)&lt;/script&gt;"
+ ],
+ [
+ "settings/calendar/?f=&rpath=https://example.com'+accesskey=x+onclick=alert(/boom/);a='",
+ "settings/calendar/?f=&amp;rpath=https://example.com&apos;+accesskey=x+onclick=alert(/boom/);a=&apos;"
+ ],
+ ];
+ }
+
/**
*xmlify and unxmlify
*/
diff --git a/tests/unit/Photo/PhotoGdTest.php b/tests/unit/Photo/PhotoGdTest.php
index ae7382c43..1324043c4 100644
--- a/tests/unit/Photo/PhotoGdTest.php
+++ b/tests/unit/Photo/PhotoGdTest.php
@@ -71,11 +71,14 @@ class PhotoGdTest extends UnitTestCase {
/**
* Tests PhotoGd->getImage()
*/
+ /* TODO: fix for PHP8
public function testGetimageReturnsAResource() {
$res = $this->photoGd->getImage();
$this->assertIsResource($res);
$this->assertEquals('gd', get_resource_type($res));
}
+ */
+
public function testGetimageReturnsFalseOnFailure() {
$this->photoGd = new PhotoGd('');
$this->assertFalse($this->photoGd->getImage());
@@ -94,11 +97,13 @@ class PhotoGdTest extends UnitTestCase {
/**
* Tests PhotoGd->rotate()
*/
+ /* TODO: fix for PHP8
public function testRotate360DegreesCreatesANewImage() {
$data = $this->photoGd->getImage();
$this->photoGd->rotate(360);
$this->assertNotEquals($data, $this->photoGd->getImage());
}
+ */
/**
* Tests PhotoGd->flip()
diff --git a/tests/unit/includes/FeedutilsTest.php b/tests/unit/includes/FeedutilsTest.php
index e9826a73d..bda0bf425 100644
--- a/tests/unit/includes/FeedutilsTest.php
+++ b/tests/unit/includes/FeedutilsTest.php
@@ -4,6 +4,8 @@ namespace Zotlabs\Tests\Unit\includes;
use Zotlabs\Tests\Unit\UnitTestCase;
+require_once('include/feedutils.php');
+
/**
* @brief Unit Test case for include/feedutils.php file.
*/
diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php
index 0ca9eacd0..9525c783d 100644
--- a/tests/unit/includes/LanguageTest.php
+++ b/tests/unit/includes/LanguageTest.php
@@ -63,11 +63,6 @@ class LanguageTest extends UnitTestCase {
public function languageExamplesProvider() {
return [
- 'empty text' => [
- '',
- '',
- null
- ],
'English' => [
'English is a West Germanic language that was first spoken in early medieval England and is now a global lingua franca.[4][5] Named after the Angles, one of the Germanic tribes that migrated to England, it ultimately derives its name from the Anglia (Angeln) peninsula in the Baltic Sea. It is closely related to the Frisian languages, but its vocabulary has been significantly influenced by other Germanic languages, particularly Norse (a North Germanic language), as well as by Latin and Romance languages, especially French.',
'en',
@@ -155,7 +150,7 @@ class LanguageTest extends UnitTestCase {
'nb',
'Norwegian Bokmål',
[
- 'de' => 'Norwegisch Bokmål',
+ 'de' => 'Norwegisch (Bokmål)',
'nb' => 'norsk bokmål'
]
]
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
index 2a92a58d2..98fe40a49 100644
--- a/tests/unit/includes/MarkdownTest.php
+++ b/tests/unit/includes/MarkdownTest.php
@@ -87,8 +87,8 @@ class MarkdownTest extends UnitTestCase {
"1. Item 1\n2. Item 2\n3. Item **3**"
],
'nested lists' => [
- '<ul><li>Item 1<ol><li>Item 1a</li><li>Item <b>1b</b></ol></li><li>Item 2</li></ul>',
- "- Item 1\n 1. Item 1a\n 2. Item **1b**\n- Item 2"
+ '<ul><li>Item A</li><li>Item B<ul><li>Nested A</li><li>Nested B</li></ul></li><li>Item C</li></ul>',
+ "- Item A\n- Item B\n - Nested A\n - Nested B\n- Item C"
],
'img' => [
'<img src="/path/to/img.png" alt="alt text" title="title text">',
diff --git a/tests/unit/includes/NetworkTest.php b/tests/unit/includes/NetworkTest.php
new file mode 100644
index 000000000..0b9b42e00
--- /dev/null
+++ b/tests/unit/includes/NetworkTest.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * tests function from include/network.php
+ *
+ * @package test.util
+ */
+
+use PHPUnit\Framework\TestCase;
+
+require_once('include/network.php');
+
+class NetworkTest extends TestCase {
+
+ public function setup() : void {
+ \App::set_baseurl("https://mytest.org");
+ }
+
+ /**
+ * @dataProvider localUrlTestProvider
+ */
+ public function testIsLocalURL($url, $expected) {
+ $this->assertEquals($expected, is_local_url($url));
+ }
+
+ public function localUrlTestProvider() : array {
+ return [
+ [ '/some/path', true ],
+ [ 'https://mytest.org/some/path', true ],
+ [ 'https://other.site/some/path', false ],
+ ];
+ }
+}
+