aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/infection.json.dist15
-rw-r--r--tests/phpunit-pgsql.xml35
-rw-r--r--tests/phpunit.xml.dist38
-rwxr-xr-xtests/travis/gen_apidocs.sh69
-rwxr-xr-xtests/travis/prepare.sh35
-rwxr-xr-xtests/travis/prepare_mysql.sh53
-rwxr-xr-xtests/travis/prepare_pgsql.sh44
-rw-r--r--tests/unit/Access/AccessListTest.php191
-rw-r--r--tests/unit/Access/PermissionLimitsTest.php78
-rw-r--r--tests/unit/Access/PermissionRolesTest.php100
-rw-r--r--tests/unit/Access/PermissionsTest.php322
-rw-r--r--tests/unit/AutonameTest.php8
-rw-r--r--tests/unit/Lib/PermissionDescriptionTest.php131
-rw-r--r--tests/unit/TextTest.php33
-rw-r--r--tests/unit/includes/FeedutilsTest.php89
-rw-r--r--tests/unit/includes/LanguageTest.php164
-rw-r--r--tests/unit/includes/MarkdownTest.php149
-rw-r--r--tests/unit/includes/TextTest.php120
-rw-r--r--tests/unit/template_test.php6
19 files changed, 1565 insertions, 115 deletions
diff --git a/tests/infection.json.dist b/tests/infection.json.dist
new file mode 100644
index 000000000..36b251982
--- /dev/null
+++ b/tests/infection.json.dist
@@ -0,0 +1,15 @@
+{
+ "timeout": 13,
+ "source": {
+ "directories": [
+ "include",
+ "Zotlabs"
+ ]
+ },
+ "logs": {
+ "text": "tests/results/infection-log.txt"
+ },
+ "phpUnit": {
+ "configDir": "tests"
+ }
+}
diff --git a/tests/phpunit-pgsql.xml b/tests/phpunit-pgsql.xml
new file mode 100644
index 000000000..ec4a6fc2d
--- /dev/null
+++ b/tests/phpunit-pgsql.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
+ bootstrap="../boot.php"
+ forceCoversAnnotation="false"
+ beStrictAboutCoversAnnotation="true"
+ beStrictAboutOutputDuringTests="true"
+ beStrictAboutTodoAnnotatedTests="true"
+ verbose="true">
+ <testsuite name="Hubzilla default Test Suite">
+ <directory suffix="Test.php">./unit/</directory>
+ </testsuite>
+ <testsuite name="API Test Suite">
+ <directory suffix="Test.php" prefix="API">./unit/</directory>
+ </testsuite>
+ <groups>
+ <exclude>
+ <group>mysql</group>
+ </exclude>
+ </groups>
+ <!--cover reporting-->
+ <filter>
+ <whitelist processUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../Zotlabs/</directory>
+ <directory suffix=".php">../include/</directory>
+ </whitelist>
+ </filter>
+ <logging>
+ <log type="junit" target="./results/junit.xml" logIncompleteSkipped="false"/>
+ <log type="coverage-clover" target="./results/coverage-clover.xml"/>
+ <log type="coverage-html" target="./results/coverage-report/" lowUpperBound="35"
+ highLowerBound="70"/>
+ <log type="testdox-text" target="./results/testdox.txt"/>
+ </logging>
+</phpunit>
diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist
new file mode 100644
index 000000000..a22317b08
--- /dev/null
+++ b/tests/phpunit.xml.dist
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
+ bootstrap="../boot.php"
+ forceCoversAnnotation="false"
+ beStrictAboutCoversAnnotation="true"
+ beStrictAboutOutputDuringTests="true"
+ beStrictAboutTodoAnnotatedTests="true"
+ verbose="true">
+ <testsuite name="Hubzilla default Test Suite">
+ <directory suffix="Test.php">./unit/</directory>
+ </testsuite>
+ <testsuite name="API Test Suite">
+ <directory suffix="Test.php" prefix="API">./unit/</directory>
+ </testsuite>
+ <testsuite name="Ex-/Import Test Suite">
+ <!--<directory suffix="Test.php">./unit/eximport/</directory>-->
+ </testsuite>
+ <groups>
+ <exclude>
+ <group>postgresql</group>
+ </exclude>
+ </groups>
+ <!--cover reporting-->
+ <filter>
+ <whitelist processUncoveredFilesFromWhitelist="true">
+ <directory suffix=".php">../Zotlabs/</directory>
+ <directory suffix=".php">../include/</directory>
+ </whitelist>
+ </filter>
+ <logging>
+ <log type="junit" target="./results/junit.xml" logIncompleteSkipped="false"/>
+ <log type="coverage-clover" target="./results/coverage-clover.xml"/>
+ <log type="coverage-html" target="./results/coverage-report/" lowUpperBound="35"
+ highLowerBound="70"/>
+ <log type="testdox-text" target="./results/testdox.txt"/>
+ </logging>
+</phpunit>
diff --git a/tests/travis/gen_apidocs.sh b/tests/travis/gen_apidocs.sh
new file mode 100755
index 000000000..e5938e1e8
--- /dev/null
+++ b/tests/travis/gen_apidocs.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2016 Hubzilla
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# Exit if anything fails
+set -e
+
+# Only create and deploy API documentation once, on first build job.
+# Waiting for upcoming 'Build Stages' Q1/Q2 2017 to make this cleaner.
+# https://github.com/travis-ci/travis-ci/issues/929
+if [[ "$TRAVIS_JOB_NUMBER" != "${TRAVIS_BUILD_NUMBER}.1" ]]; then
+ echo "Not the first build job. Creating API documentation only once is enough."
+ echo "We are finished ..."
+ exit
+fi
+
+echo "Doxygen version >= 1.8 is required"
+doxygen --version
+
+# Check if newer version of Doxygen should be used
+if [ ! -z "$DOXY_VER" ]; then
+ export DOXY_BINPATH=$HOME/doxygen/doxygen-$DOXY_VER/bin
+ if [ ! -e "$DOXY_BINPATH/doxygen" ]; then
+ echo "Installing newer Doxygen $DOXY_VER ..."
+ mkdir -p $HOME/doxygen && cd $HOME/doxygen
+ wget -O - http://ftp.stack.nl/pub/users/dimitri/doxygen-$DOXY_VER.linux.bin.tar.gz | tar xz
+ export PATH=$DOXY_BINPATH:$PATH
+ fi
+ echo "Doxygen version"
+ doxygen --version
+fi
+
+echo "Generating Doxygen API documentation ..."
+cd $TRAVIS_BUILD_DIR
+mkdir -p ./doc/html
+# Redirect stderr and stdout to log file and console to be able to review documentation errors
+doxygen $DOXYFILE 2>&1 | tee ./doc/html/doxygen.log
+
+# Check if Doxygen successfully created the documentation
+if [ -d "doc/html" ] && [ -f "doc/html/index.html" ]; then
+ echo "API documentation generated"
+ if [ -n "${TRAVIS_TAG}" ]; then
+ echo "Generate API documentation archive for release deployment ..."
+ zip -9 -r -q doc/hubzilla-api-documentation.zip doc/html/
+ fi
+else
+ echo "No API documentation files have been found" >&2
+ exit 1
+fi
diff --git a/tests/travis/prepare.sh b/tests/travis/prepare.sh
new file mode 100755
index 000000000..267b4ec46
--- /dev/null
+++ b/tests/travis/prepare.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2016 Hubzilla
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# Exit if anything fails
+set -e
+
+# gd is required, show some info about the used one
+php -r "var_dump(gd_info());"
+
+
+echo "Creating required folders for Hubzilla ..."
+mkdir -p ./store/\[data\]/smarty3
+
+echo "TODO: create .htconfig"
diff --git a/tests/travis/prepare_mysql.sh b/tests/travis/prepare_mysql.sh
new file mode 100755
index 000000000..095ad7e25
--- /dev/null
+++ b/tests/travis/prepare_mysql.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2016 Hubzilla
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# Exit if anything fails
+set -e
+
+echo "Preparing for MySQL ..."
+
+if [[ "$MYSQL_VERSION" == "5.7" ]]; then
+ echo "Using MySQL 5.7 in Docker container, need to use TCP"
+ export PROTO="--protocol=TCP"
+fi
+
+# Print out some MySQL information
+mysql --version
+mysql $PROTO -e "SELECT VERSION();"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'max_allowed_packet';"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'collation_%';"
+mysql $PROTO -e "SHOW VARIABLES LIKE 'character_set%';"
+mysql $PROTO -e "SELECT @@sql_mode;"
+
+# Create Hubzilla database
+mysql $PROTO -u root -e "CREATE DATABASE IF NOT EXISTS hubzilla;";
+mysql $PROTO -u root -e "CREATE USER 'hubzilla'@'localhost' IDENTIFIED BY 'hubzilla';"
+mysql $PROTO -u root -e "GRANT ALL ON hubzilla.* TO 'hubzilla'@'localhost';"
+
+# Import table structure
+mysql $PROTO -u root hubzilla < ./install/schema_mysql.sql
+
+# Show databases and tables
+mysql $PROTO -u root -e "SHOW DATABASES;"
+mysql $PROTO -u root -e "USE hubzilla; SHOW TABLES;"
diff --git a/tests/travis/prepare_pgsql.sh b/tests/travis/prepare_pgsql.sh
new file mode 100755
index 000000000..63c7388cb
--- /dev/null
+++ b/tests/travis/prepare_pgsql.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+#
+# Copyright (c) 2016 Hubzilla
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+# Exit if anything fails
+set -e
+
+echo "Preparing for PostgreSQL ..."
+
+# Print out some PostgreSQL information
+psql --version
+# Why does this hang further execution of the job?
+psql -U postgres -c "SELECT VERSION();"
+
+# Create Hubzilla database
+psql -U postgres -c "DROP DATABASE IF EXISTS hubzilla;"
+psql -U postgres -c "CREATE DATABASE hubzilla;"
+
+# Import table structure
+psql -U postgres -v ON_ERROR_STOP=1 hubzilla < ./install/schema_postgres.sql
+
+# Show databases and tables
+psql -U postgres -l
+psql -U postgres -d hubzilla -c "\dt;"
diff --git a/tests/unit/Access/AccessListTest.php b/tests/unit/Access/AccessListTest.php
new file mode 100644
index 000000000..dbc19fabb
--- /dev/null
+++ b/tests/unit/Access/AccessListTest.php
@@ -0,0 +1,191 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\Access;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Access\AccessList;
+
+/**
+ * @brief Unit Test case for AccessList class.
+ *
+ * @covers Zotlabs\Access\AccessList
+ */
+class AccessListTest extends UnitTestCase {
+
+ /**
+ * @brief Expected result for most tests.
+ * @var array
+ */
+ protected $expectedResult = [
+ 'allow_cid' => '<acid><acid2>',
+ 'allow_gid' => '<agid>',
+ 'deny_cid' => '',
+ 'deny_gid' => '<dgid><dgid2>'
+ ];
+
+
+
+ public function testConstructor() {
+ $channel = [
+ 'channel_allow_cid' => '<acid><acid2>',
+ 'channel_allow_gid' => '<agid>',
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => '<dgid><dgid2>'
+ ];
+
+ $accessList = new AccessList($channel);
+
+ $this->assertEquals($this->expectedResult, $accessList->get());
+ $this->assertFalse($accessList->get_explicit());
+ }
+
+ /**
+ * @expectedException PHPUnit\Framework\Error\Error
+ */
+ public function testPHPErrorOnInvalidConstructor() {
+ $accessList = new AccessList('invalid');
+ // Causes: "Illegal string offset 'channel_allow_cid'"
+ }
+
+ public function testDefaultGetExplicit() {
+ $accessList = new AccessList([]);
+
+ $this->assertFalse($accessList->get_explicit());
+ }
+
+ public function testDefaultGet() {
+ $arr = [
+ 'allow_cid' => '',
+ 'allow_gid' => '',
+ 'deny_cid' => '',
+ 'deny_gid' => ''
+ ];
+
+ $accessList = new AccessList([]);
+
+ $this->assertEquals($arr, $accessList->get());
+ }
+
+ public function testSet() {
+ $arr = [
+ 'allow_cid' => '<acid><acid2>',
+ 'allow_gid' => '<agid>',
+ 'deny_cid' => '',
+ 'deny_gid' => '<dgid><dgid2>'
+ ];
+ $accessList = new AccessList([]);
+
+ // default explicit true
+ $accessList->set($arr);
+
+ $this->assertEquals($this->expectedResult, $accessList->get());
+ $this->assertTrue($accessList->get_explicit());
+
+ // set explicit false
+ $accessList->set($arr, false);
+
+ $this->assertEquals($this->expectedResult, $accessList->get());
+ $this->assertFalse($accessList->get_explicit());
+ }
+
+ /**
+ * @expectedException PHPUnit\Framework\Error\Error
+ */
+ public function testPHPErrorOnInvalidSet() {
+ $accessList = new AccessList([]);
+
+ $accessList->set('invalid');
+ // Causes: "Illegal string offset 'allow_cid'"
+ }
+
+ /**
+ * set_from_array() calls some other functions, too which are not yet unit tested.
+ * @uses ::perms2str
+ * @uses ::sanitise_acl
+ * @uses ::notags
+ */
+ public function testSetFromArray() {
+ // array
+ $arraySetFromArray = [
+ 'contact_allow' => ['acid', 'acid2'],
+ 'group_allow' => ['agid'],
+ 'contact_deny' => [],
+ 'group_deny' => ['dgid', 'dgid2']
+ ];
+ $accessList = new AccessList([]);
+ $accessList->set_from_array($arraySetFromArray);
+
+ $this->assertEquals($this->expectedResult, $accessList->get());
+ $this->assertTrue($accessList->get_explicit());
+
+
+ // string
+ $stringSetFromArray = [
+ 'contact_allow' => 'acid,acid2',
+ 'group_allow' => 'agid',
+ 'contact_deny' => '',
+ 'group_deny' => 'dgid, dgid2'
+ ];
+ $accessList2 = new AccessList([]);
+ $accessList2->set_from_array($stringSetFromArray, false);
+
+ $this->assertEquals($this->expectedResult, $accessList2->get());
+ $this->assertFalse($accessList2->get_explicit());
+ }
+
+ /**
+ * @dataProvider isprivateProvider
+ */
+ public function testIsPrivate($channel) {
+ $accessListPublic = new AccessList([]);
+ $this->assertFalse($accessListPublic->is_private());
+
+ $accessListPrivate = new AccessList($channel);
+ $this->assertTrue($accessListPrivate->is_private());
+ }
+
+ public function isprivateProvider() {
+ return [
+ 'all set' => [[
+ 'channel_allow_cid' => '<acid>',
+ 'channel_allow_gid' => '<agid>',
+ 'channel_deny_cid' => '<dcid>',
+ 'channel_deny_gid' => '<dgid>'
+ ]],
+ 'only one set' => [[
+ 'channel_allow_cid' => '<acid>',
+ 'channel_allow_gid' => '',
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => ''
+ ]],
+ 'acid+null' => [[
+ 'channel_allow_cid' => '<acid>',
+ 'channel_allow_gid' => null,
+ 'channel_deny_cid' => '',
+ 'channel_deny_gid' => ''
+ ]]
+ ];
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/Access/PermissionLimitsTest.php b/tests/unit/Access/PermissionLimitsTest.php
new file mode 100644
index 000000000..58595111a
--- /dev/null
+++ b/tests/unit/Access/PermissionLimitsTest.php
@@ -0,0 +1,78 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\Access;
+
+use phpmock\phpunit\PHPMock;
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Access\PermissionLimits;
+
+/**
+ * @brief Unit Test case for PermissionLimits class.
+ *
+ * @covers Zotlabs\Access\PermissionLimits
+ */
+class PermissionLimitsTest extends UnitTestCase {
+
+ use PHPMock;
+
+ /**
+ * @todo If we could replace static call to Permissions::Perms() in
+ * Std_Limits() we could better unit test this method, now we test the
+ * result of Permissions::Perms() mostly.
+ *
+ * @uses Zotlabs\Access\Permissions::Perms
+ * @uses ::call_hooks
+ */
+ public function testStd_Limits() {
+ // There are 18 default perms
+ $permsCount = 18;
+
+ // Create a stub for global function t() with expectation
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+ $t->expects($this->exactly($permsCount));
+
+ $stdlimits = PermissionLimits::Std_Limits();
+ $this->assertCount($permsCount, $stdlimits, "There should be $permsCount permissions.");
+
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_stream']);
+ $this->assertEquals(PERMS_SPECIFIC, $stdlimits['send_stream']);
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_profile']);
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_contacts']);
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_storage']);
+ $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_storage']);
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_pages']);
+ $this->assertEquals(PERMS_PUBLIC, $stdlimits['view_wiki']);
+ $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_pages']);
+ $this->assertEquals(PERMS_SPECIFIC, $stdlimits['write_wiki']);
+ $this->assertEquals(PERMS_SPECIFIC, $stdlimits['post_wall']);
+ $this->assertEquals(PERMS_PUBLIC, $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
new file mode 100644
index 000000000..5e64e773a
--- /dev/null
+++ b/tests/unit/Access/PermissionRolesTest.php
@@ -0,0 +1,100 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\Access;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Access\PermissionRoles;
+use phpmock\phpunit\PHPMock;
+
+/**
+ * @brief Unit Test case for PermissionRoles class.
+ *
+ * @TODO Work around dependencies to static PermissionLimits methods.
+ *
+ * @covers Zotlabs\Access\PermissionRoles
+ */
+class PermissionRolesTest extends UnitTestCase {
+
+ use PHPMock;
+
+ public function testVersion() {
+ $expectedVersion = 2;
+
+ $this->assertEquals($expectedVersion, PermissionRoles::version());
+
+ $pr = new PermissionRoles();
+ $this->assertEquals($expectedVersion, $pr->version());
+ }
+
+
+ public function testRoles() {
+ // Create a stub for global function t() with expectation
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+ $t->expects($this->atLeastOnce())->willReturnCallback(
+ function ($string) {
+ return $string;
+ }
+ );
+
+ $roles = PermissionRoles::roles();
+ $r = new PermissionRoles();
+ $this->assertEquals($roles, $r->roles());
+
+ $socialNetworking = [
+ 'social' => 'Social - Mostly Public',
+ 'social_restricted' => 'Social - Restricted',
+ 'social_private' => 'Social - Private'
+ ];
+
+ $this->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");
+ }
+
+
+ /**
+ * @uses ::call_hooks
+ * @uses Zotlabs\Access\PermissionLimits::Std_Limits
+ * @uses Zotlabs\Access\Permissions::Perms
+ */
+ public function testRole_perms() {
+ // Create a stub for global function t()
+ $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_custom = PermissionRoles::role_perms('custom');
+ $this->assertEquals(['role' => 'custom'], $rp_custom);
+
+ $rp_nonexistent = PermissionRoles::role_perms('nonexistent');
+ $this->assertEquals(['role' => 'nonexistent'], $rp_nonexistent);
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/Access/PermissionsTest.php b/tests/unit/Access/PermissionsTest.php
new file mode 100644
index 000000000..40724fff8
--- /dev/null
+++ b/tests/unit/Access/PermissionsTest.php
@@ -0,0 +1,322 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\Access;
+
+use phpmock\phpunit\PHPMock;
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Access\Permissions;
+
+/**
+ * @brief Unit Test case for Permissions class.
+ *
+ * @covers Zotlabs\Access\Permissions
+ */
+class PermissionsTest extends UnitTestCase {
+
+ use PHPMock;
+
+ public function testVersion() {
+ $expectedVersion = 2;
+
+ // static call
+ $this->assertEquals($expectedVersion, Permissions::version());
+
+ // instance call
+ $p = new Permissions();
+ $this->assertEquals($expectedVersion, $p->version());
+ }
+
+ /**
+ * @coversNothing
+ */
+ public function testVersionEqualsPermissionRoles() {
+ $p = new Permissions();
+ $pr = new \Zotlabs\Access\PermissionRoles();
+ $this->assertEquals($p->version(), $pr->version());
+ }
+
+ /**
+ * @uses ::call_hooks
+ */
+ public function testPerms() {
+ // There are 18 default perms
+ $permsCount = 18;
+
+ // Create a stub for global function t() with expectation
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+ $t->expects($this->exactly(2*$permsCount))->willReturnCallback(
+ function ($string) {
+ return $string;
+ }
+ );
+
+ // static method Perms()
+ $perms = Permissions::Perms();
+
+ $p = new Permissions();
+ $this->assertEquals($perms, $p->Perms());
+
+ $this->assertEquals($permsCount, count($perms), "There should be $permsCount permissions.");
+
+ $this->assertEquals('Can view my channel stream and posts', $perms['view_stream']);
+
+ // non existent perm should not be set
+ $this->assertFalse(isset($perms['invalid_perm']));
+ }
+
+ /**
+ * filter parmeter is only used in hook \b permissions_list. So the result
+ * in this test should be the same as if there was no filter parameter.
+ *
+ * @todo Stub call_hooks() function and also test filter
+ *
+ * @uses ::call_hooks
+ */
+ public function testPermsFilter() {
+ // There are 18 default perms
+ $permsCount = 18;
+
+ // Create a stub for global function t() with expectation
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+ $t->expects($this->exactly(2*$permsCount))->willReturnCallback(
+ function ($string) {
+ return $string;
+ }
+ );
+
+ $perms = Permissions::Perms('view_');
+ $this->assertEquals($permsCount, count($perms));
+
+ $this->assertEquals('Can view my channel stream and posts', $perms['view_stream']);
+
+ $perms = Permissions::Perms('invalid_perm');
+ $this->assertEquals($permsCount, count($perms));
+ }
+
+ /**
+ * Better should mock Permissions::Perms, but not possible with static methods.
+ *
+ * @uses ::call_hooks
+ *
+ * @dataProvider FilledPermsProvider
+ *
+ * @param array $permarr An indexed permissions array to pass
+ * @param array $expected The expected result perms array
+ */
+ public function testFilledPerms($permarr, $expected) {
+ // Create a stub for global function t()
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+
+ $this->assertEquals($expected, Permissions::FilledPerms($permarr));
+ }
+ /**
+ * @return array An associative array with test values for FilledPerms()
+ * * \e array Indexed array which is passed as parameter to FilledPerms()
+ * * \e array Expected associative result array with filled perms
+ */
+ public function FilledPermsProvider() {
+ return [
+ 'Empty param array' => [
+ [],
+ [
+ 'view_stream' => 0,
+ 'send_stream' => 0,
+ 'view_profile' => 0,
+ 'view_contacts' => 0,
+ 'view_storage' => 0,
+ 'write_storage' => 0,
+ 'view_pages' => 0,
+ 'view_wiki' => 0,
+ 'write_pages' => 0,
+ 'write_wiki' => 0,
+ 'post_wall' => 0,
+ 'post_comments' => 0,
+ 'post_mail' => 0,
+ 'post_like' => 0,
+ 'tag_deliver' => 0,
+ 'chat' => 0,
+ 'republish' => 0,
+ 'delegate' => 0
+ ]
+ ],
+ 'provide view_stream and view_pages as param' => [
+ ['view_stream', 'view_pages'],
+ [
+ 'view_stream' => 1,
+ 'send_stream' => 0,
+ 'view_profile' => 0,
+ 'view_contacts' => 0,
+ 'view_storage' => 0,
+ 'write_storage' => 0,
+ 'view_pages' => 1,
+ 'view_wiki' => 0,
+ 'write_pages' => 0,
+ 'write_wiki' => 0,
+ 'post_wall' => 0,
+ 'post_comments' => 0,
+ 'post_mail' => 0,
+ 'post_like' => 0,
+ 'tag_deliver' => 0,
+ 'chat' => 0,
+ 'republish' => 0,
+ 'delegate' => 0
+ ]
+ ],
+ 'provide an unknown param' => [
+ ['view_stream', 'unknown_perm'],
+ [
+ 'view_stream' => 1,
+ 'send_stream' => 0,
+ 'view_profile' => 0,
+ 'view_contacts' => 0,
+ 'view_storage' => 0,
+ 'write_storage' => 0,
+ 'view_pages' => 0,
+ 'view_wiki' => 0,
+ 'write_pages' => 0,
+ 'write_wiki' => 0,
+ 'post_wall' => 0,
+ 'post_comments' => 0,
+ 'post_mail' => 0,
+ 'post_like' => 0,
+ 'tag_deliver' => 0,
+ 'chat' => 0,
+ 'republish' => 0,
+ 'delegate' => 0
+ ]
+ ]
+ ];
+ }
+ /**
+ * @uses ::call_hooks
+ */
+ public function testFilledPermsNull() {
+ // Create a stub for global function t() with expectation
+ $t = $this->getFunctionMock('Zotlabs\Access', 't');
+ $t->expects($this->atLeastOnce());
+ // Create a stub for global function bt() with expectations
+ $bt = $this->getFunctionMock('Zotlabs\Access', 'btlogger');
+ $bt->expects($this->once())->with($this->equalTo('FilledPerms: null'));
+
+ $result = [
+ 'view_stream' => 0,
+ 'send_stream' => 0,
+ 'view_profile' => 0,
+ 'view_contacts' => 0,
+ 'view_storage' => 0,
+ 'write_storage' => 0,
+ 'view_pages' => 0,
+ 'view_wiki' => 0,
+ 'write_pages' => 0,
+ 'write_wiki' => 0,
+ 'post_wall' => 0,
+ 'post_comments' => 0,
+ 'post_mail' => 0,
+ 'post_like' => 0,
+ 'tag_deliver' => 0,
+ 'chat' => 0,
+ 'republish' => 0,
+ 'delegate' => 0
+ ];
+
+ $this->assertEquals($result, Permissions::FilledPerms(null));
+ }
+
+ /**
+ * @dataProvider OPermsProvider
+ *
+ * @param array $permarr The params to pass to the OPerms method
+ * @param array $expected The expected result
+ */
+ public function testOPerms($permarr, $expected) {
+ $this->assertEquals($expected, Permissions::OPerms($permarr));
+ }
+ /**
+ * @return array An associative array with test values for OPerms()
+ * * \e array Array with perms to test
+ * * \e array Expected result array
+ */
+ public function OPermsProvider() {
+ return [
+ 'empty' => [
+ [],
+ []
+ ],
+ 'valid' => [
+ ['perm1' => 1, 'perm2' => 0],
+ [['name' => 'perm1', 'value' => 1], ['name' => 'perm2', 'value' => 0]]
+ ],
+ 'null array' => [
+ null,
+ []
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider permsCompareProvider
+ *
+ * @param array $p1 The first permission
+ * @param array $p2 The second permission
+ * @param boolean $expectedresult The expected result of the tested method
+ */
+ public function testPermsCompare($p1, $p2, $expectedresult) {
+ $this->assertEquals($expectedresult, Permissions::PermsCompare($p1, $p2));
+ }
+ /**
+ * @return array An associative array with test values for PermsCompare()
+ * * \e array 1st array with perms
+ * * \e array 2nd array with perms
+ * * \e boolean expected result for the perms comparison
+ */
+ public function permsCompareProvider() {
+ return [
+ 'equal' => [
+ ['perm1' => 1, 'perm2' => 0],
+ ['perm1' => 1, 'perm2' => 0],
+ true
+ ],
+ 'different values' => [
+ ['perm1' => 1, 'perm2' => 0],
+ ['perm1' => 0, 'perm2' => 1],
+ false
+ ],
+ 'different order' => [
+ ['perm1' => 1, 'perm2' => 0],
+ ['perm2' => 0, 'perm1' => 1],
+ true
+ ],
+ 'partial first in second' => [
+ ['perm1' => 1],
+ ['perm1' => 1, 'perm2' => 0],
+ true
+ ],
+ 'partial second in first' => [
+ ['perm1' => 1, 'perm2' => 0],
+ ['perm1' => 1],
+ false
+ ]
+ ];
+ }
+}
diff --git a/tests/unit/AutonameTest.php b/tests/unit/AutonameTest.php
index 9f92f736f..33e237bb9 100644
--- a/tests/unit/AutonameTest.php
+++ b/tests/unit/AutonameTest.php
@@ -57,7 +57,7 @@ class AutonameTest extends TestCase {
// public function testAutonameMaxLength() {
// $autoname2=autoname(PHP_INT_MAX);
- // $this->assertEquals(PHP_INT_MAX, count($autoname2));
+ // $this->assertEquals(PHP_INT_MAX, strlen($autoname2));
// }
/**
@@ -65,14 +65,14 @@ class AutonameTest extends TestCase {
*/
public function testAutonameLength1() {
$autoname1=autoname(1);
- $this->assertEquals(1, count($autoname1));
+ $this->assertEquals(1, strlen($autoname1));
$autoname2=autoname(1);
- $this->assertEquals(1, count($autoname2));
+ $this->assertEquals(1, strlen($autoname2));
// The following test is problematic, with only 26 possibilities
// generating the same thing twice happens often aka
// birthday paradox
// $this->assertFalse($autoname1==$autoname2);
}
-} \ No newline at end of file
+}
diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php
index b1da5a0fd..96c381d0c 100644
--- a/tests/unit/Lib/PermissionDescriptionTest.php
+++ b/tests/unit/Lib/PermissionDescriptionTest.php
@@ -1,6 +1,6 @@
<?php
/*
- * Copyright (c) 2016 Hubzilla
+ * Copyright (c) 2016-2017 Hubzilla
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,90 +21,77 @@
* SOFTWARE.
*/
-// Global namespace for fully qualified \App class.
-namespace {
- // General channel permissions in boot.php
- // 0 = Only you
- define ( 'PERMS_PUBLIC' , 0x0001 ); // anybody
- define ( 'PERMS_NETWORK' , 0x0002 ); // anybody in this network
- define ( 'PERMS_SITE' , 0x0004 ); // anybody on this site
- define ( 'PERMS_CONTACTS' , 0x0008 ); // any of my connections
- define ( 'PERMS_SPECIFIC' , 0x0080 ); // only specific connections
- define ( 'PERMS_AUTHED' , 0x0100 ); // anybody authenticated (could include visitors from other networks)
- define ( 'PERMS_PENDING' , 0x0200 ); // any connections including those who haven't yet been approved
- // log levels in boot.php
- define ( 'LOGGER_DEBUG', 2 );
+namespace Zotlabs\Tests\Unit\Lib;
- // Stub global fully qualified \App class for static function calls
- class App {
- // Stub get_hostname()
- public static function get_hostname() {
- return 'phpunit';
- }
- }
-}
+use phpmock\phpunit\PHPMock;
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Zotlabs\Lib\PermissionDescription;
-// Stub global functions used in PermissionDescription with the help of
-// PHP's namespace resolution rules.
-namespace Zotlabs\Lib {
- // Stub global translate function t()
- function t($s) {
- return $s;
- }
- // Stub global log function logger()
- function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
- // doesn't matter
- }
-}
+/**
+ * @brief Unit Test case for PermissionDescription class.
+ *
+ * @covers Zotlabs\Lib\PermissionDescription
+ */
+class PermissionDescriptionTest extends UnitTestCase {
-// regular namespace for this unit test
-namespace Zotlabs\Tests\Unit\Lib {
+ use PHPMock;
- use Zotlabs\Tests\Unit\UnitTestCase;
- use Zotlabs\Lib\PermissionDescription;
+ public function testFromDescription() {
+ $permDesc = PermissionDescription::fromDescription('test');
+ $permDesc2 = PermissionDescription::fromDescription('test');
+ $permDesc3 = PermissionDescription::fromDescription('test2');
- /**
- * @brief Unit Test case for ConnectionPool class.
- */
- class PermissionDescriptionTest extends UnitTestCase {
+ $this->assertEquals($permDesc, $permDesc2);
+ $this->assertNotEquals($permDesc, $permDesc3);
+ }
- public function testFromDescription() {
- $permDesc = PermissionDescription::fromDescription('test');
- $permDesc2 = PermissionDescription::fromDescription('test');
- $permDesc3 = PermissionDescription::fromDescription('test2');
+ public function testFromStandalonePermission() {
+ // Create a stub for global function t()
+ $t = $this->getFunctionMock('Zotlabs\Lib', 't');
+ $t->expects($this->atLeastOnce())->willReturnCallback(
+ function ($string) {
+ return $string;
+ }
+ );
+ // Create a mock for global function logger()
+ $this->getFunctionMock('Zotlabs\Lib', 'logger');
- $this->assertEquals($permDesc, $permDesc2);
- $this->assertNotEquals($permDesc, $permDesc3);
- }
+ $permDescUnknown = PermissionDescription::fromStandalonePermission(-1);
+ $permDescSelf = PermissionDescription::fromStandalonePermission(0);
- public function testFromStandalonePermission() {
- $permDescUnknown = PermissionDescription::fromStandalonePermission(-1);
- $permDescSelf = PermissionDescription::fromStandalonePermission(0);
+ $this->assertNull($permDescUnknown);
+ $this->assertNotNull($permDescSelf);
+ }
- $this->assertNull($permDescUnknown);
- $this->assertNotNull($permDescSelf);
- }
+ public function testFromGlobalPermission() {
+ //$permDesc = PermissionDescription::fromGlobalPermission('view_profile');
- public function testFromGlobalPermission() {
- //$permDesc = PermissionDescription::fromGlobalPermission('view_profile');
+ $this->markTestIncomplete(
+ 'The method fromGlobalPermission() is not yet testable ...'
+ );
+ }
- $this->markTestIncomplete(
- 'For this test we need more stubs...'
- );
- }
+ public function testGetPermissionDescription() {
+ // Create a stub for global function t()
+ $t = $this->getFunctionMock('Zotlabs\Lib', 't');
+ $t->expects($this->atLeastOnce())->willReturnCallback(
+ function ($string) {
+ return $string;
+ }
+ );
+ // Create a mock for global function logger()
+ $this->getFunctionMock('Zotlabs\Lib', 'logger');
- public function testGetPermissionDescription() {
+ // Create a stub for the PermissionDescription class
+ $stub = $this->createMock(PermissionDescription::class);
+ $stub->method('get_permission_description')
+ ->will($this->returnArgument(0));
- // fromStandalonePermission uses get_permission_description(), so that will not help
- //$permDescSelf = PermissionDescription::fromStandalonePermission(0);
- //$permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC);
+ $permDescSelf = PermissionDescription::fromStandalonePermission(0);
+ $this->assertInstanceOf(PermissionDescription::class, $permDescSelf);
+ $this->assertEquals($permDescSelf->get_permission_description(), 'Only me');
- $this->markTestIncomplete(
- 'For this test we need a mock of PermissionDescription...'
- );
- //$permDescSelf =
- //$this->assertEquals($permDescSelf->, 'Only me');
- //$this->assertEquals($permDescPublic, 'Public');
- }
+ $permDescPublic = PermissionDescription::fromStandalonePermission(PERMS_PUBLIC);
+ $this->assertEquals($permDescPublic->get_permission_description(), 'Public');
}
}
diff --git a/tests/unit/TextTest.php b/tests/unit/TextTest.php
deleted file mode 100644
index 48c04bc54..000000000
--- a/tests/unit/TextTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/**
- * this file contains tests for text.php
- *
- * @package test.util
- */
-
-use PHPUnit\Framework\TestCase;
-
-/** required, it is the file under test */
-require_once('include/text.php');
-
-/**
- * TestCase for the texter
- *
- * @author ken restivo
- * @package test.util
- */
-class TextTest extends TestCase {
- public function testGoodEmail() {
- $this->assertTrue(valid_email_regex('ken@spaz.org'));
- }
- public function testGoodEmail2() {
- $this->assertTrue(valid_email_regex('ken@restivo.org'));
- }
- public function testGoodEmail3() {
- $this->assertTrue(valid_email_regex('nobody@hubzilla.com'));
- }
- public function testBadEmail() {
- $this->assertFalse(valid_email_regex('nobody!uses!these!any.more'));
- }
-
-} \ No newline at end of file
diff --git a/tests/unit/includes/FeedutilsTest.php b/tests/unit/includes/FeedutilsTest.php
new file mode 100644
index 000000000..e9826a73d
--- /dev/null
+++ b/tests/unit/includes/FeedutilsTest.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+
+/**
+ * @brief Unit Test case for include/feedutils.php file.
+ */
+class FeedutilsTest extends UnitTestCase {
+
+ public function test_normalise_id() {
+ $this->assertEquals('id', normalise_id('id'));
+ $this->assertEquals('id', normalise_id('X-ZOT:id'));
+ $this->assertEquals('id id2', normalise_id('X-ZOT:id X-ZOT:id2'));
+ $this->assertEmpty(normalise_id(''));
+ }
+
+ public function test_encode_rel_links() {
+ // invalid params return empty array
+ $this->assertEquals([], encode_rel_links('string'));
+ $this->assertEquals([], encode_rel_links([]));
+
+ $b = ['attribs' => ['' => [
+ 'rel' => 'rel_value',
+ 'type' => 'type_value',
+ 'href' => 'href_value',
+ 'length' => 'length_value',
+ 'title' => 'title_value'
+ ]]];
+ $blink1 = ['link1' => $b];
+ $bresult[] = $b['attribs'][''];
+ $this->assertEquals($bresult, encode_rel_links($blink1));
+ }
+
+/* public function test_encode_rel_links_fail() {
+ $a = [ 'key' => 'value'];
+ $this->assertFalse(encode_rel_links($a));
+ //Illegal string offset 'attribs'
+ }*/
+
+ /**
+ * @uses ::xmlify
+ */
+ public function test_atom_author() {
+ $this->assertEquals('', atom_author('', 'nick', 'name', 'uri', 72, 72, 'png', 'photourl'));
+
+ $a = '<tag>
+ <id>uri</id>
+ <name>nick</name>
+ <uri>uri</uri>
+ <link rel="photo" type="png" media:width="72" media:height="72" href="http://photourl" />
+ <link rel="avatar" type="png" media:width="72" media:height="72" href="http://photourl" />
+ <poco:preferredUsername>nick</poco:preferredUsername>
+ <poco:displayName>name</poco:displayName>
+</tag>';
+
+ $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl'));
+ }
+
+ /**
+ * @uses ::xmlify
+ */
+ public function test_atom_render_author() {
+ $xchan = [
+ 'xchan_addr' => 'chan@hub',
+ 'xchan_url' => 'http://hub',
+ 'xchan_name' => 'Chan',
+ 'xchan_photo_l' => 'http://hub/img',
+ 'xchan_photo_mimetype' => 'mimetype'
+ ];
+ // There is no input validation in atom_render_author
+ //$this->assertEquals('', atom_render_author('', $xchan));
+
+ $a = '<tag>
+ <as:object-type>http://activitystrea.ms/schema/1.0/person</as:object-type>
+ <id>http://hub</id>
+ <name>chan</name>
+ <uri>http://hub</uri>
+ <link rel="alternate" type="text/html" href="http://hub" />
+ <link rel="photo" type="mimetype" media:width="300" media:height="300" href="http://hub/img" />
+ <link rel="avatar" type="mimetype" media:width="300" media:height="300" href="http://hub/img" />
+ <poco:preferredUsername>chan</poco:preferredUsername>
+ <poco:displayName>Chan</poco:displayName>
+</tag>';
+
+ $this->assertXmlStringEqualsXmlString($a, atom_render_author('tag', $xchan));
+ }
+}
diff --git a/tests/unit/includes/LanguageTest.php b/tests/unit/includes/LanguageTest.php
new file mode 100644
index 000000000..dd71115c4
--- /dev/null
+++ b/tests/unit/includes/LanguageTest.php
@@ -0,0 +1,164 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use Text_LanguageDetect;
+//use phpmock\phpunit\PHPMock;
+
+/**
+ * @brief Unit Test cases for include/language.php file.
+ *
+ * @author Klaus Weidenbach
+ */
+class LanguageTest extends UnitTestCase {
+ //use PHPMock;
+
+ /**
+ * @dataProvider languageExamplesProvider
+ * @coversNothing
+ */
+ public function testDetectLanguage($text, $langCode, $confidence) {
+
+ // php-mock can not mock global functions which is called by a global function.
+ // If the calling function is in a namespace it would work.
+ //$gc = $this->getFunctionMock(__NAMESPACE__, 'get_config');
+ //$gc->expects($this->once())->willReturn(10)
+ //$cg = $this->getFunctionMock('Zotlabs\Lib\Config', 'Get');
+ //$cg->expects($this->once())->willReturn(10);
+ //$this->assertEquals($langCode, detect_language($text));
+
+
+ // Can not unit test detect_language(), therefore test the used library
+ // only for now to find regressions on library updates.
+ $l = new Text_LanguageDetect;
+ // return 2-letter ISO 639-1 (en) language code
+ $l->setNameMode(2);
+ $lng = $l->detectConfidence($text);
+
+ $this->assertEquals($langCode, $lng['language']);
+ $this->assertEquals($confidence, round($lng['confidence'], 6));
+ }
+
+ 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',
+ 0.078422
+ ],
+ 'German' => [
+ 'Deutschland ist ein Bundesstaat in Mitteleuropa. Er besteht aus 16 Ländern und ist als freiheitlich-demokratischer und sozialer Rechtsstaat verfasst. Die Bundesrepublik Deutschland stellt die jüngste Ausprägung des deutschen Nationalstaates dar. Mit rund 82,8 Millionen Einwohnern (31. Dezember 2016) zählt Deutschland zu den dicht besiedelten Flächenstaaten.',
+ 'de',
+ 0.134339
+ ],
+ 'Norwegian' => [
+ 'Kongeriket Norge er et nordisk, europeisk land og en selvstendig stat vest på Den skandinaviske halvøy. Landet er langt og smalt, og kysten strekker seg langs Nord-Atlanteren, hvor også Norges kjente fjorder befinner seg. Totalt dekker det relativt tynt befolkede landet 385 000 kvadratkilometer med litt over fem millioner innbyggere (2016).',
+ 'no',
+ 0.007076
+ ]
+ ];
+ }
+
+
+ /**
+ * @covers ::get_language_name
+ * @dataProvider getLanguageNameProvider
+ */
+ public function testGetLanguageName($lang, $name, $trans) {
+ $this->assertEquals($name, get_language_name($lang));
+ foreach ($trans as $k => $v) {
+ //echo "$k -> $v";
+ $this->assertEquals($v, get_language_name($lang, $k));
+ }
+ }
+
+ public function getLanguageNameProvider() {
+ return [
+ 'empty language code' => [
+ '',
+ '',
+ ['de' => '']
+ ],
+ 'invalid language code' => [
+ 'zz',
+ 'zz',
+ ['de' => 'zz']
+ ],
+ 'de' => [
+ 'de',
+ 'German',
+ [
+ 'de' => 'Deutsch',
+ 'nb' => 'tysk'
+ ]
+ ],
+ 'de-de' => [
+ 'de-de',
+ 'German',
+ [
+ 'de-de' => 'Deutsch',
+ 'nb' => 'Deutsch' // should be tysk, seems to be a bug upstream
+ ]
+ ],
+ 'en' => [
+ 'en',
+ 'English',
+ [
+ 'de' => 'Englisch',
+ 'nb' => 'engelsk'
+ ]
+ ],
+ 'en-gb' => [
+ 'en-gb',
+ 'British English',
+ [
+ 'de' => 'Britisches Englisch',
+ 'nb' => 'engelsk (Storbritannia)'
+ ]
+ ],
+ 'en-au' => [
+ 'en-au',
+ 'Australian English',
+ [
+ 'de' => 'Australisches Englisch',
+ 'nb' => 'engelsk (Australia)'
+ ]
+ ],
+ 'nb' => [
+ 'nb',
+ 'Norwegian Bokmål',
+ [
+ 'de' => 'Norwegisch Bokmål',
+ 'nb' => 'norsk bokmål'
+ ]
+ ]
+ ];
+ }
+} \ No newline at end of file
diff --git a/tests/unit/includes/MarkdownTest.php b/tests/unit/includes/MarkdownTest.php
new file mode 100644
index 000000000..3026c633a
--- /dev/null
+++ b/tests/unit/includes/MarkdownTest.php
@@ -0,0 +1,149 @@
+<?php
+/*
+ * Copyright (c) 2017 Hubzilla
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy
+* of this software and associated documentation files (the "Software"), to deal
+* in the Software without restriction, including without limitation the rights
+* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the Software is
+* furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in
+* all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+* SOFTWARE.
+*/
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+use phpmock\phpunit\PHPMock;
+
+require_once 'include/markdown.php';
+
+/**
+ * @brief Unit Test case for markdown functions.
+ */
+class MarkdownTest extends UnitTestCase {
+ use PHPMock;
+
+ /**
+ * @covers ::html2markdown
+ * @dataProvider html2markdownProvider
+ */
+ public function testHtml2markdown($html, $markdown) {
+ $this->assertEquals($markdown, html2markdown($html));
+ }
+
+ public function html2markdownProvider() {
+ return [
+ 'empty text' => [
+ '',
+ ''
+ ],
+ 'space and nbsp only' => [
+ ' &nbsp;',
+ ''
+ ],
+ 'strong, b, em, i, bib' => [
+ '<strong>strong</strong> <b>bold</b> <em>em</em> <i>italic</i> <b>bo<i>italic</i>ld</b>',
+ '**strong** **bold** _em_ _italic_ **bo_italic_ld**'
+ ],
+ 'empty tags' => [
+ 'text1 <b></b> text2 <i></i>',
+ 'text1 text2'
+ ],
+ 'HTML entities, lt does not work' => [
+ '& gt > lt <',
+ '& gt > lt'
+ ],
+ 'escaped HTML entities' => [
+ '&amp; lt &lt; gt &gt;',
+ '& lt < gt >'
+ ],
+ 'our escaped HTML entities' => [
+ '&_lt_; &_gt_; &_amp_;',
+ '&\_lt\_; &\_gt\_; &\_amp\_;'
+ ],
+ 'linebreak' => [
+ "line1<br>line2\nline3",
+ "line1 \nline2 line3"
+ ],
+ 'headlines' => [
+ '<h1>header1</h1><h3>Header 3</h3>',
+ "header1\n=======\n\n### Header 3"
+ ],
+ 'unordered list' => [
+ '<ul><li>Item 1</li><li>Item 2</li><li>Item <b>3</b></li></ul>',
+ "- Item 1\n- Item 2\n- Item **3**"
+ ],
+ 'ordered list' => [
+ '<ol><li>Item 1</li><li>Item 2</li><li>Item <b>3</b></li></ol>',
+ "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"
+ ],
+ 'img' => [
+ '<img src="/path/to/img.png" alt="alt text" title="title text">',
+ '![alt text](/path/to/img.png "title text")'
+ ],
+ 'link' => [
+ '<a href="http://hubzilla.org" title="Hubzilla">link</a>',
+ '[link](http://hubzilla.org "Hubzilla")'
+ ],
+ 'img link' => [
+ '<a href="http://hubzilla.org" title="Hubzilla"><img src="/img/hubzilla.png" alt="alt img text" title="img title"></a>',
+ '[![alt img text](/img/hubzilla.png "img title")](http://hubzilla.org "Hubzilla")'
+ ],
+ 'script' => [
+ "<script>alert('test');</script>",
+ "<script>alert('test');</script>"
+ ],
+ 'blockquote, issue #793' => [
+ '<blockquote>something</blockquote>blah',
+ "> something\n\nblah"
+ ],
+ 'code' => [
+ '<code>&lt;p&gt;HTML text&lt;/p&gt;</code>',
+ '`<p>HTML text</p>`'
+ ],
+ 'pre' => [
+ '<pre> line with spaces </pre>',
+ '` line with spaces `'
+ ],
+ 'div p' => [
+ '<div>div</div><div><p>p</p></div>',
+ "<div>div</div><div>p\n\n</div>"
+ ]
+ ];
+ }
+
+ /*public function testHtml2markdownException() {
+ //$this->expectException(\InvalidArgumentException::class);
+ // need to stub logger() for this to work
+ $this->assertEquals('', html2markdown('<<invalid'));
+ }*/
+
+/* public function testBB2diasporaMardown() {
+ //stub bbcode() and return our HTML, we just need to test the HTML2Markdown library.
+ $html1 = 'test<b>bold</b><br><i>i</i><ul><li>li1</li><li>li2</li></ul><br>';
+ $bb1 = 'test';
+
+ // php-mock can not mock global functions which is called by a global function.
+ // If the calling function is in a namespace it does work.
+ $bbc = $this->getFunctionMock(__NAMESPACE__, "bbcode");
+ $bbc->expects($this->once())->willReturn('test<b>bold</b><br><i>i</i><ul><li>li1</li><li>li2</li></ul><br>');
+
+ $this->assertEquals($bb1, bb2diaspora($html1));
+ }
+*/
+} \ No newline at end of file
diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php
new file mode 100644
index 000000000..97fa64895
--- /dev/null
+++ b/tests/unit/includes/TextTest.php
@@ -0,0 +1,120 @@
+<?php
+
+namespace Zotlabs\Tests\Unit\includes;
+
+use Zotlabs\Tests\Unit\UnitTestCase;
+
+/**
+ * @brief Unit Test case for include/text.php file.
+ *
+ * @author ken restivo
+ */
+class TextTest extends UnitTestCase {
+
+
+ public function testPurifyHTML() {
+ // linebreaks
+ $htmlbr = 'first line<br />
+ one tab preserved
+
+empty line above';
+ $this->assertEquals($htmlbr, purify_html($htmlbr));
+
+ // HTML5 is not supported by HTMLPurifier yet, test our own configuration
+ $html5elements = '<section>section<nav>navigation</nav><article>main<a href="http://hubzilla.org/">hubzilla.org</a></article></section><footer>footer</footer>';
+ $this->assertEquals($html5elements, purify_html($html5elements));
+ $this->assertEquals('<button>button label</button>', purify_html('<button>button label</button>'));
+
+ // unsupported HTML5 elements
+ $this->assertEquals('Your HTML parser does not support HTML5 video.', purify_html('<video controls><source src="movie.ogg" type="video/ogg">Your HTML parser does not support HTML5 video.</video>'));
+ $this->assertEquals('Your HTML parser does not support HTML5 audio.', purify_html('<audio controls><source src="movie.ogg" "type="audio/ogg">Your HTML parser does not support HTML5 audio.</audio>'));
+
+ // preserve f6 and bootstrap additional data attributes from our own configuration
+ $this->assertEquals('<div data-title="title">text</div>', purify_html('<div data-title="title">text</div>'));
+ $this->assertEquals('<ul data-accordion-menu=""><li>item1</li></ul>', purify_html('<ul data-accordion-menu><li>item1</li></ul>'));
+ $this->assertEquals('<ul><li>item1</li></ul>', purify_html('<ul data-accordion-menu-unknown><li>item1</li></ul>'));
+ }
+
+ /**
+ * @covers ::purify_html
+ */
+ public function testPurifyHTML_html() {
+ $this->assertEquals('<div id="id01"><p class="class01">ids und classes</p></div>', purify_html('<div id="id01"><p class="class01">ids und classes</p></div>'));
+ $this->assertEquals('<div><p>close missing tags</p></div>', purify_html('<div><p>close missing tags'));
+ $this->assertEquals('<center>deprecated tag</center>', purify_html('<center>deprecated tag</center>'));
+ $this->assertEquals('<span></span><div>illegal nesting</div>', purify_html('<span><div>illegal nesting</div></span>'));
+ $this->assertEquals('<a href="#">link with target</a>', purify_html('<a href="#" target="_blank">link with target</a>'));
+ $this->assertEquals('<a href="#">link with rel="nofollow"</a>', purify_html('<a href="#" rel="nofollow">link with rel="nofollow"</a>'));
+ $this->assertEquals('a b', purify_html('a&nbsp;b'));
+ $this->assertEquals('ä ä € €', purify_html('ä &auml; &euro; &#8364;'));
+ $this->assertEquals('<img src="picture.png" alt="text" />', purify_html('<img src="picture.png" alt="text">'));
+ $this->assertEquals('', purify_html('<iframe width="560" height="315" src="https://www.youtube.com/embed/kiNGx5oL7hk" frameborder="0" allowfullscreen></iframe>'));
+ }
+
+ /**
+ * @covers ::purify_html
+ */
+ public function testPurifyHTML_js() {
+ $this->assertEquals('<div></div>', purify_html('<div><img src="javascript:evil();" onload="evil();"></div>'));
+ $this->assertEquals('<a href="#">link</a>', purify_html('<a href="#" onclick="alert(\'xss\')">link</a>'));
+ $this->assertEquals('', purify_html('<IMG SRC="javascript:alert(&#039;XSS&#039;);">'));
+ $this->assertEquals('', purify_html('<script>alter("42")</script>'));
+ }
+
+ /**
+ * @covers ::purify_html
+ */
+ public function testPurifyHTML_css() {
+ $this->assertEquals('<p style="color:#FF0000;background-color:#fff;">red</p>', purify_html('<p style="color:red; background-color:#fff">red</p>'));
+ $this->assertEquals('<p>invalid color</p>', purify_html('<p style="color:invalid; background-color:#jjkkmm">invalid color</p>'));
+ $this->assertEquals('<p>invalid style</p>', purify_html('<p style="foo:bar">invalid style</p>'));
+
+ // test our own CSS configuration
+ $this->assertEquals('<div>position removed</div>', purify_html('<div style="position:absolut">position removed</div>'));
+ $this->assertEquals('<div style="position:fixed;">position preserved</div>', purify_html('<div style="position:fixed">position preserved</div>', true));
+ $this->assertEquals('<div>invalid position removed</div>', purify_html('<div style="position:invalid">invalid position removed</div>', true));
+
+ $this->assertEquals('<div>position removed</div>', purify_html('<div style="top:10px; left:3em;">position removed</div>'));
+ $this->assertEquals('<div style="top:10px;left:3em;right:50%;">position preserved</div>', purify_html('<div style="top:10px; left:3em; right:50%;">position preserved</div>', true));
+ $this->assertEquals('<div>invalid position removed</div>', purify_html('<div style="top:10p">invalid position removed</div>', true));
+ }
+
+ /**
+ * @dataProvider notagsProvider
+ */
+ public function testNotags($string, $expected) {
+ $this->assertEquals($expected, notags($string));
+ }
+ public function notagsProvider() {
+ return [
+ 'empty string' => ['', ''],
+ 'simple tag' => ['<value>', '[value]'],
+ 'tag pair' => ['<b>text</b>', '[b]text[/b]'],
+ 'double angle bracket' => ['<<value', '[[value'],
+ 'HTML entity &gt;' => ['&gt;', '&gt;']
+ ];
+ }
+
+ /**
+ * @dataProvider sanitise_aclProvider
+ */
+ public function testSanitise_acl($string, $expected) {
+ sanitise_acl($string);
+ $this->assertEquals($expected, $string);
+ }
+ public function sanitise_aclProvider() {
+ return [
+ 'text' => ['value', '<value>'],
+ 'text with angle bracket' => ['<value>', '<[value]>'],
+ 'comma separated acls' => ['value1,value2', '<value1,value2>']
+ ];
+ }
+
+ public function testUnsetSanitise_acl() {
+ $empty = '';
+ sanitise_acl($empty);
+ $this->assertTrue(isset($empty)); // unset() not working? Would expect false
+ $this->assertEmpty($empty);
+ }
+
+}
diff --git a/tests/unit/template_test.php b/tests/unit/template_test.php
index 1f9f80531..dfaecb4a1 100644
--- a/tests/unit/template_test.php
+++ b/tests/unit/template_test.php
@@ -25,12 +25,6 @@ function x($s,$k = NULL) {
}
}
-if(!function_exists('get_app')) {
-function get_app() {
- return new TemplateMockApp();
-}
-}
-
/**
* TestCase for the template engine
*