From 33153b8f3a2e4974ae5b1e9f4017f669e35207fe Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 22 Oct 2016 22:43:25 +0200 Subject: [FEATURE] :construction_worker: Extend Travis CI integration. Testing several Travis CI features. Add DBs to travis execution matrix. Doxygen API docu generation and deployment to gh-pages. Update phpunit to 5.7. --- tests/phpunit-mariadb.xml | 1 + tests/phpunit-mysql.xml | 37 +++++++++++++++++++ tests/phpunit-pgsql.xml | 34 +++++++++++++++++ tests/travis/gen_apidocs.sh | 86 +++++++++++++++++++++++++++++++++++++++++++ tests/travis/prepare.sh | 35 ++++++++++++++++++ tests/travis/prepare_mysql.sh | 37 +++++++++++++++++++ tests/travis/prepare_pgsql.sh | 37 +++++++++++++++++++ 7 files changed, 267 insertions(+) create mode 120000 tests/phpunit-mariadb.xml create mode 100644 tests/phpunit-mysql.xml create mode 100644 tests/phpunit-pgsql.xml create mode 100755 tests/travis/gen_apidocs.sh create mode 100755 tests/travis/prepare.sh create mode 100755 tests/travis/prepare_mysql.sh create mode 100755 tests/travis/prepare_pgsql.sh (limited to 'tests') diff --git a/tests/phpunit-mariadb.xml b/tests/phpunit-mariadb.xml new file mode 120000 index 000000000..63656b78b --- /dev/null +++ b/tests/phpunit-mariadb.xml @@ -0,0 +1 @@ +phpunit-mysql.xml \ No newline at end of file diff --git a/tests/phpunit-mysql.xml b/tests/phpunit-mysql.xml new file mode 100644 index 000000000..b421d7a7b --- /dev/null +++ b/tests/phpunit-mysql.xml @@ -0,0 +1,37 @@ + + + + ./unit/ + + + ./unit/ + + + ./unit/eximport/ + + + + postgresql + + + + + + ../Zotlabs/ + ../include/ + + + + + + + diff --git a/tests/phpunit-pgsql.xml b/tests/phpunit-pgsql.xml new file mode 100644 index 000000000..f59dd05ad --- /dev/null +++ b/tests/phpunit-pgsql.xml @@ -0,0 +1,34 @@ + + + + ./unit/ + + + ./unit/ + + + + mysql + + + + + + ../Zotlabs/ + ../include/ + + + + + + + diff --git a/tests/travis/gen_apidocs.sh b/tests/travis/gen_apidocs.sh new file mode 100755 index 000000000..dc25347c6 --- /dev/null +++ b/tests/travis/gen_apidocs.sh @@ -0,0 +1,86 @@ +#!/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 + +# @TODO get newer doxygen +echo "Doxygen version 1.7 is too old for us :(" +doxygen --version + +# Only build API documentation for master branch push +if [[ "$TRAVIS_EVENT_TYPE" != "push" ]] || [[ "$TRAVIS_BRANCH" != "master" ]]; then + echo "Conditions not met to build API documentation." + echo "We are finished ..." + exit +fi + +echo "Generating Doxygen API documentation for master ..." + +cd $TRAVIS_BUILD_DIR +mkdir -p ./doc/html + +# Redirect stderr and stdout to log file and console +doxygen $DOXYFILE 2>&1 | tee ./doc/html/doxygen.log + +# Check if GitHub token is configured in Travis to be able to push to the repo +if [ -z "$GHP_TOKEN" ]; then + echo "No GitHub token configured in Travis, can not deploy to gh-pages ..." + echo "Add Environment Variable 'GHP_TOKEN' in Travis CI project settings" + echo "with a 'Personal access token' from GitHub with 'repo:public_repo'." + exit +fi + +# Upload the API documentation to the gh-pages branch of the GitHub repository. +# Only upload if Doxygen successfully created the documentation. +if [ -d "doc/html" ] && [ -f "doc/html/index.html" ]; then + echo "Uploading API documentation to the gh-pages branch ..." + + # Add the new API documentation as a Git commit + cd ./doc/html + + # Create and configure a new git repo for committing to gh-pages + git init + # Add a fake Travis CI user + git config user.name "Travis CI" + git config user.email "travis@travis-ci.org" + # Add the generated API documentation + git add --all + git commit -q -m "API documentation generated by Travis build: ${TRAVIS_BUILD_NUMBER}" -m "From commit: ${TRAVIS_COMMIT}" + + # No need for a history, force push to the remote gh-pages branch + git push -f "https://${GHP_TOKEN}@${GHP_REPO_REF}" master:gh-pages > /dev/null 2>&1 +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..96a562ac3 --- /dev/null +++ b/tests/travis/prepare_mysql.sh @@ -0,0 +1,37 @@ +#!/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 ..." + +# Print out some MySQL information +mysql --version +mysql -e "SELECT VERSION();" +mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';" +mysql -e "SELECT @@sql_mode;" + +# Create Hubzilla database +mysql -e "CREATE DATABASE IF NOT EXISTS hubzilla;" -uroot; diff --git a/tests/travis/prepare_pgsql.sh b/tests/travis/prepare_pgsql.sh new file mode 100755 index 000000000..64c3524e7 --- /dev/null +++ b/tests/travis/prepare_pgsql.sh @@ -0,0 +1,37 @@ +#!/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 -c "SELECT VERSION();" -U postgres + +# Create Hubzilla database +psql -c "DROP DATABASE IF EXISTS hubzilla;" -U postgres +psql -c "CREATE DATABASE hubzilla;" -U postgres -- cgit v1.2.3 From 03db9833e833959bb2414b736fddb967763d0d4f Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 6 Nov 2016 21:31:02 +0100 Subject: :green_heart: Update Travis CI's Doxygen. Travis CI has Doxygen 1.7. We need 1.8 to generate our API documentation. Get a static version and use it. Always build API Documentation, but changed Doxygen configuration to only print out errors in the documentation generation, so these can be reviewed. --- tests/travis/gen_apidocs.sh | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/travis/gen_apidocs.sh b/tests/travis/gen_apidocs.sh index dc25347c6..248818117 100755 --- a/tests/travis/gen_apidocs.sh +++ b/tests/travis/gen_apidocs.sh @@ -34,25 +34,42 @@ if [[ "$TRAVIS_JOB_NUMBER" != "${TRAVIS_BUILD_NUMBER}.1" ]]; then exit fi -# @TODO get newer doxygen -echo "Doxygen version 1.7 is too old for us :(" -doxygen --version +# Get newer Doxygen +#echo "Doxygen version 1.7 is too old for us :(" +#doxygen --version -# Only build API documentation for master branch push -if [[ "$TRAVIS_EVENT_TYPE" != "push" ]] || [[ "$TRAVIS_BRANCH" != "master" ]]; then - echo "Conditions not met to build API documentation." - echo "We are finished ..." - exit +# Travis CI has an old Doxygen 1.7 build, so we fetch a recent static binary +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=$PATH:$DOXY_BINPATH fi +echo "Doxygen version" +doxygen --version -echo "Generating Doxygen API documentation for master ..." - +echo "Generating Doxygen API documentation ..." cd $TRAVIS_BUILD_DIR mkdir -p ./doc/html - -# Redirect stderr and stdout to log file and console +# 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 + +# There is no sane way yet, to prevent missuse of the push tokens in our workflow. +# We would need a way to limit a token to only push to gh-pages or a way to prevent +# manipulations to travis scripts which is not possible because we want it to run +# for pull requests. +# There are protected branches in GitHub, but they do not work for forced pushes. +exit + +# Only continue for master branch pushes +if [[ "$TRAVIS_EVENT_TYPE" != "push" ]] || [[ "$TRAVIS_BRANCH" != "master" ]]; then + echo "Conditions not met to build API documentation." + echo "We are finished ..." +# exit +fi + # Check if GitHub token is configured in Travis to be able to push to the repo if [ -z "$GHP_TOKEN" ]; then echo "No GitHub token configured in Travis, can not deploy to gh-pages ..." -- cgit v1.2.3 From 8e80500ee68972eef7d9c004823d1a547270334f Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 5 Dec 2016 20:23:59 +0100 Subject: :construction_worker: use PHP7.1 and add PostgreSQL9.6 Use newer distro for Travis CI runs. New environment provides PostgreSQL9.6. Also no need to install custom Doxygen, made it optional. Changed default PHP environment from PHP7.0 to current PHP7.1. Changed codecoverage reporting. --- tests/travis/gen_apidocs.sh | 25 +++++++++++++------------ tests/travis/prepare_pgsql.sh | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'tests') diff --git a/tests/travis/gen_apidocs.sh b/tests/travis/gen_apidocs.sh index 248818117..ed5e429fa 100755 --- a/tests/travis/gen_apidocs.sh +++ b/tests/travis/gen_apidocs.sh @@ -34,20 +34,21 @@ if [[ "$TRAVIS_JOB_NUMBER" != "${TRAVIS_BUILD_NUMBER}.1" ]]; then exit fi -# Get newer Doxygen -#echo "Doxygen version 1.7 is too old for us :(" -#doxygen --version +echo "Doxygen version >= 1.8 is required" +doxygen --version -# Travis CI has an old Doxygen 1.7 build, so we fetch a recent static binary -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=$PATH:$DOXY_BINPATH +# 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 "Doxygen version" -doxygen --version echo "Generating Doxygen API documentation ..." cd $TRAVIS_BUILD_DIR diff --git a/tests/travis/prepare_pgsql.sh b/tests/travis/prepare_pgsql.sh index 64c3524e7..dcd83f3be 100755 --- a/tests/travis/prepare_pgsql.sh +++ b/tests/travis/prepare_pgsql.sh @@ -30,7 +30,7 @@ echo "Preparing for PostgreSQL ..." # Print out some PostgreSQL information psql --version # Why does this hang further execution of the job? -#psql -c "SELECT VERSION();" -U postgres +psql -c "SELECT VERSION();" -U postgres # Create Hubzilla database psql -c "DROP DATABASE IF EXISTS hubzilla;" -U postgres -- cgit v1.2.3 From cb2eee1d2e82be62118482fb2668561c193a012b Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Fri, 27 Jan 2017 21:56:21 +0100 Subject: :construction_worker: Add old MySQL 5.5 to Travis CI again. The trusty distro contains MySQL 5.6. Add a precise distro with MySQL 5.5. Unfortunately 5.7 is not yet provided, which would be interesting because of the enabled strict SQL mode. --- tests/phpunit-mysql.xml | 2 +- tests/travis/prepare_mysql.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/phpunit-mysql.xml b/tests/phpunit-mysql.xml index b421d7a7b..9ba40f087 100644 --- a/tests/phpunit-mysql.xml +++ b/tests/phpunit-mysql.xml @@ -6,7 +6,7 @@ beStrictAboutOutputDuringTests="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutTodoAnnotatedTests="true" - processIsolation="true" + processIsolation="false" verbose="true"> ./unit/ diff --git a/tests/travis/prepare_mysql.sh b/tests/travis/prepare_mysql.sh index 96a562ac3..92c720205 100755 --- a/tests/travis/prepare_mysql.sh +++ b/tests/travis/prepare_mysql.sh @@ -31,6 +31,8 @@ echo "Preparing for MySQL ..." mysql --version mysql -e "SELECT VERSION();" mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';" +mysql -e "SHOW VARIABLES LIKE 'collation_%';" +mysql -e "SHOW VARIABLES LIKE 'character_set%';" mysql -e "SELECT @@sql_mode;" # Create Hubzilla database -- cgit v1.2.3 From 4a85726e5583e7de497077ded4e2ffbcd8b8a0b9 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 5 Feb 2017 01:38:12 +0100 Subject: :construction_worker: :arrow_up: :heavy_plus_sign: Update PHPUnit to current stable 6. Update requirements to PHP7 for dev. Add php-mock-phpunit to mock and stub global functions in a better way. --- tests/phpunit-mysql.xml | 12 +-- tests/phpunit-pgsql.xml | 12 +-- tests/unit/Lib/PermissionDescriptionTest.php | 129 ++++++++++++--------------- 3 files changed, 69 insertions(+), 84 deletions(-) (limited to 'tests') diff --git a/tests/phpunit-mysql.xml b/tests/phpunit-mysql.xml index 9ba40f087..171211094 100644 --- a/tests/phpunit-mysql.xml +++ b/tests/phpunit-mysql.xml @@ -1,12 +1,11 @@ ./unit/ @@ -31,7 +30,8 @@ - + + diff --git a/tests/phpunit-pgsql.xml b/tests/phpunit-pgsql.xml index f59dd05ad..ace14e196 100644 --- a/tests/phpunit-pgsql.xml +++ b/tests/phpunit-pgsql.xml @@ -1,12 +1,11 @@ ./unit/ @@ -28,7 +27,8 @@ - + + diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php index b1da5a0fd..97a39a2c8 100644 --- a/tests/unit/Lib/PermissionDescriptionTest.php +++ b/tests/unit/Lib/PermissionDescriptionTest.php @@ -1,6 +1,6 @@ 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'); } } -- cgit v1.2.3 From 5c080ca4e84d9c516d229b8a1248ad5aecf2fe0f Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Fri, 10 Mar 2017 01:01:35 +0100 Subject: :construction_worker: Add Travis' GitHub deployment steps. Changed API documentation deployment to gh_pages to Travis's GitHub Pages deployment. Also add Travis GitHub Release Deployment step to offer API documentation. Both steps are optional and need to be activated in Travis by setting GH_TOKEN. --- tests/travis/gen_apidocs.sh | 47 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) (limited to 'tests') diff --git a/tests/travis/gen_apidocs.sh b/tests/travis/gen_apidocs.sh index ed5e429fa..e5938e1e8 100755 --- a/tests/travis/gen_apidocs.sh +++ b/tests/travis/gen_apidocs.sh @@ -56,48 +56,13 @@ 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 - -# There is no sane way yet, to prevent missuse of the push tokens in our workflow. -# We would need a way to limit a token to only push to gh-pages or a way to prevent -# manipulations to travis scripts which is not possible because we want it to run -# for pull requests. -# There are protected branches in GitHub, but they do not work for forced pushes. -exit - -# Only continue for master branch pushes -if [[ "$TRAVIS_EVENT_TYPE" != "push" ]] || [[ "$TRAVIS_BRANCH" != "master" ]]; then - echo "Conditions not met to build API documentation." - echo "We are finished ..." -# exit -fi - -# Check if GitHub token is configured in Travis to be able to push to the repo -if [ -z "$GHP_TOKEN" ]; then - echo "No GitHub token configured in Travis, can not deploy to gh-pages ..." - echo "Add Environment Variable 'GHP_TOKEN' in Travis CI project settings" - echo "with a 'Personal access token' from GitHub with 'repo:public_repo'." - exit -fi - -# Upload the API documentation to the gh-pages branch of the GitHub repository. -# Only upload if Doxygen successfully created the documentation. +# Check if Doxygen successfully created the documentation if [ -d "doc/html" ] && [ -f "doc/html/index.html" ]; then - echo "Uploading API documentation to the gh-pages branch ..." - - # Add the new API documentation as a Git commit - cd ./doc/html - - # Create and configure a new git repo for committing to gh-pages - git init - # Add a fake Travis CI user - git config user.name "Travis CI" - git config user.email "travis@travis-ci.org" - # Add the generated API documentation - git add --all - git commit -q -m "API documentation generated by Travis build: ${TRAVIS_BUILD_NUMBER}" -m "From commit: ${TRAVIS_COMMIT}" - - # No need for a history, force push to the remote gh-pages branch - git push -f "https://${GHP_TOKEN}@${GHP_REPO_REF}" master:gh-pages > /dev/null 2>&1 + 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 -- cgit v1.2.3 From d4bd4ca000c2d099406300ea74ea4027a5cd0ec7 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 19 Mar 2017 23:00:09 +0100 Subject: :white_check_mark: Add unit test for purify_html(). In preparation to update HTMLPurifier library add a unit test. Please add more HTML that you need to have working and we can check against regressions. --- tests/unit/TextTest.php | 33 --------------------------------- tests/unit/includes/TextTest.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 33 deletions(-) delete mode 100644 tests/unit/TextTest.php create mode 100644 tests/unit/includes/TextTest.php (limited to 'tests') 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 @@ -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/TextTest.php b/tests/unit/includes/TextTest.php new file mode 100644 index 000000000..2b4cb19ea --- /dev/null +++ b/tests/unit/includes/TextTest.php @@ -0,0 +1,37 @@ +assertTrue(valid_email_regex('ken@spaz.org')); + $this->assertTrue(valid_email_regex('ken@restivo.org')); + $this->assertTrue(valid_email_regex('nobody@hubzilla.org')); + $this->assertTrue(valid_email_regex('foo+nobody@hubzilla.org')); + } + + public function testBadEmail() { + $this->assertFalse(valid_email_regex('nobody!uses!these!any.more')); + $this->assertFalse(valid_email_regex('foo@bar@hubzilla.org')); + } + + public function testPurifyHTML() { + $html = '

text
b

'; + $html_expect = '

text
b

'; + $html5elements = '
section
footer
'; + $htmldata = '
text
'; + + $this->assertEquals($html_expect, purify_html($html)); + $this->assertEquals($html5elements, purify_html($html5elements)); + $this->assertEquals($htmldata, purify_html($htmldata)); + } +} + -- cgit v1.2.3 From 30a3339653007be1d562c6d21ed9b569c716ab0f Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 21 Mar 2017 00:13:43 +0100 Subject: :white_check_mark: Some more tests for purify_html(). Add some generic HTML, JS, CSS expectations for purify_html(). Also cover our own configuration for HTMLPurifier. --- tests/unit/includes/TextTest.php | 57 ++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index 2b4cb19ea..85ed6a4fd 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -5,7 +5,7 @@ namespace Zotlabs\Tests\Unit\includes; use Zotlabs\Tests\Unit\UnitTestCase; /** - * @brief Unit Test case for texter. + * @brief Unit Test case for include/texter.php file. * * @author ken restivo */ @@ -24,14 +24,55 @@ class TextTest extends UnitTestCase { } public function testPurifyHTML() { - $html = '

text
b

'; - $html_expect = '

text
b

'; - $html5elements = '
section
footer
'; - $htmldata = '
text
'; + // linebreaks + $htmlbr = 'first line
+ one tab preserved + +empty line above'; + $this->assertEquals($htmlbr, purify_html($htmlbr)); - $this->assertEquals($html_expect, purify_html($html)); + // HTML5 is not supported by HTMLPurifier yet, test our own configuration + $html5elements = '
section
footer
'; $this->assertEquals($html5elements, purify_html($html5elements)); - $this->assertEquals($htmldata, purify_html($htmldata)); + $this->assertEquals('', purify_html('')); + + // preserve f6 and bootstrap additional data attributes from our own configuration + $this->assertEquals('
text
', purify_html('
text
')); + $this->assertEquals('
  • item1
', purify_html('
  • item1
')); + $this->assertEquals('
  • item1
', purify_html('
  • item1
')); + } + + public function testPurifyHTML_html() { + $this->assertEquals('

ids und classes

', purify_html('

ids und classes

')); + $this->assertEquals('

close missing tags

', purify_html('

close missing tags')); + $this->assertEquals('

deprecated tag
', purify_html('
deprecated tag
')); + $this->assertEquals('
illegal nesting
', purify_html('
illegal nesting
')); + $this->assertEquals('link with target', purify_html('link with target')); + $this->assertEquals('link with rel="nofollow"', purify_html('link with rel="nofollow"')); + $this->assertEquals('a b', purify_html('a b')); + $this->assertEquals('ä ä € €', purify_html('ä ä € €')); } -} + public function testPurifyHTML_js() { + $this->assertEquals('
', purify_html('
')); + $this->assertEquals('link', purify_html('link')); + $this->assertEquals('', purify_html('')); + $this->assertEquals('', purify_html('')); + } + + public function testPurifyHTML_css() { + $this->assertEquals('

red

', purify_html('

red

')); + $this->assertEquals('

invalid color

', purify_html('

invalid color

')); + $this->assertEquals('

invalid style

', purify_html('

invalid style

')); + + // test our own CSS configuration + $this->assertEquals('
position removed
', purify_html('
position removed
')); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + + $this->assertEquals('
position removed
', purify_html('
position removed
')); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + } + +} -- cgit v1.2.3 From f718e2b0db0fe3477212a8dd6c3ec067f4432862 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 18 Mar 2017 17:50:05 +0100 Subject: :arrow_up: Update HTML Purifier library. Updated HTML Purifier from 4.6.0 to 4.9.2 with better PHP7 compatibility. Used composer to manage this library. --- tests/unit/includes/TextTest.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index 85ed6a4fd..e2c7cbb9a 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -36,6 +36,10 @@ empty line above'; $this->assertEquals($html5elements, purify_html($html5elements)); $this->assertEquals('', purify_html('')); + // unsupported HTML5 elements + $this->assertEquals('Your HTML parser does not support HTML5 video.', purify_html('')); + $this->assertEquals('Your HTML parser does not support HTML5 audio.', purify_html('')); + // preserve f6 and bootstrap additional data attributes from our own configuration $this->assertEquals('
text
', purify_html('
text
')); $this->assertEquals('
  • item1
', purify_html('
  • item1
')); @@ -51,6 +55,8 @@ empty line above'; $this->assertEquals('link with rel="nofollow"', purify_html('link with rel="nofollow"')); $this->assertEquals('a b', purify_html('a b')); $this->assertEquals('ä ä € €', purify_html('ä ä € €')); + $this->assertEquals('text', purify_html('text')); + $this->assertEquals('', purify_html('')); } public function testPurifyHTML_js() { -- cgit v1.2.3 From c20aa6062c38d81d19d53bad3a65f78e95b126c9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 28 Mar 2017 16:02:47 -0700 Subject: get rid of get_app() --- tests/unit/template_test.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') 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 * -- cgit v1.2.3 From b6459e617289f729da1372b40f5a35940943f36d Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Mon, 3 Apr 2017 22:08:32 +0200 Subject: :arrow_up: Update SimplePie library. As a follow up to issue #699 update SimplePie from 1.2.1-dev (around 6years old) to current git master (1.4.4-dev). We use the master branch until the next release because it contains our patch for enclosure titles already. The other patches in the library from us can be done by configuring the SimplePie object in our code instead. Used composer to manage this library and use class autoloading. Add some unit tests for include/feedutils.php, but the interesting parts are unfortunately not testable with the current code. --- tests/unit/includes/FeedutilsText.php | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/unit/includes/FeedutilsText.php (limited to 'tests') diff --git a/tests/unit/includes/FeedutilsText.php b/tests/unit/includes/FeedutilsText.php new file mode 100644 index 000000000..e3eaa91a7 --- /dev/null +++ b/tests/unit/includes/FeedutilsText.php @@ -0,0 +1,52 @@ +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' + ]]]; + $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' + }*/ + + public function test_atom_author() { + $this->assertEquals('', atom_author('', 'name', 'uri', 72, 72, 'png', 'photourl')); + + $a = ' + name + uri + + +'; + + $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'name', 'uri', 72, 72, 'png', 'http://photourl')); + } +} -- cgit v1.2.3 From ab32372f8fa8bd2e831a907ce5f1232b84a8d083 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 27 Apr 2017 16:50:37 -0700 Subject: update feedutils with as:author changes, also update tests --- tests/unit/includes/FeedutilsText.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/unit/includes/FeedutilsText.php b/tests/unit/includes/FeedutilsText.php index e3eaa91a7..932a1b3a1 100644 --- a/tests/unit/includes/FeedutilsText.php +++ b/tests/unit/includes/FeedutilsText.php @@ -38,15 +38,18 @@ class FeedutilsTest extends UnitTestCase { }*/ public function test_atom_author() { - $this->assertEquals('', atom_author('', 'name', 'uri', 72, 72, 'png', 'photourl')); + $this->assertEquals('', atom_author('', 'nick', 'name', 'uri', 72, 72, 'png', 'photourl')); $a = ' - name + uri + nick uri + nick + name '; - $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'name', 'uri', 72, 72, 'png', 'http://photourl')); + $this->assertXmlStringEqualsXmlString($a, atom_author('tag', 'nick', 'name', 'uri', 72, 72, 'png', 'http://photourl')); } } -- cgit v1.2.3 From 8f0a0add1e5edca5306cb1ca22e1f582b1907ff9 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 25 Apr 2017 23:33:44 +0200 Subject: :white_check_mark::bulb: Add Unit Tests for AccessList class. Also some Doxygen docu for this class. --- tests/unit/Access/AccessListTest.php | 189 +++++++++++++++++++++++++++ tests/unit/Lib/PermissionDescriptionTest.php | 2 + 2 files changed, 191 insertions(+) create mode 100644 tests/unit/Access/AccessListTest.php (limited to 'tests') diff --git a/tests/unit/Access/AccessListTest.php b/tests/unit/Access/AccessListTest.php new file mode 100644 index 000000000..3dbe5cd65 --- /dev/null +++ b/tests/unit/Access/AccessListTest.php @@ -0,0 +1,189 @@ + '', + 'allow_gid' => '', + 'deny_cid' => '', + 'deny_gid' => '' + ]; + + + + public function testConstructor() { + $channel = [ + 'channel_allow_cid' => '', + 'channel_allow_gid' => '', + 'channel_deny_cid' => '', + 'channel_deny_gid' => '' + ]; + + $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' => '', + 'allow_gid' => '', + 'deny_cid' => '', + 'deny_gid' => '' + ]; + $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() + */ + 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' => '', + 'channel_allow_gid' => '', + 'channel_deny_cid' => '', + 'channel_deny_gid' => '' + ]], + 'only one set' => [[ + 'channel_allow_cid' => '', + 'channel_allow_gid' => '', + 'channel_deny_cid' => '', + 'channel_deny_gid' => '' + ]], + 'acid+null' => [[ + 'channel_allow_cid' => '', + 'channel_allow_gid' => null, + 'channel_deny_cid' => '', + 'channel_deny_gid' => '' + ]] + ]; + } + +} \ No newline at end of file diff --git a/tests/unit/Lib/PermissionDescriptionTest.php b/tests/unit/Lib/PermissionDescriptionTest.php index 97a39a2c8..96c381d0c 100644 --- a/tests/unit/Lib/PermissionDescriptionTest.php +++ b/tests/unit/Lib/PermissionDescriptionTest.php @@ -29,6 +29,8 @@ use Zotlabs\Lib\PermissionDescription; /** * @brief Unit Test case for PermissionDescription class. + * + * @covers Zotlabs\Lib\PermissionDescription */ class PermissionDescriptionTest extends UnitTestCase { -- cgit v1.2.3 From b7df4de4b751203f43ccf73ca88a2ac3b6c39729 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Fri, 5 May 2017 23:13:54 +0200 Subject: :construction_worker::white_check_mark::bug: Import table structure in TravisCI. Fix a syntax error in schema_postres.sql which was discovered while working on this. --- tests/travis/prepare_mysql.sh | 11 ++++++++++- tests/travis/prepare_pgsql.sh | 13 ++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/travis/prepare_mysql.sh b/tests/travis/prepare_mysql.sh index 92c720205..b3d84253c 100755 --- a/tests/travis/prepare_mysql.sh +++ b/tests/travis/prepare_mysql.sh @@ -36,4 +36,13 @@ mysql -e "SHOW VARIABLES LIKE 'character_set%';" mysql -e "SELECT @@sql_mode;" # Create Hubzilla database -mysql -e "CREATE DATABASE IF NOT EXISTS hubzilla;" -uroot; +mysql -u root -e "CREATE DATABASE IF NOT EXISTS hubzilla;"; +mysql -u root -e "CREATE USER 'hubzilla'@'localhost' IDENTIFIED BY 'hubzilla';" +mysql -u root -e "GRANT ALL ON hubzilla.* TO 'hubzilla'@'localhost';" + +# Import table structure +mysql -u root hubzilla < ./install/schema_mysql.sql + +# Show databases and tables +mysql -u root -e "SHOW DATABASES;" +mysql -u root -e "USE hubzilla; SHOW TABLES;" diff --git a/tests/travis/prepare_pgsql.sh b/tests/travis/prepare_pgsql.sh index dcd83f3be..63c7388cb 100755 --- a/tests/travis/prepare_pgsql.sh +++ b/tests/travis/prepare_pgsql.sh @@ -30,8 +30,15 @@ echo "Preparing for PostgreSQL ..." # Print out some PostgreSQL information psql --version # Why does this hang further execution of the job? -psql -c "SELECT VERSION();" -U postgres +psql -U postgres -c "SELECT VERSION();" # Create Hubzilla database -psql -c "DROP DATABASE IF EXISTS hubzilla;" -U postgres -psql -c "CREATE DATABASE hubzilla;" -U postgres +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;" -- cgit v1.2.3