Skip to content
Permalink
Browse files

Import unit-tests inside the main repo (#2326)

Import unit-tests inside the main repo

Co-authored-by: ྅༻ Ǭɀħ ༄༆ཉ <ozh@ozh.org>
  • Loading branch information...
LeoColomb and ozh committed Sep 21, 2019
2 parents 858d6ab + d764480 commit b8f2eaab138a7f4fc37ec8b7b6cb0c3899567696
Showing with 5,458 additions and 24 deletions.
  1. +2 −0 .gitattributes
  2. +9 −6 .gitignore
  3. +5 −18 .travis.yml
  4. +39 −0 phpunit-travis.xml.dist
  5. +48 −0 phpunit.xml.dist
  6. +55 −0 tests/bootstrap.php
  7. +5 −0 tests/composer.json
  8. +12 −0 tests/data/auth/config-test-auth.php
  9. +50 −0 tests/data/config/yourls-tests-config-sample.php
  10. +65 −0 tests/data/config/yourls-tests-config-travis.php
  11. +5 −0 tests/data/formatting/big5.txt
  12. +5 −0 tests/data/formatting/utf-8.txt
  13. +8 −0 tests/data/htaccess/expected_empty.txt
  14. +6 −0 tests/data/htaccess/expected_fresh-YOURLS-content.txt
  15. +8 −0 tests/data/htaccess/expected_nofile.txt
  16. +6 −0 tests/data/htaccess/expected_old-YOURLS-content.txt
  17. +12 −0 tests/data/htaccess/expected_other-content.txt
  18. 0 tests/data/htaccess/original_empty.txt
  19. +10 −0 tests/data/htaccess/original_fresh-YOURLS-content.txt
  20. +5 −0 tests/data/htaccess/original_old-YOURLS-content.txt
  21. +4 −0 tests/data/htaccess/original_other-content.txt
  22. BIN tests/data/pomo/fr_FR.mo
  23. +71 −0 tests/data/pomo/fr_FR.po
  24. BIN tests/data/pomo/test-fr_FR.mo
  25. +56 −0 tests/data/pomo/test-fr_FR.po
  26. +65 −0 tests/includes/install.php
  27. +117 −0 tests/includes/utils.php
  28. +23 −0 tests/tests/TODO.md
  29. +37 −0 tests/tests/api/funcs.php
  30. +104 −0 tests/tests/api/output.php
  31. +218 −0 tests/tests/auth/auth.php
  32. +22 −0 tests/tests/auth/login_API.php
  33. +95 −0 tests/tests/auth/login_base.php
  34. +14 −0 tests/tests/auth/login_normal.php
  35. +27 −0 tests/tests/auth/login_secure.php
  36. +29 −0 tests/tests/auth/login_secure_time.php
  37. +93 −0 tests/tests/auth/signatures.php
  38. +36 −0 tests/tests/db/db.php
  39. +16 −0 tests/tests/db/misc.php
  40. +234 −0 tests/tests/format/escaping.php
  41. +286 −0 tests/tests/format/general.php
  42. +46 −0 tests/tests/format/kses.php
  43. +200 −0 tests/tests/format/sanitizing.php
  44. +184 −0 tests/tests/format/urls.php
  45. +87 −0 tests/tests/geoip/geoip.php
  46. +221 −0 tests/tests/http/api-check.php
  47. +64 −0 tests/tests/http/general.php
  48. +94 −0 tests/tests/http/headers.php
  49. +24 −0 tests/tests/http/misc.php
  50. +113 −0 tests/tests/http/proxy.php
  51. +66 −0 tests/tests/http/requests.php
  52. +102 −0 tests/tests/install/htaccess.php
  53. +135 −0 tests/tests/install/install.php
  54. +82 −0 tests/tests/install/version.php
  55. +68 −0 tests/tests/l10n/domain.php
  56. +115 −0 tests/tests/l10n/formats.php
  57. +66 −0 tests/tests/l10n/general.php
  58. +169 −0 tests/tests/l10n/translations.php
  59. +135 −0 tests/tests/options.php
  60. +495 −0 tests/tests/plugins/actions.php
  61. +131 −0 tests/tests/plugins/files.php
  62. +467 −0 tests/tests/plugins/filters.php
  63. +170 −0 tests/tests/plugins/misc.php
  64. +133 −0 tests/tests/shorturl/shorturl.php
  65. +15 −0 tests/tests/stats/misc.php
  66. +43 −0 tests/tests/themes/themes.php
  67. +94 −0 tests/tests/utilities/get_request.php
  68. +37 −0 tests/tests/utilities/next_decimal.php
@@ -9,3 +9,5 @@ assets/less/ export-ignore
.travis.yml export-ignore
/.git* export-ignore
/*.md export-ignore
tests/ export-ignore
/*.dist export-ignore
@@ -3,6 +3,7 @@
############

# Configuration
*config.php
user/*
!user/config-sample.php
.htaccess
@@ -11,11 +12,9 @@ user/*
[Rr]obots.txt

# Languages
user/languages/*
!user/languages/

# Plugins
user/plugins/*
# Core plugins
!user/plugins/hyphens-in-urls/
!user/plugins/random-bg/
@@ -29,14 +28,18 @@ pages/*

# Keep index.html
!user/index.html
!user/*/index.html
!user/**/index.html

############
## Tests
############

test*.php
tests/
includes/**/tests/
build/
coverage/
phpunit.xml
tests/vendor/
tests/data/auth/config-test-auth-hashed.php

############
## Environnement
@@ -52,4 +55,4 @@ Desktop.ini
.DS_Store

# NetBeans files
/nbproject/
/nbproject/
@@ -1,4 +1,3 @@
sudo: false
language: php

env:
@@ -19,29 +18,17 @@ matrix:
fast_finish: true
allow_failures:
- php: nightly

before_script:
- mysql --version
- git clone git://github.com/YOURLS/YOURLS-unit-tests.git tests
- |
# Use same branch in YOURLS and YOURLS-unit-tests
export CURRENT_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
echo "Current YOURLS branch: $CURRENT_BRANCH"
cd tests
if [ `git checkout $CURRENT_BRANCH &> /dev/null; echo $?` == 0 ]
then
echo "Using branch $CURRENT_BRANCH for Tests as well"
else
echo "Using branch master for Tests"
fi
composer install
cd ..
- git clone git://github.com/ozh/YOURLS-fr_FR.git user/languages/fr
- cp user/languages/fr/fr_FR.* user/languages
- mysql -e 'create database IF NOT EXISTS yourls_tests;'
- cp tests/yourls-tests-config-travis.php user/config.php
- cp tests/data/config/yourls-tests-config-travis.php user/config.php

install: composer install -d ./tests

script: tests/vendor/bin/phpunit --configuration ./tests/phpunit-travis.xml.dist
script: tests/vendor/bin/phpunit --configuration ./phpunit-travis.xml.dist

notifications:
email: false
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
colors="false"
stopOnFailure="false"
verbose="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="YOURLS Test Suite">
<directory suffix=".php">./tests/tests</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>ajax</group>
</exclude>
</groups>
<php>
<!-- Constants -->
<const name="PHPUNIT_TESTSUITE" value="true" />
<const name="TRAVIS_TESTSUITE" value="true" />
<!-- Login -->
<request name="username" value="yourls"/>
<request name="password" value="travis-ci-test"/>
<!-- Install -->
<server name="SERVER_SOFTWARE" value="TRAVIS APACHE"/>
<!-- Stats data -->
<server name="HTTP_USER_AGENT" value="Travis-CI (PHPUnit\3.7)"/>
<server name="HTTP_HOST" value="travis.com"/>
<server name="HTTP_CLIENT_IP" value="10.10.10.1"/>
<!-- API -->
<request name="format" value="simple"/>
</php>
<logging>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false" />
</logging>
</phpunit>
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
colors="false"
stopOnFailure="false"
verbose="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="YOURLS Test Suite">
<directory suffix=".php">./tests/tests</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>ajax</group>
</exclude>
</groups>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./includes</directory>
<exclude>
<directory suffix=".php">./includes/vendors</directory>
</exclude>
</whitelist>
</filter>
<php>
<!-- Constants -->
<const name="PHPUNIT_TESTSUITE" value="true" />
<const name="LOCAL_TESTSUITE" value="true" />
<!-- Login -->
<request name="username" value="yourls"/>
<request name="password" value="travis-ci-test"/>
<server name="REQUEST_URI" value="/"/>
<!-- Install -->
<server name="SERVER_SOFTWARE" value="TRAVIS APACHE"/>
<!-- Stats data -->
<server name="HTTP_USER_AGENT" value="Travis-CI (PHPUnit\3.7)"/>
<server name="HTTP_HOST" value="travis.com"/>
<server name="HTTP_CLIENT_IP" value="10.10.10.1"/>
<!-- API -->
<request name="format" value="simple"/>
</php>
<logging>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false" />
</logging>
</phpunit>
@@ -0,0 +1,55 @@
<?php
/**
* YOURLS Unit Test. No, I don't know what I'm doing.
*/
// Globalize some YOURLS variables because PHPUnit loads this inside a function
// See https://github.com/sebastianbergmann/phpunit/issues/325
// This has to be done before including any file
global $ydb, $yourls_user_passwords, $yourls_reserved_URL, // main object & config file
$yourls_filters, $yourls_actions, // used by plugin API
$yourls_locale, $yourls_l10n, $yourls_locale_formats, // used by L10N API
$yourls_allowedentitynames, $yourls_allowedprotocols; // used by KSES
require_once dirname( __FILE__ ) . '/includes/utils.php';
require_once dirname( __FILE__ ) . '/includes/install.php';
// Include relevant config file
define('YOURLS_CONFIGFILE', yut_find_config());
require_once YOURLS_CONFIGFILE;
// Bootstrap YOURLS
require_once YOURLS_ABSPATH . '/includes/vendor/autoload.php';
define('YOURLS_TESTDATA_DIR', dirname( __FILE__ ) . '/data');
define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
$config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
$config->define_core_constants();
// Define YOURLS actions upon new instance
$init = new \YOURLS\Config\InitDefaults;
$init->check_maintenance_mode = false;
$init->fix_request_uri = false;
$init->redirect_ssl = false;
$init->redirect_to_install = false;
$init->check_if_upgrade_needed = false;
$init->load_plugins = false; // do not attempt to load (no DB yet to store data), but do send the 'plugins_loaded' action (some code depend on it)
$init->get_all_options = false;
$init->check_new_version = false;
$init->include_auth_funcs = true;
$init->include_install_upgrade_funcs = true;
new \YOURLS\Config\Init($init);
// All set -- install
yut_install_yourls();
// PHPUnit 6 compatibility for previous versions
if ( class_exists( 'PHPUnit\Runner\Version' ) && version_compare( PHPUnit\Runner\Version::id(), '6.0', '>=' ) ) {
class_alias( 'PHPUnit\Framework\Assert', 'PHPUnit_Framework_Assert' );
class_alias( 'PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase' );
class_alias( 'PHPUnit\Framework\Error\Error', 'PHPUnit_Framework_Error' );
class_alias( 'PHPUnit\Framework\Error\Notice', 'PHPUnit_Framework_Error_Notice' );
class_alias( 'PHPUnit\Framework\Error\Warning', 'PHPUnit_Framework_Error_Warning' );
}
// At this point, tests will start
echo "YOURLS installed, starting PHPUnit\n\n";
@@ -0,0 +1,5 @@
{
"require": {
"phpunit/phpunit": "^5.7"
}
}
@@ -0,0 +1,12 @@
<?php
/** Test encrypting file with passwords containing special chars */
$yourls_user_passwords = array(
'string' => 'hello ozh',
'special' => 'lol .\+*?[^]$(){}=!<>|:-/@',
'1994' => '@$*',
'quote1' => '"ahah"',
'quote2' => "'ahah'",
'utf8fun' => 'أنا أحب النقانق',
);
@@ -0,0 +1,50 @@
<?php
/**
* YOURLS Config for local unit tests. Copy this file to yourls-test-config.php
*/
/*** YOURLS code base you want to test */
define( 'YOURLS_ABSPATH', '/home/you/yourls_directory' );
/*** URL of that YOURLS code base */
define( 'YOURLS_SITE', 'http://127.0.0.1/yourls_directory' );
/*** MySQL settings */
define( 'YOURLS_DB_USER', 'your DB username' );
define( 'YOURLS_DB_PASS', 'your DB password' );
define( 'YOURLS_DB_NAME', 'DB name for tests -- an empty one' ); // Must be an EMPTY DATABASE: everything will be erased
define( 'YOURLS_DB_HOST', 'localhost' );
/*** PHP binary - edit if the executable binary is not in system path and put full path ie 'c:/php/php.exe' */
define( 'YOURLS_PHP_BIN', 'php' );
/*** Most likely, don't edit anything else. Pretty much standard YOURLS config. */
define('YOURLS_HOURS_OFFSET', 5);
define('YOURLS_UNIQUE_URLS', true);
define('YOURLS_PRIVATE', true);
define('YOURLS_COOKIEKEY', 'I &hearts; unit tests');
define('YOURLS_URL_CONVERT', 62);
define('YOURLS_DB_PREFIX', 'yourls_');
define('YOURLS_FLOOD_DELAY_SECONDS', 0);
define('YOURLS_FLOOD_IP_WHITELIST', '');
define('YOURLS_NO_HASH_PASSWORD', true); // prevents rewriting config.php with encrypted passwords
define('YOURLS_LANG', 'fr_FR'); // locale of a sample translation file in the data dir
define('YOURLS_DEBUG', true);
$yourls_reserved_URL = array(
'porn', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
);
$yourls_user_passwords = array(
'yourls' => 'travis-ci-test',
'clear' => 'somepassword',
'md5' => 'md5:12373:e52e4488f79a740bd341f229e3c163c8', // password: '3cd6944201fa7bbc5e0fe852e36b1096' with md5 and salt
'phpass' => 'phpass:!2a!08!T1ptMlBSxu7g3odpbUXgd.9wbKvg8k7cJt.HbwSqUNrlLPudWnf/6', // password: '3cd6944201fa7bbc5e0fe852e36b1096' with PHPass
'phpass2' => 'phpass:$2a$08$gt2bnpfUyuCX3hrp0RPOieFR1RwBnLsMzpq/NvPXwCdV3LqI3RGYi', // password: also '3cd6944201fa7bbc5e0fe852e36b1096' but without YOURLS internal char substitution
'1994' => '@$*',
'special' => 'lol .\+*?[^]$(){}=!<>|:-/',
'quote1' => '"ahah"',
'quote2' => "'ahah'",
'utf8fun' => 'أنا أحب النقانق',
);
@@ -0,0 +1,65 @@
<?php
/**
* YOURLS Config for Travis (https://travis-ci.org/YOURLS/YOURLS)
*/
if (!defined('YOURLS_TESTS_CI') || YOURLS_TESTS_CI === false) {
define( 'YOURLS_TESTS_CI', true );
}
/*** Code base and URL of that code base */
if( $path = getenv( 'TRAVIS_REPO_SLUG' ) ) {
switch( $path ) {
case 'YOURLS/YOURLS':
define( 'YOURLS_ABSPATH', '/home/travis/build/YOURLS/YOURLS' );
break;
case 'YOURLS/YOURLS-unit-tests':
define( 'YOURLS_ABSPATH', '/home/travis/build/YOURLS/YOURLS-unit-tests/YOURLS' );
break;
default:
die( sprintf( 'Wrong repo: "%s"', $path ) );
}
} else {
die( 'Not in Travis' );
}
define( 'YOURLS_SITE', 'http://localhost/YOURLS' );
/*** MySQL settings */
define( 'YOURLS_DB_USER', 'root' );
define( 'YOURLS_DB_PASS', '' );
define( 'YOURLS_DB_NAME', 'yourls_tests' );
define( 'YOURLS_DB_HOST', 'localhost' );
/*** Site options */
define( 'YOURLS_PHP_BIN', 'php' );
/*** Standard YOURLS config. */
define('YOURLS_HOURS_OFFSET', 5);
define('YOURLS_UNIQUE_URLS', true);
define('YOURLS_PRIVATE', true);
define('YOURLS_COOKIEKEY', 'I &hearts; unit tests');
define('YOURLS_URL_CONVERT', 62);
define('YOURLS_DB_PREFIX', 'yourls_');
define('YOURLS_FLOOD_DELAY_SECONDS', 0);
define('YOURLS_FLOOD_IP_WHITELIST', '');
define('YOURLS_NO_HASH_PASSWORD', true); // prevents rewriting config.php with encrypted passwords
define('YOURLS_LANG', 'fr_FR'); // locale of a sample translation file in the data dir
define('YOURLS_DEBUG', true);
$yourls_reserved_URL = array(
'porn', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
);
$yourls_user_passwords = array(
'yourls' => 'travis-ci-test',
'clear' => 'somepassword',
'md5' => 'md5:12373:e52e4488f79a740bd341f229e3c163c8', // password: '3cd6944201fa7bbc5e0fe852e36b1096' with md5 and salt
'phpass' => 'phpass:!2a!08!T1ptMlBSxu7g3odpbUXgd.9wbKvg8k7cJt.HbwSqUNrlLPudWnf/6', // password: '3cd6944201fa7bbc5e0fe852e36b1096' with PHPass
'phpass2' => 'phpass:$2a$08$gt2bnpfUyuCX3hrp0RPOieFR1RwBnLsMzpq/NvPXwCdV3LqI3RGYi', // password: also '3cd6944201fa7bbc5e0fe852e36b1096' but without YOURLS internal char substitution
'1994' => '@$*',
'special' => 'lol .\+*?[^]$(){}=!<>|:-/',
'quote1' => '"ahah"',
'quote2' => "'ahah'",
'utf8fun' => 'أنا أحب النقانق',
);
@@ -0,0 +1,5 @@
����
����
���
�ʽ�
����
@@ -0,0 +1,5 @@
章子怡
François Truffaut
საქართველო
Björk Guðmundsdóttir
宮崎 駿
@@ -0,0 +1,8 @@


# BEGIN YOURLS
This is a test
Hello World
1,2... 1,2...
# END YOURLS

0 comments on commit b8f2eaa

Please sign in to comment.
You can’t perform that action at this time.