From 9f30c299ee93c15e4c2d24f8282201c73e4b6dbb Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Fri, 12 Jul 2019 16:31:14 +0100 Subject: [PATCH] [CORE] Make tests great gain --- composer.lock | 64 +-- ...e_left_curry.php => callableleftcurry.php} | 2 +- lib/common.php | 41 +- lib/event.php | 52 +-- lib/gnusocial.php | 39 +- lib/language.php | 51 ++- lib/plugin.php | 52 +-- lib/util.php | 4 +- phpunit.xml | 26 ++ tests/{ => Core}/ActivityGenerationTests.php | 153 ++++--- tests/{ => Core}/ActivityParseTests.php | 166 +++++--- tests/Core/CallableLeftCurryTest.php | 91 +++++ tests/{ => Core}/CommandInterperterTest.php | 45 ++- tests/Core/HashTagDetectionTests.php | 83 ++++ tests/Core/LocationTest.php | 124 ++++++ tests/Core/NicknameTest.php | 156 ++++++++ tests/Core/TagURITest.php | 59 +++ tests/Core/URLDetectionTest.php | 377 ++++++++++++++++++ tests/Core/UUIDTest.php | 58 +++ tests/{ => Core}/UserFeedParseTest.php | 51 ++- tests/{ => Core}/UserRightsTest.php | 41 +- tests/{ => Core}/XmppValidateTest.php | 106 +++-- tests/CurryTest.php | 72 ---- tests/HashTagDetectionTests.php | 63 --- tests/LocationTest.php | 89 ----- tests/{ => Media}/MediaFileTest.php | 47 ++- tests/{ => Media}/sample-uploads/image.gif | Bin tests/{ => Media}/sample-uploads/image.jpeg | Bin tests/{ => Media}/sample-uploads/image.jpg | Bin tests/{ => Media}/sample-uploads/image.png | Bin tests/{ => Media}/sample-uploads/office.pdf | Bin .../sample-uploads/presentation.odp | Bin .../sample-uploads/presentation.otp | Bin .../sample-uploads/presentation.pot | Bin .../sample-uploads/presentation.potm | Bin .../sample-uploads/presentation.ppt | Bin .../sample-uploads/presentation.pptx | Bin .../sample-uploads/spreadsheet.ods | Bin .../sample-uploads/spreadsheet.ots | Bin .../sample-uploads/spreadsheet.xls | Bin .../sample-uploads/spreadsheet.xlsx | Bin .../sample-uploads/spreadsheet.xlt | Bin tests/{ => Media}/sample-uploads/wordproc.doc | Bin .../{ => Media}/sample-uploads/wordproc.docx | Bin tests/{ => Media}/sample-uploads/wordproc.odt | Bin tests/{ => Media}/sample-uploads/wordproc.ott | Bin tests/{ => Media}/sample-uploads/wordproc.rtf | 0 tests/NicknameTest.php | 116 ------ tests/TagURITest.php | 37 -- tests/URLDetectionTest.php | 355 ----------------- tests/UUIDTest.php | 38 -- 51 files changed, 1507 insertions(+), 1151 deletions(-) rename lib/{callable_left_curry.php => callableleftcurry.php} (97%) create mode 100644 phpunit.xml rename tests/{ => Core}/ActivityGenerationTests.php (80%) rename tests/{ => Core}/ActivityParseTests.php (90%) create mode 100644 tests/Core/CallableLeftCurryTest.php rename tests/{ => Core}/CommandInterperterTest.php (79%) create mode 100644 tests/Core/HashTagDetectionTests.php create mode 100644 tests/Core/LocationTest.php create mode 100644 tests/Core/NicknameTest.php create mode 100644 tests/Core/TagURITest.php create mode 100644 tests/Core/URLDetectionTest.php create mode 100644 tests/Core/UUIDTest.php rename tests/{ => Core}/UserFeedParseTest.php (76%) rename tests/{ => Core}/UserRightsTest.php (52%) rename tests/{ => Core}/XmppValidateTest.php (72%) delete mode 100644 tests/CurryTest.php delete mode 100644 tests/HashTagDetectionTests.php delete mode 100644 tests/LocationTest.php rename tests/{ => Media}/MediaFileTest.php (68%) rename tests/{ => Media}/sample-uploads/image.gif (100%) rename tests/{ => Media}/sample-uploads/image.jpeg (100%) rename tests/{ => Media}/sample-uploads/image.jpg (100%) rename tests/{ => Media}/sample-uploads/image.png (100%) rename tests/{ => Media}/sample-uploads/office.pdf (100%) rename tests/{ => Media}/sample-uploads/presentation.odp (100%) rename tests/{ => Media}/sample-uploads/presentation.otp (100%) rename tests/{ => Media}/sample-uploads/presentation.pot (100%) rename tests/{ => Media}/sample-uploads/presentation.potm (100%) rename tests/{ => Media}/sample-uploads/presentation.ppt (100%) rename tests/{ => Media}/sample-uploads/presentation.pptx (100%) rename tests/{ => Media}/sample-uploads/spreadsheet.ods (100%) rename tests/{ => Media}/sample-uploads/spreadsheet.ots (100%) rename tests/{ => Media}/sample-uploads/spreadsheet.xls (100%) rename tests/{ => Media}/sample-uploads/spreadsheet.xlsx (100%) rename tests/{ => Media}/sample-uploads/spreadsheet.xlt (100%) rename tests/{ => Media}/sample-uploads/wordproc.doc (100%) rename tests/{ => Media}/sample-uploads/wordproc.docx (100%) rename tests/{ => Media}/sample-uploads/wordproc.odt (100%) rename tests/{ => Media}/sample-uploads/wordproc.ott (100%) rename tests/{ => Media}/sample-uploads/wordproc.rtf (100%) delete mode 100644 tests/NicknameTest.php delete mode 100644 tests/TagURITest.php delete mode 100644 tests/URLDetectionTest.php delete mode 100644 tests/UUIDTest.php diff --git a/composer.lock b/composer.lock index 5d4ab05e8f..d624005f05 100644 --- a/composer.lock +++ b/composer.lock @@ -2125,16 +2125,16 @@ }, { "name": "jms/serializer", - "version": "3.0.1", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/schmittjoh/serializer.git", - "reference": "bf2bae374e565f443fc01fe60695061366bd3261" + "reference": "7f8dc86e9168d0112b3cc38ba8cca41b17f409a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/bf2bae374e565f443fc01fe60695061366bd3261", - "reference": "bf2bae374e565f443fc01fe60695061366bd3261", + "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/7f8dc86e9168d0112b3cc38ba8cca41b17f409a0", + "reference": "7f8dc86e9168d0112b3cc38ba8cca41b17f409a0", "shasum": "" }, "require": { @@ -2174,7 +2174,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -2205,7 +2205,7 @@ "serialization", "xml" ], - "time": "2019-04-23T17:53:59+00:00" + "time": "2019-06-28T09:09:40+00:00" }, { "name": "justinrainbow/json-schema", @@ -2930,16 +2930,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.5", + "version": "7.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff" + "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aed67b57d459dcab93e84a5c9703d3deb5025dff", - "reference": "aed67b57d459dcab93e84a5c9703d3deb5025dff", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d471d0d2b529a67c6a722dd446c4ec90881ac315", + "reference": "d471d0d2b529a67c6a722dd446c4ec90881ac315", "shasum": "" }, "require": { @@ -2948,17 +2948,17 @@ "php": "^7.2", "phpunit/php-file-iterator": "^2.0.2", "phpunit/php-text-template": "^1.2.1", - "phpunit/php-token-stream": "^3.0.1", + "phpunit/php-token-stream": "^3.0.2", "sebastian/code-unit-reverse-lookup": "^1.0.1", - "sebastian/environment": "^4.1", + "sebastian/environment": "^4.2.2", "sebastian/version": "^2.0.1", - "theseer/tokenizer": "^1.1" + "theseer/tokenizer": "^1.1.3" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.2.2" }, "suggest": { - "ext-xdebug": "^2.6.1" + "ext-xdebug": "^2.7.2" }, "type": "library", "extra": { @@ -2989,7 +2989,7 @@ "testing", "xunit" ], - "time": "2019-06-06T12:28:18+00:00" + "time": "2019-07-08T05:29:42+00:00" }, { "name": "phpunit/php-file-iterator", @@ -3133,16 +3133,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", - "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c", + "reference": "c4a66b97f040e3e20b3aa2a243230a1c3a9f7c8c", "shasum": "" }, "require": { @@ -3178,20 +3178,20 @@ "keywords": [ "tokenizer" ], - "time": "2018-10-30T05:52:18+00:00" + "time": "2019-07-08T05:24:54+00:00" }, { "name": "phpunit/phpunit", - "version": "8.2.3", + "version": "8.2.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f67ca36860ebca7224d4573f107f79bd8ed0ba03" + "reference": "25fe0b5031b24722f66a75ad479a074cccc1bb37" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f67ca36860ebca7224d4573f107f79bd8ed0ba03", - "reference": "f67ca36860ebca7224d4573f107f79bd8ed0ba03", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/25fe0b5031b24722f66a75ad479a074cccc1bb37", + "reference": "25fe0b5031b24722f66a75ad479a074cccc1bb37", "shasum": "" }, "require": { @@ -3218,7 +3218,7 @@ "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0.1", - "sebastian/type": "^1.1.0", + "sebastian/type": "^1.1.3", "sebastian/version": "^2.0.1" }, "require-dev": { @@ -3261,7 +3261,7 @@ "testing", "xunit" ], - "time": "2019-06-19T12:03:56+00:00" + "time": "2019-07-03T08:30:33+00:00" }, { "name": "pimple/pimple", @@ -4101,16 +4101,16 @@ }, { "name": "sebastian/type", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "251ca774d58181fe1d3eda68843264eaae7e07ef" + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/251ca774d58181fe1d3eda68843264eaae7e07ef", - "reference": "251ca774d58181fe1d3eda68843264eaae7e07ef", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/3aaaa15fa71d27650d62a948be022fe3b48541a3", + "reference": "3aaaa15fa71d27650d62a948be022fe3b48541a3", "shasum": "" }, "require": { @@ -4143,7 +4143,7 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", - "time": "2019-06-19T06:39:12+00:00" + "time": "2019-07-02T08:10:15+00:00" }, { "name": "sebastian/version", diff --git a/lib/callable_left_curry.php b/lib/callableleftcurry.php similarity index 97% rename from lib/callable_left_curry.php rename to lib/callableleftcurry.php index 37c9c1c18e..8ad2e61c27 100644 --- a/lib/callable_left_curry.php +++ b/lib/callableleftcurry.php @@ -25,7 +25,7 @@ * @param ... any remaining arguments will be appended to call-time params * @return callback */ -function callable_left_curry($fn) { +function callableLeftCurry($fn) { $extra_args = func_get_args(); array_shift($extra_args); return function() use ($fn, $extra_args) { diff --git a/lib/common.php b/lib/common.php index c31c45f626..4a74fb5e7f 100644 --- a/lib/common.php +++ b/lib/common.php @@ -1,25 +1,28 @@ . - */ +// This file is part of GNU social - https://www.gnu.org/software/social +// +// GNU social is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GNU social is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with GNU social. If not, see . -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +defined('GNUSOCIAL') || die(); -// All the fun stuff to actually initialize StatusNet's framework code, +/* Work internally in UTC */ +date_default_timezone_set('UTC'); + +/* Work internally with UTF-8 */ +mb_internal_encoding('UTF-8'); + +// All the fun stuff to actually initialize GNU social's framework code, // without loading up a site configuration. require_once INSTALLDIR . '/lib/framework.php'; diff --git a/lib/event.php b/lib/event.php index e6bb41091e..5ece77edf3 100644 --- a/lib/event.php +++ b/lib/event.php @@ -1,35 +1,20 @@ . - * - * @category Event - * @package StatusNet - * @author Evan Prodromou - * @copyright 2008 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ +// This file is part of GNU social - https://www.gnu.org/software/social +// +// GNU social is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GNU social is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with GNU social. If not, see . -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Class for events @@ -37,14 +22,13 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * This "class" two static functions for managing events in the StatusNet code. * * @category Event - * @package StatusNet + * @package GNU social * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * * @todo Define a system for using Event instances */ - class Event { /* Global array of hooks, mapping eventname => array of callables */ diff --git a/lib/gnusocial.php b/lib/gnusocial.php index 789cece2be..43c7c60ad2 100644 --- a/lib/gnusocial.php +++ b/lib/gnusocial.php @@ -1,24 +1,20 @@ . - * - */ +// This file is part of GNU social - https://www.gnu.org/software/social +// +// GNU social is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GNU social is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with GNU social. If not, see . -if (!defined('GNUSOCIAL')) { exit(1); } +defined('GNUSOCIAL') || die(); global $config, $_server, $_path; @@ -343,11 +339,6 @@ class GNUsocial $config['db'] = &$_PEAR->getStaticProperty('DB_DataObject','options'); $config['db'] = $default['db']; - - if (function_exists('date_default_timezone_set')) { - /* Work internally in UTC */ - date_default_timezone_set('UTC'); - } } public static function loadSiteProfile($name) diff --git a/lib/language.php b/lib/language.php index f0144b4106..c70adb8ea5 100644 --- a/lib/language.php +++ b/lib/language.php @@ -1,34 +1,33 @@ . + /** - * GNU social - a federating social network + * Utility functions for i18n * - * utility functions for i18n - * - * LICENCE: This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * @category I18n - * @package GNU social - * @author Matthew Gregg - * @author Ciaran Gultnieks - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @category I18n + * @package GNU social + * @author Matthew Gregg + * @author Ciaran Gultnieks + * @author Evan Prodromou + * @author Diogo Cordeiro + * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); // Locale category constants are usually predefined, but may not be // on some systems such as Win32. diff --git a/lib/plugin.php b/lib/plugin.php index 2625bf3520..cd0c9c6bad 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -1,35 +1,20 @@ . - * - * @category Plugin - * @package StatusNet - * @author Evan Prodromou - * @copyright 2008 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ +// This file is part of GNU social - https://www.gnu.org/software/social +// +// GNU social is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// GNU social is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with GNU social. If not, see . -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} +defined('GNUSOCIAL') || die(); /** * Base class for plugins @@ -45,14 +30,13 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * initialize() and cleanup() methods, respectively. * * @category Plugin - * @package StatusNet + * @package GNU social * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ + * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * * @see Event */ - class Plugin { function __construct() diff --git a/lib/util.php b/lib/util.php index 0866b32d55..966c415024 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1040,7 +1040,7 @@ function common_replace_urls_callback($text, $callback, $arg = null) '#ixu'; //preg_match_all($regex,$text,$matches); //print_r($matches); - return preg_replace_callback($regex, callable_left_curry('callback_helper', $callback, $arg), $text); + return preg_replace_callback($regex, callableLeftCurry('callback_helper', $callback, $arg), $text); } /** @@ -1102,7 +1102,7 @@ function callback_helper($matches, $callback, $arg = null) return substr($matches[0], 0, $left) . $result . substr($matches[0], $right); } -require_once INSTALLDIR . "/lib/callable_left_curry.php"; +require_once INSTALLDIR . "/lib/callableleftcurry.php"; function common_linkify($url) { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000000..b57ab9c7db --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + ./tests/Core + + + ./tests/Media + + + + + + + + + + diff --git a/tests/ActivityGenerationTests.php b/tests/Core/ActivityGenerationTests.php similarity index 80% rename from tests/ActivityGenerationTests.php rename to tests/Core/ActivityGenerationTests.php index 21fe32a58b..f8bb0257a0 100644 --- a/tests/ActivityGenerationTests.php +++ b/tests/Core/ActivityGenerationTests.php @@ -1,19 +1,49 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('PUBLICDIR')) { + define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -// XXX: we should probably have some common source for this stuff - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use Activity; +use ActivityObject; +use ActivityUtils; +use ActivityVerb; +use Conversation; +use DOMDocument; +use Exception; +use Notice; +use PHPUnit\Framework\TestCase; +use User; +use User_group; require_once INSTALLDIR . '/lib/common.php'; -class ActivityGenerationTests extends PHPUnit_Framework_TestCase +final class ActivityGenerationTests extends TestCase { static $author1 = null; static $author2 = null; @@ -35,44 +65,44 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $groupNick1 = 'activitygenerationtestsgroup' . common_random_hexstr(4); $groupNick2 = 'activitygenerationtestsgroup' . common_random_hexstr(4); - try{ - self::$author1 = User::register(array('nickname' => $authorNick1, - 'email' => $authorNick1 . '@example.net', - 'email_confirmed' => true)); + try { + self::$author1 = User::register(array('nickname' => $authorNick1, + 'email' => $authorNick1 . '@example.net', + 'email_confirmed' => true)); - self::$author2 = User::register(array('nickname' => $authorNick2, - 'email' => $authorNick2 . '@example.net', - 'email_confirmed' => true)); + self::$author2 = User::register(array('nickname' => $authorNick2, + 'email' => $authorNick2 . '@example.net', + 'email_confirmed' => true)); - self::$targetUser1 = User::register(array('nickname' => $targetNick1, - 'email' => $targetNick1 . '@example.net', - 'email_confirmed' => true)); + self::$targetUser1 = User::register(array('nickname' => $targetNick1, + 'email' => $targetNick1 . '@example.net', + 'email_confirmed' => true)); - self::$targetUser2 = User::register(array('nickname' => $targetNick2, - 'email' => $targetNick2 . '@example.net', - 'email_confirmed' => true)); + self::$targetUser2 = User::register(array('nickname' => $targetNick2, + 'email' => $targetNick2 . '@example.net', + 'email_confirmed' => true)); - self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1, - 'userid' => self::$author1->id, - 'aliases' => array(), - 'local' => true, - 'location' => null, - 'description' => null, - 'fullname' => null, - 'homepage' => null, - 'mainpage' => null)); - self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2, - 'userid' => self::$author1->id, - 'aliases' => array(), - 'local' => true, - 'location' => null, - 'description' => null, - 'fullname' => null, - 'homepage' => null, - 'mainpage' => null)); + self::$targetGroup1 = User_group::register(array('nickname' => $groupNick1, + 'userid' => self::$author1->id, + 'aliases' => array(), + 'local' => true, + 'location' => null, + 'description' => null, + 'fullname' => null, + 'homepage' => null, + 'mainpage' => null)); + self::$targetGroup2 = User_group::register(array('nickname' => $groupNick2, + 'userid' => self::$author1->id, + 'aliases' => array(), + 'local' => true, + 'location' => null, + 'description' => null, + 'fullname' => null, + 'homepage' => null, + 'mainpage' => null)); } catch (Exception $e) { - self::tearDownAfterClass(); - throw $e; + self::tearDownAfterClass(); + throw $e; } } @@ -85,7 +115,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $element = $this->_entryToElement($entry, false); $this->assertEquals($notice->getUri(), ActivityUtils::childContent($element, 'id')); - $this->assertEquals('New note by '. self::$author1->nickname, ActivityUtils::childContent($element, 'title')); + $this->assertEquals('New note by ' . self::$author1->nickname, ActivityUtils::childContent($element, 'title')); $this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content')); $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published'))); $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated'))); @@ -195,7 +225,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $element = $this->_entryToElement($entry, true); $author = ActivityUtils::child($element, 'author'); - $actor = ActivityUtils::child($element, 'actor', Activity::SPEC); + $actor = ActivityUtils::child($element, 'actor', Activity::SPEC); $this->assertFalse(is_null($author)); $this->assertTrue(is_null($actor)); // is obsolete, no longer added @@ -459,32 +489,32 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase $this->assertEquals('false', $noticeInfo->getAttribute('repeated')); } -/* public function testNoticeInfoFave() - { - $notice = $this->_fakeNotice(); + /* public function testNoticeInfoFave() + { + $notice = $this->_fakeNotice(); - $fave = Fave::addNew(self::$author2->getProfile(), $notice); + $fave = Fave::addNew(self::$author2->getProfile(), $notice); - // Should be set if user has faved + // Should be set if user has faved - $entry = $notice->asAtomEntry(false, false, false, self::$author2); + $entry = $notice->asAtomEntry(false, false, false, self::$author2); - $element = $this->_entryToElement($entry, true); + $element = $this->_entryToElement($entry, true); - $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); + $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); - $this->assertEquals('true', $noticeInfo->getAttribute('favorite')); + $this->assertEquals('true', $noticeInfo->getAttribute('favorite')); - // Shouldn't be set if user has not faved + // Shouldn't be set if user has not faved - $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1); + $entry = $notice->asAtomEntry(false, false, false, self::$targetUser1); - $element = $this->_entryToElement($entry, true); + $element = $this->_entryToElement($entry, true); - $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); + $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/"); - $this->assertEquals('false', $noticeInfo->getAttribute('favorite')); - }*/ + $this->assertEquals('false', $noticeInfo->getAttribute('favorite')); + }*/ public function testConversationLink() { @@ -545,7 +575,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase private function _entryToElement($entry, $namespace = false) { - $xml = ''."\n\n"; + $xml = '' . "\n\n"; $xml .= '' . "\n"; - $doc = DOMDocument::loadXML($xml); + $doc = new DOMDocument(); + $doc->loadXML($xml); $feed = $doc->documentElement; $entries = $feed->getElementsByTagName('entry'); diff --git a/tests/ActivityParseTests.php b/tests/Core/ActivityParseTests.php similarity index 90% rename from tests/ActivityParseTests.php rename to tests/Core/ActivityParseTests.php index 566318e9ea..12e2f03ddb 100644 --- a/tests/ActivityParseTests.php +++ b/tests/Core/ActivityParseTests.php @@ -1,24 +1,48 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -// XXX: we should probably have some common source for this stuff - -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use Activity; +use ActivityObject; +use ActivityUtils; +use ActivityVerb; +use DOMDocument; +use PHPUnit\Framework\TestCase; require_once INSTALLDIR . '/lib/common.php'; -class ActivityParseTests extends PHPUnit_Framework_TestCase +final class ActivityParseTests extends TestCase { - public function testMastodonRetweet() { + public function testMastodonRetweet() + { global $_mastodon_retweet; - $dom = DOMDocument::loadXML($_mastodon_retweet); + $dom = new DOMDocument(); + $dom->loadXML($_mastodon_retweet); $feed = $dom->documentElement; $entries = $feed->getElementsByTagName('entry'); $entry = $entries->item(0); @@ -30,9 +54,11 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase $this->assertEquals($object->verb, ActivityVerb::POST); } - public function testGSReweet() { + public function testGSReweet() + { global $_gs_retweet; - $dom = DOMDocument::loadXML($_gs_retweet); + $dom = new DOMDocument(); + $dom->loadXML($_gs_retweet); $feed = $dom->documentElement; $entries = $feed->getElementsByTagName('entry'); $entry = $entries->item(0); @@ -47,7 +73,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testExample1() { global $_example1; - $dom = DOMDocument::loadXML($_example1); + $dom = new DOMDocument(); + $dom->loadXML($_example1); $act = new Activity($dom->documentElement); $this->assertFalse(empty($act)); @@ -65,19 +92,21 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testExample2() { global $_example2; - $dom = DOMDocument::loadXML($_example2); + $dom = new DOMDocument(); + $dom->loadXML($_example2); $act = new Activity($dom->documentElement); $this->assertFalse(empty($act)); // Did we handle correctly with a typical payload? $this->assertEquals("

Geraldine posted a Photo on PhotoPanic

\n " . - "", trim($act->content)); + "", trim($act->content)); } public function testExample3() { global $_example3; - $dom = DOMDocument::loadXML($_example3); + $dom = new DOMDocument(); + $dom->loadXML($_example3); $feed = $dom->documentElement; @@ -116,7 +145,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testExample4() { global $_example4; - $dom = DOMDocument::loadXML($_example4); + $dom = new DOMDocument(); + $dom->loadXML($_example4); $entry = $dom->documentElement; @@ -134,7 +164,7 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase $this->assertFalse(empty($act->objects[0])); $this->assertEquals($act->objects[0]->content, - '@evan now is the time for all good men to come to the aid of their country. #'); + '@evan now is the time for all good men to come to the aid of their country. #'); $this->assertFalse(empty($act->actor)); } @@ -142,7 +172,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testExample5() { global $_example5; - $dom = DOMDocument::loadXML($_example5); + $dom = new DOMDocument(); + $dom->loadXML($_example5); $feed = $dom->documentElement; @@ -167,8 +198,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase $avatars = $act->actor->avatarLinks; $this->assertEquals( - $avatars[0]->url, - 'http://example.net/mysite/avatar/3-96-20100224004207.jpeg' + $avatars[0]->url, + 'http://example.net/mysite/avatar/3-96-20100224004207.jpeg' ); $this->assertEquals($act->actor->displayName, 'Test User'); @@ -186,7 +217,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase { global $_example6; - $dom = DOMDocument::loadXML($_example6); + $dom = new DOMDocument(); + $dom->loadXML($_example6); $rss = $dom->documentElement; @@ -217,7 +249,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase { global $_example7; - $dom = DOMDocument::loadXML($_example7); + $dom = new DOMDocument(); + $dom->loadXML($_example7); $rss = $dom->documentElement; @@ -249,7 +282,7 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase $this->assertTrue(is_array($actor->avatarLinks)); $this->assertEquals(1, count($actor->avatarLinks)); $this->assertEquals('http://files.posterous.com/user_profile_pics/480326/2009-08-05-142447.jpg', - $actor->avatarLinks[0]->url); + $actor->avatarLinks[0]->url); $this->assertNotNull($actor->poco); $this->assertEquals('evanpro', $actor->poco->preferredUsername); $this->assertEquals('Evan Prodromou', $actor->poco->displayName); @@ -262,7 +295,8 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testExample8() { global $_example8; - $dom = DOMDocument::loadXML($_example8); + $dom = new DOMDocument(); + $dom->loadXML($_example8); $feed = $dom->documentElement; @@ -350,32 +384,33 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testAtomContent() { $tests = array(array("Some regular plain text.", - "Some regular plain text."), - array("<b>this is not HTML</b>", - "<b>this is not HTML</b>"), - array("Some regular plain HTML.", - "Some regular plain HTML."), - array("<b>this is too HTML</b>", - "this is too HTML"), - array("&lt;b&gt;but this is not HTML!&lt;/b&gt;", - "<b>but this is not HTML!</b>"), - array("
Some regular plain XHTML.
", - "Some regular plain XHTML."), - array("
This is some XHTML!
", - "This is some XHTML!"), - array("
<b>This is not some XHTML!</b>
", - "<b>This is not some XHTML!</b>"), - array("
&lt;b&gt;This is not some XHTML either!&lt;/b&gt;
", - "&lt;b&gt;This is not some XHTML either!&lt;/b&gt;")); + "Some regular plain text."), + array("<b>this is not HTML</b>", + "<b>this is not HTML</b>"), + array("Some regular plain HTML.", + "Some regular plain HTML."), + array("<b>this is too HTML</b>", + "this is too HTML"), + array("&lt;b&gt;but this is not HTML!&lt;/b&gt;", + "<b>but this is not HTML!</b>"), + array("
Some regular plain XHTML.
", + "Some regular plain XHTML."), + array("
This is some XHTML!
", + "This is some XHTML!"), + array("
<b>This is not some XHTML!</b>
", + "<b>This is not some XHTML!</b>"), + array("
&lt;b&gt;This is not some XHTML either!&lt;/b&gt;
", + "&lt;b&gt;This is not some XHTML either!&lt;/b&gt;")); foreach ($tests as $data) { list($source, $output) = $data; $xml = "" . - "http://example.com/fakeid" . - "Test" . - "Atom content tests" . - $source . - ""; - $dom = DOMDocument::loadXML($xml); + "http://example.com/fakeid" . + "Test" . + "Atom content tests" . + $source . + ""; + $dom = new DOMDocument(); + $dom->loadXML($xml); $act = new Activity($dom->documentElement); $this->assertFalse(empty($act)); @@ -386,25 +421,26 @@ class ActivityParseTests extends PHPUnit_Framework_TestCase public function testRssContent() { $tests = array(array("Some regular plain HTML.", - "Some regular plain HTML."), - array("Some <b>exciting bold HTML</b>", - "Some exciting bold HTML"), - array("Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;", - "Some <b>escaped non-HTML.</b>"), - array("Some plain text.", - "Some plain text."), - array("Some <b>non-HTML text</b>", - "Some <b>non-HTML text</b>"), - array("Some &lt;b&gt;double-escaped text&lt;/b&gt;", - "Some &lt;b&gt;double-escaped text&lt;/b&gt;")); + "Some regular plain HTML."), + array("Some <b>exciting bold HTML</b>", + "Some exciting bold HTML"), + array("Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;", + "Some <b>escaped non-HTML.</b>"), + array("Some plain text.", + "Some plain text."), + array("Some <b>non-HTML text</b>", + "Some <b>non-HTML text</b>"), + array("Some &lt;b&gt;double-escaped text&lt;/b&gt;", + "Some &lt;b&gt;double-escaped text&lt;/b&gt;")); foreach ($tests as $data) { list($source, $output) = $data; $xml = "" . - "http://example.com/fakeid" . - "RSS content tests" . - $source . - ""; - $dom = DOMDocument::loadXML($xml); + "http://example.com/fakeid" . + "RSS content tests" . + $source . + ""; + $dom = new DOMDocument(); + $dom->loadXML($xml); $act = new Activity($dom->documentElement); $this->assertFalse(empty($act)); diff --git a/tests/Core/CallableLeftCurryTest.php b/tests/Core/CallableLeftCurryTest.php new file mode 100644 index 0000000000..b3eeea33dc --- /dev/null +++ b/tests/Core/CallableLeftCurryTest.php @@ -0,0 +1,91 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} + +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . "/lib/callableleftcurry.php"; + +final class CallableLeftCurryTest extends TestCase +{ + /** + * @dataProvider provider + * @param $callback_test + * @param $curry_params + * @param $call_params + * @param $expected + */ + public function testCallableLeftCurry($callback_test, $curry_params, $call_params, $expected) + { + $params = array_merge([$callback_test], $curry_params); + $curried = call_user_func_array('callableLeftCurry', $params); + $result = call_user_func_array($curried, $call_params); + $this->assertEquals($expected, $result); + } + + static public function provider() + { + $obj = new CurryTestHelperObj('oldval'); + return [[['Tests\Unit\CallableLeftCurryTest', 'callback_test'], + ['curried'], + ['called'], + 'called|curried'], + [['Tests\Unit\CallableLeftCurryTest', 'callback_test'], + ['curried1', 'curried2'], + ['called1', 'called2'], + 'called1|called2|curried1|curried2'], + [['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'], + [$obj], + ['newval1'], + 'oldval|newval1'], + // Confirm object identity is retained... + [['Tests\Unit\CallableLeftCurryTest', 'callback_testObj'], + [$obj], + ['newval2'], + 'newval1|newval2']]; + } + + static function callback_test() + { + $args = func_get_args(); + return implode("|", $args); + } + + static function callback_testObj($val, $obj) + { + $old = $obj->val; + $obj->val = $val; + return "$old|$val"; + } +} + +class CurryTestHelperObj +{ + public $val = ''; + + function __construct($val) + { + $this->val = $val; + } +} diff --git a/tests/CommandInterperterTest.php b/tests/Core/CommandInterperterTest.php similarity index 79% rename from tests/CommandInterperterTest.php rename to tests/Core/CommandInterperterTest.php index 5f681ae1da..d8f6149a7c 100644 --- a/tests/CommandInterperterTest.php +++ b/tests/Core/CommandInterperterTest.php @@ -1,23 +1,46 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use CommandInterpreter; +use PHPUnit\Framework\TestCase; require_once INSTALLDIR . '/lib/common.php'; -class CommandInterpreterTest extends PHPUnit_Framework_TestCase +final class CommandInterpreterTest extends TestCase { /** * @dataProvider commandInterpreterCases + * @param $input + * @param $expectedType + * @param string $comment */ - public function testCommandInterpreter($input, $expectedType, $comment='') + public function testCommandInterpreter($input, $expectedType, $comment = '') { $inter = new CommandInterpreter(); @@ -130,9 +153,9 @@ class CommandInterpreterTest extends PHPUnit_Framework_TestCase array('whois foo', 'WhoisCommand'), array('whois foo bar', null), -/* array('fav', null), - array('fav foo', 'FavCommand'), - array('fav foo bar', null),*/ + /* array('fav', null), + array('fav foo', 'FavCommand'), + array('fav foo bar', null),*/ array('nudge', null), array('nudge foo', 'NudgeCommand'), diff --git a/tests/Core/HashTagDetectionTests.php b/tests/Core/HashTagDetectionTests.php new file mode 100644 index 0000000000..00b312545d --- /dev/null +++ b/tests/Core/HashTagDetectionTests.php @@ -0,0 +1,83 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . '/lib/common.php'; + +final class HashTagDetectionTests extends TestCase +{ + /** + * @dataProvider provider + * @param $content + * @param $expected + */ + public function testProduction($content, $expected) + { + $rendered = common_render_text($content); + $this->assertEquals($expected, $rendered); + } + + static public function provider() + { + return array( + array('hello', + 'hello'), + array('#hello people', + '# people'), + array('"#hello" people', + '"#" people'), + array('say "#hello" people', + 'say "#" people'), + array('say (#hello) people', + 'say (#) people'), + array('say [#hello] people', + 'say [#] people'), + array('say {#hello} people', + 'say {#} people'), + array('say \'#hello\' people', + 'say \'#\' people'), + + // Unicode legit letters + array('#éclair yummy', + '# yummy'), + array('#维基百科 zh.wikipedia!', + '# zh.wikipedia!'), + array('#Россия russia', + '# russia'), + + // Unicode punctuators -- the ideographic "," separates the tag, just as "," does + array('#维基百科,zh.wikipedia!', + '#,zh.wikipedia!'), + array('#维基百科,zh.wikipedia!', + '#,zh.wikipedia!'), + + ); + } +} + diff --git a/tests/Core/LocationTest.php b/tests/Core/LocationTest.php new file mode 100644 index 0000000000..747a470d9d --- /dev/null +++ b/tests/Core/LocationTest.php @@ -0,0 +1,124 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use GeonamesPlugin; +use Location; +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . '/lib/common.php'; + +// Make sure this is loaded +// XXX: how to test other plugins...? + +addPlugin('Geonames'); + +final class LocationTest extends TestCase +{ + + /** + * @dataProvider locationNames + * @param $name + * @param $language + * @param $location + */ + + public function testLocationFromName($name, $language, $location) + { + $result = Location::fromName($name, $language); + $this->assertEquals($result, $location); + } + + static public function locationNames() + { + return array(array('Montreal', 'en', null), + array('San Francisco, CA', 'en', null), + array('Paris, France', 'en', null), + array('Paris, Texas', 'en', null)); + } + + /** + * @dataProvider locationIds + * @param $id + * @param $ns + * @param $language + * @param $location + */ + + public function testLocationFromId($id, $ns, $language, $location) + { + $result = Location::fromId($id, $ns, $language); + $this->assertEquals($result, $location); + } + + static public function locationIds() + { + return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null), + array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null)); + } + + /** + * @dataProvider locationLatLons + * @param $lat + * @param $lon + * @param $language + * @param $location + */ + + public function testLocationFromLatLon($lat, $lon, $language, $location) + { + $result = Location::fromLatLon($lat, $lon, $language); + $this->assertEquals($location, $result->location_id); + } + + static public function locationLatLons() + { + return array(array(37.77493, -122.41942, 'en', null), + array(45.509, -73.588, 'en', null)); + } + + /** + * @dataProvider nameOfLocation + * @param $location + * @param $language + * @param $name + */ + + public function testLocationGetName($location, $language, $name) + { + $result = empty($location) ? null : $location->getName($language); + $this->assertEquals($name, $result); + } + + static public function nameOfLocation() + { + $loc = Location::fromName('Montreal', 'en'); + return array(array($loc, 'en', null), //'Montreal'), + array($loc, 'fr', null));//'Montréal')); + } +} + diff --git a/tests/Core/NicknameTest.php b/tests/Core/NicknameTest.php new file mode 100644 index 0000000000..e315033bbb --- /dev/null +++ b/tests/Core/NicknameTest.php @@ -0,0 +1,156 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use Nickname; +use NicknameBlacklistedException; +use NicknameEmptyException; +use NicknameException; +use NicknameInvalidException; +use NicknamePathCollisionException; +use NicknameTakenException; +use NicknameTooLongException; +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . '/lib/common.php'; + +/** + * Test cases for nickname validity and normalization. + */ +final class NicknameTest extends TestCase +{ + /** + * Basic test using Nickname::normalize() + * + * @dataProvider provider + * @param $input + * @param $expected + * @param null $expectedException + */ + public function testBasic($input, $expected, $expectedException = null) + { + $exception = null; + $normalized = false; + try { + $normalized = Nickname::normalize($input); + } catch (NicknameException $e) { + $exception = $e; + } + + if ($expected === false) { + if ($expectedException) { + if ($exception) { + $stuff = get_class($exception) . ': ' . $exception->getMessage(); + } else { + $stuff = var_export($exception, true); + } + $this->assertTrue($exception && $exception instanceof $expectedException, + "invalid input '$input' expected to fail with $expectedException, " . + "got $stuff"); + } else { + $this->assertTrue($normalized == false, + "invalid input '$input' expected to fail"); + } + } else { + $msg = "normalized input nickname '$input' expected to normalize to '$expected', got "; + if ($exception) { + $msg .= get_class($exception) . ': ' . $exception->getMessage(); + } else { + $msg .= "'$normalized'"; + } + $this->assertEquals($expected, $normalized, $msg); + } + } + + /** + * Test on the regex matching used in common_find_mentions + * (testing on the full notice rendering is difficult as it needs + * to be able to pull from global state) + * + * @dataProvider provider + * @param $input + * @param $expected + * @param null $expectedException + * @throws NicknameBlacklistedException + * @throws NicknameEmptyException + * @throws NicknameException + * @throws NicknameInvalidException + * @throws NicknamePathCollisionException + * @throws NicknameTakenException + * @throws NicknameTooLongException + */ + public function testAtReply($input, $expected, $expectedException = null) + { + if ($expected == false) { + // nothing to do + } else { + $text = "@{$input} awesome! :)"; + $matches = common_find_mentions_raw($text); + $this->assertEquals(1, count($matches)); + $this->assertEquals($expected, Nickname::normalize($matches[0][0])); + } + } + + static public function provider() + { + return array( + array('evan', 'evan'), + + // Case and underscore variants + array('Evan', 'evan'), + array('EVAN', 'evan'), + array('ev_an', 'evan'), + array('E__V_an', 'evan'), + array('evan1', 'evan1'), + array('evan_1', 'evan1'), + array('0x20', '0x20'), + array('1234', '1234'), // should this be allowed though? :) + array('12__34', '1234'), + + // Some (currently) invalid chars... + array('^#@&^#@', false, 'NicknameInvalidException'), // all invalid :D + array('ev.an', false, 'NicknameInvalidException'), + array('ev/an', false, 'NicknameInvalidException'), + array('ev an', false, 'NicknameInvalidException'), + array('ev-an', false, 'NicknameInvalidException'), + + // Non-ASCII letters; currently not allowed, in future + // we'll add them at least with conversion to ASCII. + // Not much use until we have storage of display names, + // though. + array('évan', false, 'NicknameInvalidException'), // so far... + array('Évan', false, 'NicknameInvalidException'), // so far... + + // Length checks + array('', false, 'NicknameEmptyException'), + array('___', false, 'NicknameEmptyException'), + array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars + array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long... + array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long + ); + } +} diff --git a/tests/Core/TagURITest.php b/tests/Core/TagURITest.php new file mode 100644 index 0000000000..07343a35fa --- /dev/null +++ b/tests/Core/TagURITest.php @@ -0,0 +1,59 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . '/lib/common.php'; + +$config['site']['server'] = 'example.net'; +$config['site']['path'] = '/apps/statusnet'; + +final class TagURITest extends TestCase +{ + /** + * @dataProvider provider + * @param $format + * @param $args + * @param $uri + */ + public function testProduction($format, $args, $uri) + { + $minted = call_user_func_array(array('TagURI', 'mint'), + array_merge(array($format), $args)); + + $this->assertEquals($uri, $minted); + } + + static public function provider() + { + return array(array('favorite:%d:%d', + array(1, 3), + 'tag:example.net,' . date('Y-m-d') . ':apps:statusnet:favorite:1:3')); + } +} + diff --git a/tests/Core/URLDetectionTest.php b/tests/Core/URLDetectionTest.php new file mode 100644 index 0000000000..e4adce5ab3 --- /dev/null +++ b/tests/Core/URLDetectionTest.php @@ -0,0 +1,377 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use PHPUnit\Framework\TestCase; + +require_once INSTALLDIR . '/lib/common.php'; + +final class URLDetectionTest extends TestCase +{ + /** + * @dataProvider provider + * @param $content + * @param $expected + */ + public function testProduction($content, $expected) + { + $rendered = common_render_text($content); + // hack! + $rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered); + $this->assertEquals($expected, $rendered); + } + + /** + * @dataProvider linkifyProvider + * @param $content + * @param $expected + * @param $config + */ + public function testLinkifyProduction($content, $expected, $config) + { + $rendered = common_render_text($content); + // hack! + $rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered); + if (common_config('linkify', $config)) { + $this->assertEquals($expected, $rendered); + } else { + $content = common_remove_unicode_formatting(nl2br(htmlspecialchars($content))); + $this->assertEquals($content, $rendered); + } + } + + static public function provider() + { + return array( + array('not a link :: no way', + 'not a link :: no way'), + array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link', + 'link http://www.somesite.com/xyz/35637563@N00/52803365/ link'), + array('http://127.0.0.1', + 'http://127.0.0.1'), + array('http://[::1]:99/test.php', + 'http://[::1]:99/test.php'), + array('http://::1/test.php', + 'http://::1/test.php'), + array('http://::1', + 'http://::1'), + array('http://127.0.0.1', + 'http://127.0.0.1'), + array('http://example.com', + 'http://example.com'), + array('http://example.com.', + 'http://example.com.'), + array('/var/lib/example.so', + '/var/lib/example.so'), + array('example', + 'example'), + array('mailto:user@example.com', + 'mailto:user@example.com'), + array('mailto:user@example.com?subject=test', + 'mailto:user@example.com?subject=test'), + array('xmpp:user@example.com', + 'xmpp:user@example.com'), + array('#example', + '#'), + array('#example.com', + '#'), + array('#.net', + '#'), + array('http://example', + 'http://example'), + array('http://3xampl3', + 'http://3xampl3'), + array('http://example/', + 'http://example/'), + array('http://example/path', + 'http://example/path'), + array('http://example.com', + 'http://example.com'), + array('https://example.com', + 'https://example.com'), + array('ftp://example.com', + 'ftp://example.com'), + array('ftps://example.com', + 'ftps://example.com'), + array('http://user@example.com', + 'http://user@example.com'), + array('http://user:pass@example.com', + 'http://user:pass@example.com'), + array('http://example.com:8080', + 'http://example.com:8080'), + array('http://example.com:8080/test.php', + 'http://example.com:8080/test.php'), + array('http://www.example.com', + 'http://www.example.com'), + array('http://example.com/', + 'http://example.com/'), + array('http://example.com/path', + 'http://example.com/path'), + array('http://example.com/path.html', + 'http://example.com/path.html'), + array('http://example.com/path.html#fragment', + 'http://example.com/path.html#fragment'), + array('http://example.com/path.php?foo=bar&bar=foo', + 'http://example.com/path.php?foo=bar&bar=foo'), + array('http://example.com.', + 'http://example.com.'), + array('http://müllärör.de', + 'http://müllärör.de'), + array('http://ﺱﺲﺷ.com', + 'http://ﺱﺲﺷ.com'), + array('http://сделаткартинки.com', + 'http://сделаткартинки.com'), + array('http://tūdaliņ.lv', + 'http://tūdaliņ.lv'), + array('http://brændendekærlighed.com', + 'http://brændendekærlighed.com'), + array('http://あーるいん.com', + 'http://あーるいん.com'), + array('http://예비교사.com', + 'http://예비교사.com'), + array('http://example.com.', + 'http://example.com.'), + array('http://example.com?', + 'http://example.com?'), + array('http://example.com!', + 'http://example.com!'), + array('http://example.com,', + 'http://example.com,'), + array('http://example.com;', + 'http://example.com;'), + array('http://example.com:', + 'http://example.com:'), + array('\'http://example.com\'', + '\'http://example.com\''), + array('"http://example.com"', + '"http://example.com"'), + array('"http://example.com/"', + '"http://example.com/"'), + array('http://example.com', + 'http://example.com'), + array('(http://example.com)', + '(http://example.com)'), + array('[http://example.com]', + '[http://example.com]'), + array('', + '<http://example.com>'), + array('http://example.com/path/(foo)/bar', + 'http://example.com/path/(foo)/bar'), + array('http://example.com/path/[foo]/bar', + 'http://example.com/path/[foo]/bar'), + array('http://example.com/path/foo/(bar)', + 'http://example.com/path/foo/(bar)'), + //Not a valid url - urls cannot contain unencoded square brackets + array('http://example.com/path/foo/[bar]', + 'http://example.com/path/foo/[bar]'), + array('Hey, check out my cool site http://example.com okay?', + 'Hey, check out my cool site http://example.com okay?'), + array('What about parens (e.g. http://example.com/path/foo/(bar))?', + 'What about parens (e.g. http://example.com/path/foo/(bar))?'), + array('What about parens (e.g. http://example.com/path/foo/(bar)?', + 'What about parens (e.g. http://example.com/path/foo/(bar)?'), + array('What about parens (e.g. http://example.com/path/foo/(bar).)?', + 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), + //Not a valid url - urls cannot contain unencoded commas + array('What about parens (e.g. http://example.com/path/(foo,bar)?', + 'What about parens (e.g. http://example.com/path/(foo,bar)?'), + array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', + 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), + array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', + 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), + array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', + 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), + array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', + 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), + array('file.ext', + 'file.ext'), + array('file.html', + 'file.html'), + array('file.php', + 'file.php'), + + // scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248 + array('http://flickr.com/photos/34807140@N05/3838905434', + 'http://flickr.com/photos/34807140@N05/3838905434'), + ); + } + + static public function linkifyProvider() + { + return array( + //bare ip addresses are no longer supported + array('127.0.0.1', + '127.0.0.1', + 'bare_ipv4'), + array('127.0.0.1:99', + '127.0.0.1:99', + 'bare_ipv4'), + array('127.0.0.1/Name:test.php', + '127.0.0.1/Name:test.php', + 'bare_ipv4'), + array('127.0.0.1/~test', + '127.0.0.1/~test', + 'bare_ipv4'), + array('127.0.0.1/+test', + '127.0.0.1/+test', + 'bare_ipv4'), + array('127.0.0.1/$test', + '127.0.0.1/$test', + 'bare_ipv4'), + array('127.0.0.1/\'test', + '127.0.0.1/\'test', + 'bare_ipv4'), + array('127.0.0.1/"test', + '127.0.0.1/"test', + 'bare_ipv4'), + array('127.0.0.1/test"test', + '127.0.0.1/test"test', + 'bare_ipv4'), + array('127.0.0.1/-test', + '127.0.0.1/-test', + 'bare_ipv4'), + array('127.0.0.1/_test', + '127.0.0.1/_test', + 'bare_ipv4'), + array('127.0.0.1/!test', + '127.0.0.1/!test', + 'bare_ipv4'), + array('127.0.0.1/*test', + '127.0.0.1/*test', + 'bare_ipv4'), + array('127.0.0.1/test%20stuff', + '127.0.0.1/test%20stuff', + 'bare_ipv4'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', + 'bare_ipv6'), + array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', + '[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', + 'bare_ipv6'), + array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', + '2001:4978:1b5:0:21d:e0ff:fe66:59ab', + 'bare_ipv6'), + array('example.com', + 'example.com', + 'bare_domains'), + array('flickr.com/photos/34807140@N05/3838905434', + 'flickr.com/photos/34807140@N05/3838905434', + 'bare_domains'), + array('What about parens (e.g. example.com/path/foo/(bar))?', + 'What about parens (e.g. example.com/path/foo/(bar))?', + 'bare_domains'), + array('What about parens (e.g. example.com/path/foo/(bar)?', + 'What about parens (e.g. example.com/path/foo/(bar)?', + 'bare_domains'), + array('What about parens (e.g. example.com/path/foo/(bar).)?', + 'What about parens (e.g. example.com/path/foo/(bar).?', + 'bare_domains'), + array('What about parens (e.g. example.com/path/(foo,bar)?', + 'What about parens (e.g. example.com/path/(foo,bar)?', + 'bare_domains'), + array('example.com', + 'example.com', + 'bare_domains'), + array('example.org', + 'example.org', + 'bare_domains'), + array('example.co.uk', + 'example.co.uk', + 'bare_domains'), + array('www.example.co.uk', + 'www.example.co.uk', + 'bare_domains'), + array('farm1.images.example.co.uk', + 'farm1.images.example.co.uk', + 'bare_domains'), + array('example.museum', + 'example.museum', + 'bare_domains'), + array('example.travel', + 'example.travel', + 'bare_domains'), + array('example.com.', + 'example.com.', + 'bare_domains'), + array('example.com?', + 'example.com?', + 'bare_domains'), + array('example.com!', + 'example.com!', + 'bare_domains'), + array('example.com,', + 'example.com,', + 'bare_domains'), + array('example.com;', + 'example.com;', + 'bare_domains'), + array('example.com:', + 'example.com:', + 'bare_domains'), + array('\'example.com\'', + '\'example.com\'', + 'bare_domains'), + array('"example.com"', + '"example.com"', + 'bare_domains'), + array('example.com', + 'example.com', + 'bare_domains'), + array('(example.com)', + '(example.com)', + 'bare_domains'), + array('[example.com]', + '[example.com]', + 'bare_domains'), + array('', + '<example.com>', + 'bare_domains'), + array('Hey, check out my cool site example.com okay?', + 'Hey, check out my cool site example.com okay?', + 'bare_domains'), + array('Hey, check out my cool site example.com.I made it.', + 'Hey, check out my cool site example.com.I made it.', + 'bare_domains'), + array('Hey, check out my cool site example.com.Funny thing...', + 'Hey, check out my cool site example.com.Funny thing...', + 'bare_domains'), + array('Hey, check out my cool site example.com.You will love it.', + 'Hey, check out my cool site example.com.You will love it.', + 'bare_domains'), + array('example.com:8080/test.php', + 'example.com:8080/test.php', + 'bare_domains'), + array('user_name+other@example.com', + 'user_name+other@example.com', + 'bare_domains'), + array('user@example.com', + 'user@example.com', + 'bare_domains'), + ); + } +} + diff --git a/tests/Core/UUIDTest.php b/tests/Core/UUIDTest.php new file mode 100644 index 0000000000..50e9257a07 --- /dev/null +++ b/tests/Core/UUIDTest.php @@ -0,0 +1,58 @@ +. + +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); +} + +use PHPUnit\Framework\TestCase; +use UUID; + +require_once INSTALLDIR . '/lib/common.php'; + +final class UUIDTest extends TestCase +{ + public function testGenerate() + { + $result = UUID::gen(); + $this->assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/', + $result); + // Check version number + $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000); + $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000); + } + + public function testUnique() + { + $reps = 100; + $ids = array(); + + for ($i = 0; $i < $reps; $i++) { + $ids[] = UUID::gen(); + } + + $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique"); + } +} + diff --git a/tests/UserFeedParseTest.php b/tests/Core/UserFeedParseTest.php similarity index 76% rename from tests/UserFeedParseTest.php rename to tests/Core/UserFeedParseTest.php index b68783bb03..f2685469d9 100644 --- a/tests/UserFeedParseTest.php +++ b/tests/Core/UserFeedParseTest.php @@ -1,22 +1,45 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use Activity; +use ActivityObject; +use DOMDocument; +use PHPUnit\Framework\TestCase; require_once INSTALLDIR . '/lib/common.php'; -class UserFeedParseTests extends PHPUnit_Framework_TestCase +final class UserFeedParseTests extends TestCase { public function testFeed1() { global $_testfeed1; - $dom = DOMDocument::loadXML($_testfeed1); + $dom = new DOMDocument(); + $dom->loadXML($_testfeed1); $this->assertFalse(empty($dom)); $entries = $dom->getElementsByTagName('entry'); @@ -40,18 +63,18 @@ class UserFeedParseTests extends PHPUnit_Framework_TestCase $avatars = $act1->actor->avatarLinks; $this->assertEquals( - $avatars[0]->url, - 'http://localhost/statusnet/theme/default/default-avatar-profile.png' + $avatars[0]->url, + 'http://localhost/statusnet/theme/default/default-avatar-profile.png' ); $this->assertEquals( - $avatars[1]->url, - 'http://localhost/statusnet/theme/default/default-avatar-stream.png' + $avatars[1]->url, + 'http://localhost/statusnet/theme/default/default-avatar-stream.png' ); $this->assertEquals( - $avatars[2]->url, - 'http://localhost/statusnet/theme/default/default-avatar-mini.png' + $avatars[2]->url, + 'http://localhost/statusnet/theme/default/default-avatar-mini.png' ); $this->assertEquals($act1->actor->displayName, 'Zach Copley'); diff --git a/tests/UserRightsTest.php b/tests/Core/UserRightsTest.php similarity index 52% rename from tests/UserRightsTest.php rename to tests/Core/UserRightsTest.php index bd9124a91d..42af9ba683 100644 --- a/tests/UserRightsTest.php +++ b/tests/Core/UserRightsTest.php @@ -1,17 +1,38 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use Exception; +use PHPUnit\Framework\TestCase; +use User; require_once INSTALLDIR . '/lib/common.php'; -class UserRightsTest extends PHPUnit_Framework_TestCase +final class UserRightsTest extends TestCase { protected $user = null; @@ -47,12 +68,12 @@ class UserRightsTest extends PHPUnit_Framework_TestCase function standardRoles() { return array(array('admin'), - array('moderator')); + array('moderator')); } /** * @dataProvider standardRoles - * + * @param $role */ function testUngrantedRole($role) @@ -62,7 +83,7 @@ class UserRightsTest extends PHPUnit_Framework_TestCase /** * @dataProvider standardRoles - * + * @param $role */ function testGrantedRole($role) diff --git a/tests/XmppValidateTest.php b/tests/Core/XmppValidateTest.php similarity index 72% rename from tests/XmppValidateTest.php rename to tests/Core/XmppValidateTest.php index f3377390aa..f751eb092f 100644 --- a/tests/XmppValidateTest.php +++ b/tests/Core/XmppValidateTest.php @@ -1,55 +1,82 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility - -mb_internal_encoding('UTF-8'); // @fixme this probably belongs in common.php? +use GNUsocial; +use PHPUnit\Framework\TestCase; +use XmppPlugin; require_once INSTALLDIR . '/lib/common.php'; + require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php'; -class XmppValidateTest extends PHPUnit_Framework_TestCase +final class XmppValidateTest extends TestCase { - public function setUp() - { - if(!array_key_exists('Xmpp', GNUsocial::getActivePlugins())){ - $this->markTestSkipped('XmppPlugin is not enabled.'); - } - } + public function setUp() + { + if (!array_key_exists('Xmpp', GNUsocial::getActivePlugins())) { + $this->markTestSkipped('XmppPlugin is not enabled.'); + } + } + /** * @dataProvider validationCases - * + * @param $jid + * @param $validFull + * @param $validBase */ public function testValidate($jid, $validFull, $validBase) { - $xmpp = new TestXmppPlugin(); - $this->assertEquals($validFull || $validBase, $xmpp->validate($jid)); + $xmpp = new TestXmppPlugin(); + $this->assertEquals($validFull || $validBase, $xmpp->validate($jid)); $this->assertEquals($validFull, $xmpp->validateFullJid($jid), "validating as full or base JID"); $this->assertEquals($validBase, $xmpp->validateBaseJid($jid), "validating as base JID only"); } /** * @dataProvider normalizationCases - * + * @param $jid + * @param $expected */ public function testNormalize($jid, $expected) { - $xmpp = new XmppPlugin(); + $xmpp = new XmppPlugin(); $this->assertEquals($expected, $xmpp->normalize($jid)); } /** * @dataProvider domainCheckCases() + * @param $domain + * @param $expected + * @param $note */ public function testDomainCheck($domain, $expected, $note) { - $xmpp = new TestXmppPlugin(); + $xmpp = new TestXmppPlugin(); $this->assertEquals($expected, $xmpp->checkDomain($domain), $note); } @@ -68,7 +95,7 @@ class XmppValidateTest extends PHPUnit_Framework_TestCase array('example.com', true, true), array('example.com/resource', true, false), array('jabchat', true, true), - + array("$long1023@$long1023/$long1023", true, false), // max 1023 "bytes" per portion per spec. Do they really mean bytes though? array("$long1024@$long1023/$long1023", false, false), array("$long1023@$long1024/$long1023", false, false), @@ -125,7 +152,7 @@ class XmppValidateTest extends PHPUnit_Framework_TestCase //array("foo@example.com/٭simplexe٭", false, false) ); } - + static public function normalizationCases() { return array( @@ -153,19 +180,20 @@ class XmppValidateTest extends PHPUnit_Framework_TestCase } -class TestXmppPlugin extends XmppPlugin { - public function checkDomain($domain) - { - return parent::checkDomain($domain); - } - - public function validateBaseJid($jid, $check_domain=false) - { - return parent::validateBaseJid($jid, $check_domain); - } - - public function validateFullJid($jid, $check_domain=false) - { - return parent::validateFullJid($jid, $check_domain); - } -} \ No newline at end of file +class TestXmppPlugin extends XmppPlugin +{ + public function checkDomain($domain) + { + return parent::checkDomain($domain); + } + + public function validateBaseJid($jid, $check_domain = false) + { + return parent::validateBaseJid($jid, $check_domain); + } + + public function validateFullJid($jid, $check_domain = false) + { + return parent::validateFullJid($jid, $check_domain); + } +} diff --git a/tests/CurryTest.php b/tests/CurryTest.php deleted file mode 100644 index 2722a54fc5..0000000000 --- a/tests/CurryTest.php +++ /dev/null @@ -1,72 +0,0 @@ -assertEquals($expected, $result); - } - - static public function provider() - { - $obj = new CurryTestHelperObj('oldval'); - return array(array(array('CurryTest', 'callback'), - array('curried'), - array('called'), - 'called|curried'), - array(array('CurryTest', 'callback'), - array('curried1', 'curried2'), - array('called1', 'called2'), - 'called1|called2|curried1|curried2'), - array(array('CurryTest', 'callbackObj'), - array($obj), - array('newval1'), - 'oldval|newval1'), - // Confirm object identity is retained... - array(array('CurryTest', 'callbackObj'), - array($obj), - array('newval2'), - 'newval1|newval2')); - } - - static function callback() - { - $args = func_get_args(); - return implode("|", $args); - } - - static function callbackObj($val, $obj) - { - $old = $obj->val; - $obj->val = $val; - return "$old|$val"; - } -} - -class CurryTestHelperObj -{ - public $val=''; - - function __construct($val) - { - $this->val = $val; - } -} diff --git a/tests/HashTagDetectionTests.php b/tests/HashTagDetectionTests.php deleted file mode 100644 index 1fbc98983d..0000000000 --- a/tests/HashTagDetectionTests.php +++ /dev/null @@ -1,63 +0,0 @@ -assertEquals($expected, $rendered); - } - - static public function provider() - { - return array( - array('hello', - 'hello'), - array('#hello people', - '# people'), - array('"#hello" people', - '"#" people'), - array('say "#hello" people', - 'say "#" people'), - array('say (#hello) people', - 'say (#) people'), - array('say [#hello] people', - 'say [#] people'), - array('say {#hello} people', - 'say {#} people'), - array('say \'#hello\' people', - 'say \'#\' people'), - - // Unicode legit letters - array('#éclair yummy', - '# yummy'), - array('#维基百科 zh.wikipedia!', - '# zh.wikipedia!'), - array('#Россия russia', - '# russia'), - - // Unicode punctuators -- the ideographic "," separates the tag, just as "," does - array('#维基百科,zh.wikipedia!', - '#,zh.wikipedia!'), - array('#维基百科,zh.wikipedia!', - '#,zh.wikipedia!'), - - ); - } -} - diff --git a/tests/LocationTest.php b/tests/LocationTest.php deleted file mode 100644 index f7df271b53..0000000000 --- a/tests/LocationTest.php +++ /dev/null @@ -1,89 +0,0 @@ -assertEquals($result, $location); - } - - static public function locationNames() - { - return array(array('Montreal', 'en', null), - array('San Francisco, CA', 'en', null), - array('Paris, France', 'en', null), - array('Paris, Texas', 'en', null)); - } - - /** - * @dataProvider locationIds - */ - - public function testLocationFromId($id, $ns, $language, $location) - { - $result = Location::fromId($id, $ns, $language); - $this->assertEquals($result, $location); - } - - static public function locationIds() - { - return array(array(6077243, GeonamesPlugin::LOCATION_NS, 'en', null), - array(5391959, GeonamesPlugin::LOCATION_NS, 'en', null)); - } - - /** - * @dataProvider locationLatLons - */ - - public function testLocationFromLatLon($lat, $lon, $language, $location) - { - $result = Location::fromLatLon($lat, $lon, $language); - $this->assertEquals($location, $result->location_id); - } - - static public function locationLatLons() - { - return array(array(37.77493, -122.41942, 'en', null), - array(45.509, -73.588, 'en', null)); - } - - /** - * @dataProvider nameOfLocation - */ - - public function testLocationGetName($location, $language, $name) - { - $result = empty($location)?null:$location->getName($language); - $this->assertEquals($name, $result); - } - - static public function nameOfLocation() - { - $loc = Location::fromName('Montreal', 'en'); - return array(array($loc, 'en', null), //'Montreal'), - array($loc, 'fr', null));//'Montréal')); - } -} - diff --git a/tests/MediaFileTest.php b/tests/Media/MediaFileTest.php similarity index 68% rename from tests/MediaFileTest.php rename to tests/Media/MediaFileTest.php index 1e4a3c9dbb..cd28941896 100644 --- a/tests/MediaFileTest.php +++ b/tests/Media/MediaFileTest.php @@ -1,17 +1,40 @@ . -if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { - print "This script must be run from the command line\n"; - exit(); +namespace Tests\Unit; + +if (!defined('INSTALLDIR')) { + define('INSTALLDIR', dirname(dirname(__DIR__))); +} +if (!defined('GNUSOCIAL')) { + define('GNUSOCIAL', true); +} +if (!defined('STATUSNET')) { // Compatibility + define('STATUSNET', true); } -define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); -define('GNUSOCIAL', true); -define('STATUSNET', true); // compatibility +use ClientException; +use Exception; +use MediaFile; +use PHPUnit\Framework\TestCase; +use ServerException; require_once INSTALLDIR . '/lib/common.php'; -class MediaFileTest extends PHPUnit_Framework_TestCase +final class MediaFileTest extends TestCase { public function setup() @@ -27,7 +50,10 @@ class MediaFileTest extends PHPUnit_Framework_TestCase /** * @dataProvider fileTypeCases - * + * @param $filename + * @param $expectedType + * @throws ClientException + * @throws ServerException */ public function testMimeType($filename, $expectedType) { @@ -41,7 +67,10 @@ class MediaFileTest extends PHPUnit_Framework_TestCase /** * @dataProvider fileTypeCases - * + * @param $filename + * @param $expectedType + * @throws ClientException + * @throws ServerException */ public function testUploadedMimeType($filename, $expectedType) { diff --git a/tests/sample-uploads/image.gif b/tests/Media/sample-uploads/image.gif similarity index 100% rename from tests/sample-uploads/image.gif rename to tests/Media/sample-uploads/image.gif diff --git a/tests/sample-uploads/image.jpeg b/tests/Media/sample-uploads/image.jpeg similarity index 100% rename from tests/sample-uploads/image.jpeg rename to tests/Media/sample-uploads/image.jpeg diff --git a/tests/sample-uploads/image.jpg b/tests/Media/sample-uploads/image.jpg similarity index 100% rename from tests/sample-uploads/image.jpg rename to tests/Media/sample-uploads/image.jpg diff --git a/tests/sample-uploads/image.png b/tests/Media/sample-uploads/image.png similarity index 100% rename from tests/sample-uploads/image.png rename to tests/Media/sample-uploads/image.png diff --git a/tests/sample-uploads/office.pdf b/tests/Media/sample-uploads/office.pdf similarity index 100% rename from tests/sample-uploads/office.pdf rename to tests/Media/sample-uploads/office.pdf diff --git a/tests/sample-uploads/presentation.odp b/tests/Media/sample-uploads/presentation.odp similarity index 100% rename from tests/sample-uploads/presentation.odp rename to tests/Media/sample-uploads/presentation.odp diff --git a/tests/sample-uploads/presentation.otp b/tests/Media/sample-uploads/presentation.otp similarity index 100% rename from tests/sample-uploads/presentation.otp rename to tests/Media/sample-uploads/presentation.otp diff --git a/tests/sample-uploads/presentation.pot b/tests/Media/sample-uploads/presentation.pot similarity index 100% rename from tests/sample-uploads/presentation.pot rename to tests/Media/sample-uploads/presentation.pot diff --git a/tests/sample-uploads/presentation.potm b/tests/Media/sample-uploads/presentation.potm similarity index 100% rename from tests/sample-uploads/presentation.potm rename to tests/Media/sample-uploads/presentation.potm diff --git a/tests/sample-uploads/presentation.ppt b/tests/Media/sample-uploads/presentation.ppt similarity index 100% rename from tests/sample-uploads/presentation.ppt rename to tests/Media/sample-uploads/presentation.ppt diff --git a/tests/sample-uploads/presentation.pptx b/tests/Media/sample-uploads/presentation.pptx similarity index 100% rename from tests/sample-uploads/presentation.pptx rename to tests/Media/sample-uploads/presentation.pptx diff --git a/tests/sample-uploads/spreadsheet.ods b/tests/Media/sample-uploads/spreadsheet.ods similarity index 100% rename from tests/sample-uploads/spreadsheet.ods rename to tests/Media/sample-uploads/spreadsheet.ods diff --git a/tests/sample-uploads/spreadsheet.ots b/tests/Media/sample-uploads/spreadsheet.ots similarity index 100% rename from tests/sample-uploads/spreadsheet.ots rename to tests/Media/sample-uploads/spreadsheet.ots diff --git a/tests/sample-uploads/spreadsheet.xls b/tests/Media/sample-uploads/spreadsheet.xls similarity index 100% rename from tests/sample-uploads/spreadsheet.xls rename to tests/Media/sample-uploads/spreadsheet.xls diff --git a/tests/sample-uploads/spreadsheet.xlsx b/tests/Media/sample-uploads/spreadsheet.xlsx similarity index 100% rename from tests/sample-uploads/spreadsheet.xlsx rename to tests/Media/sample-uploads/spreadsheet.xlsx diff --git a/tests/sample-uploads/spreadsheet.xlt b/tests/Media/sample-uploads/spreadsheet.xlt similarity index 100% rename from tests/sample-uploads/spreadsheet.xlt rename to tests/Media/sample-uploads/spreadsheet.xlt diff --git a/tests/sample-uploads/wordproc.doc b/tests/Media/sample-uploads/wordproc.doc similarity index 100% rename from tests/sample-uploads/wordproc.doc rename to tests/Media/sample-uploads/wordproc.doc diff --git a/tests/sample-uploads/wordproc.docx b/tests/Media/sample-uploads/wordproc.docx similarity index 100% rename from tests/sample-uploads/wordproc.docx rename to tests/Media/sample-uploads/wordproc.docx diff --git a/tests/sample-uploads/wordproc.odt b/tests/Media/sample-uploads/wordproc.odt similarity index 100% rename from tests/sample-uploads/wordproc.odt rename to tests/Media/sample-uploads/wordproc.odt diff --git a/tests/sample-uploads/wordproc.ott b/tests/Media/sample-uploads/wordproc.ott similarity index 100% rename from tests/sample-uploads/wordproc.ott rename to tests/Media/sample-uploads/wordproc.ott diff --git a/tests/sample-uploads/wordproc.rtf b/tests/Media/sample-uploads/wordproc.rtf similarity index 100% rename from tests/sample-uploads/wordproc.rtf rename to tests/Media/sample-uploads/wordproc.rtf diff --git a/tests/NicknameTest.php b/tests/NicknameTest.php deleted file mode 100644 index 2841398a65..0000000000 --- a/tests/NicknameTest.php +++ /dev/null @@ -1,116 +0,0 @@ -getMessage(); - } else { - $stuff = var_export($exception, true); - } - $this->assertTrue($exception && $exception instanceof $expectedException, - "invalid input '$input' expected to fail with $expectedException, " . - "got $stuff"); - } else { - $this->assertTrue($normalized == false, - "invalid input '$input' expected to fail"); - } - } else { - $msg = "normalized input nickname '$input' expected to normalize to '$expected', got "; - if ($exception) { - $msg .= get_class($exception) . ': ' . $exception->getMessage(); - } else { - $msg .= "'$normalized'"; - } - $this->assertEquals($expected, $normalized, $msg); - } - } - - /** - * Test on the regex matching used in common_find_mentions - * (testing on the full notice rendering is difficult as it needs - * to be able to pull from global state) - * - * @dataProvider provider - */ - public function testAtReply($input, $expected, $expectedException=null) - { - if ($expected == false) { - // nothing to do - } else { - $text = "@{$input} awesome! :)"; - $matches = common_find_mentions_raw($text); - $this->assertEquals(1, count($matches)); - $this->assertEquals($expected, Nickname::normalize($matches[0][0])); - } - } - - static public function provider() - { - return array( - array('evan', 'evan'), - - // Case and underscore variants - array('Evan', 'evan'), - array('EVAN', 'evan'), - array('ev_an', 'evan'), - array('E__V_an', 'evan'), - array('evan1', 'evan1'), - array('evan_1', 'evan1'), - array('0x20', '0x20'), - array('1234', '1234'), // should this be allowed though? :) - array('12__34', '1234'), - - // Some (currently) invalid chars... - array('^#@&^#@', false, 'NicknameInvalidException'), // all invalid :D - array('ev.an', false, 'NicknameInvalidException'), - array('ev/an', false, 'NicknameInvalidException'), - array('ev an', false, 'NicknameInvalidException'), - array('ev-an', false, 'NicknameInvalidException'), - - // Non-ASCII letters; currently not allowed, in future - // we'll add them at least with conversion to ASCII. - // Not much use until we have storage of display names, - // though. - array('évan', false, 'NicknameInvalidException'), // so far... - array('Évan', false, 'NicknameInvalidException'), // so far... - - // Length checks - array('', false, 'NicknameEmptyException'), - array('___', false, 'NicknameEmptyException'), - array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), // 64 chars - array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_', false, 'NicknameTooLongException'), // the _ is too long... - array('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', false, 'NicknameTooLongException'), // 65 chars -- too long - ); - } -} diff --git a/tests/TagURITest.php b/tests/TagURITest.php deleted file mode 100644 index ccc80b8064..0000000000 --- a/tests/TagURITest.php +++ /dev/null @@ -1,37 +0,0 @@ -assertEquals($uri, $minted); - } - - static public function provider() - { - return array(array('favorite:%d:%d', - array(1, 3), - 'tag:example.net,'.date('Y-m-d').':apps:statusnet:favorite:1:3')); - } -} - diff --git a/tests/URLDetectionTest.php b/tests/URLDetectionTest.php deleted file mode 100644 index 6d0771d101..0000000000 --- a/tests/URLDetectionTest.php +++ /dev/null @@ -1,355 +0,0 @@ -assertEquals($expected, $rendered); - } - - /** - * @dataProvider linkifyProvider - * - */ - public function testLinkifyProduction($content, $expected, $config) - { - $rendered = common_render_text($content); - // hack! - $rendered = preg_replace('/id="attachment-\d+"/', 'id="attachment-XXX"', $rendered); - if(common_config('linkify', $config)){ - $this->assertEquals($expected, $rendered); - } else { - $content = common_remove_unicode_formatting(nl2br(htmlspecialchars($content))); - $this->assertEquals($content, $rendered); - } - } - - static public function provider() - { - return array( - array('not a link :: no way', - 'not a link :: no way'), - array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link', - 'link http://www.somesite.com/xyz/35637563@N00/52803365/ link'), - array('http://127.0.0.1', - 'http://127.0.0.1'), - array('http://[::1]:99/test.php', - 'http://[::1]:99/test.php'), - array('http://::1/test.php', - 'http://::1/test.php'), - array('http://::1', - 'http://::1'), - array('http://127.0.0.1', - 'http://127.0.0.1'), - array('http://example.com', - 'http://example.com'), - array('http://example.com.', - 'http://example.com.'), - array('/var/lib/example.so', - '/var/lib/example.so'), - array('example', - 'example'), - array('mailto:user@example.com', - 'mailto:user@example.com'), - array('mailto:user@example.com?subject=test', - 'mailto:user@example.com?subject=test'), - array('xmpp:user@example.com', - 'xmpp:user@example.com'), - array('#example', - '#'), - array('#example.com', - '#'), - array('#.net', - '#'), - array('http://example', - 'http://example'), - array('http://3xampl3', - 'http://3xampl3'), - array('http://example/', - 'http://example/'), - array('http://example/path', - 'http://example/path'), - array('http://example.com', - 'http://example.com'), - array('https://example.com', - 'https://example.com'), - array('ftp://example.com', - 'ftp://example.com'), - array('ftps://example.com', - 'ftps://example.com'), - array('http://user@example.com', - 'http://user@example.com'), - array('http://user:pass@example.com', - 'http://user:pass@example.com'), - array('http://example.com:8080', - 'http://example.com:8080'), - array('http://example.com:8080/test.php', - 'http://example.com:8080/test.php'), - array('http://www.example.com', - 'http://www.example.com'), - array('http://example.com/', - 'http://example.com/'), - array('http://example.com/path', - 'http://example.com/path'), - array('http://example.com/path.html', - 'http://example.com/path.html'), - array('http://example.com/path.html#fragment', - 'http://example.com/path.html#fragment'), - array('http://example.com/path.php?foo=bar&bar=foo', - 'http://example.com/path.php?foo=bar&bar=foo'), - array('http://example.com.', - 'http://example.com.'), - array('http://müllärör.de', - 'http://müllärör.de'), - array('http://ﺱﺲﺷ.com', - 'http://ﺱﺲﺷ.com'), - array('http://сделаткартинки.com', - 'http://сделаткартинки.com'), - array('http://tūdaliņ.lv', - 'http://tūdaliņ.lv'), - array('http://brændendekærlighed.com', - 'http://brændendekærlighed.com'), - array('http://あーるいん.com', - 'http://あーるいん.com'), - array('http://예비교사.com', - 'http://예비교사.com'), - array('http://example.com.', - 'http://example.com.'), - array('http://example.com?', - 'http://example.com?'), - array('http://example.com!', - 'http://example.com!'), - array('http://example.com,', - 'http://example.com,'), - array('http://example.com;', - 'http://example.com;'), - array('http://example.com:', - 'http://example.com:'), - array('\'http://example.com\'', - '\'http://example.com\''), - array('"http://example.com"', - '"http://example.com"'), - array('"http://example.com/"', - '"http://example.com/"'), - array('http://example.com', - 'http://example.com'), - array('(http://example.com)', - '(http://example.com)'), - array('[http://example.com]', - '[http://example.com]'), - array('', - '<http://example.com>'), - array('http://example.com/path/(foo)/bar', - 'http://example.com/path/(foo)/bar'), - array('http://example.com/path/[foo]/bar', - 'http://example.com/path/[foo]/bar'), - array('http://example.com/path/foo/(bar)', - 'http://example.com/path/foo/(bar)'), - //Not a valid url - urls cannot contain unencoded square brackets - array('http://example.com/path/foo/[bar]', - 'http://example.com/path/foo/[bar]'), - array('Hey, check out my cool site http://example.com okay?', - 'Hey, check out my cool site http://example.com okay?'), - array('What about parens (e.g. http://example.com/path/foo/(bar))?', - 'What about parens (e.g. http://example.com/path/foo/(bar))?'), - array('What about parens (e.g. http://example.com/path/foo/(bar)?', - 'What about parens (e.g. http://example.com/path/foo/(bar)?'), - array('What about parens (e.g. http://example.com/path/foo/(bar).)?', - 'What about parens (e.g. http://example.com/path/foo/(bar).)?'), - //Not a valid url - urls cannot contain unencoded commas - array('What about parens (e.g. http://example.com/path/(foo,bar)?', - 'What about parens (e.g. http://example.com/path/(foo,bar)?'), - array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?', - 'Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?'), - array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?', - 'Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?'), - array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?', - 'Unbalanced too (e.g. http://example.com/path/foo/((((bar)?'), - array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?', - 'Unbalanced too (e.g. http://example.com/path/foo/(bar))))?'), - array('file.ext', - 'file.ext'), - array('file.html', - 'file.html'), - array('file.php', - 'file.php'), - - // scheme-less HTTP URLs with @ in the path: http://status.net/open-source/issues/2248 - array('http://flickr.com/photos/34807140@N05/3838905434', - 'http://flickr.com/photos/34807140@N05/3838905434'), - ); - } - - static public function linkifyProvider() - { - return array( - //bare ip addresses are no longer supported - array('127.0.0.1', - '127.0.0.1', - 'bare_ipv4'), - array('127.0.0.1:99', - '127.0.0.1:99', - 'bare_ipv4'), - array('127.0.0.1/Name:test.php', - '127.0.0.1/Name:test.php', - 'bare_ipv4'), - array('127.0.0.1/~test', - '127.0.0.1/~test', - 'bare_ipv4'), - array('127.0.0.1/+test', - '127.0.0.1/+test', - 'bare_ipv4'), - array('127.0.0.1/$test', - '127.0.0.1/$test', - 'bare_ipv4'), - array('127.0.0.1/\'test', - '127.0.0.1/\'test', - 'bare_ipv4'), - array('127.0.0.1/"test', - '127.0.0.1/"test', - 'bare_ipv4'), - array('127.0.0.1/test"test', - '127.0.0.1/test"test', - 'bare_ipv4'), - array('127.0.0.1/-test', - '127.0.0.1/-test', - 'bare_ipv4'), - array('127.0.0.1/_test', - '127.0.0.1/_test', - 'bare_ipv4'), - array('127.0.0.1/!test', - '127.0.0.1/!test', - 'bare_ipv4'), - array('127.0.0.1/*test', - '127.0.0.1/*test', - 'bare_ipv4'), - array('127.0.0.1/test%20stuff', - '127.0.0.1/test%20stuff', - 'bare_ipv4'), - array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', - '2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php', - 'bare_ipv6'), - array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', - '[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php', - 'bare_ipv6'), - array('2001:4978:1b5:0:21d:e0ff:fe66:59ab', - '2001:4978:1b5:0:21d:e0ff:fe66:59ab', - 'bare_ipv6'), - array('example.com', - 'example.com', - 'bare_domains'), - array('flickr.com/photos/34807140@N05/3838905434', - 'flickr.com/photos/34807140@N05/3838905434', - 'bare_domains'), - array('What about parens (e.g. example.com/path/foo/(bar))?', - 'What about parens (e.g. example.com/path/foo/(bar))?', - 'bare_domains'), - array('What about parens (e.g. example.com/path/foo/(bar)?', - 'What about parens (e.g. example.com/path/foo/(bar)?', - 'bare_domains'), - array('What about parens (e.g. example.com/path/foo/(bar).)?', - 'What about parens (e.g. example.com/path/foo/(bar).?', - 'bare_domains'), - array('What about parens (e.g. example.com/path/(foo,bar)?', - 'What about parens (e.g. example.com/path/(foo,bar)?', - 'bare_domains'), - array('example.com', - 'example.com', - 'bare_domains'), - array('example.org', - 'example.org', - 'bare_domains'), - array('example.co.uk', - 'example.co.uk', - 'bare_domains'), - array('www.example.co.uk', - 'www.example.co.uk', - 'bare_domains'), - array('farm1.images.example.co.uk', - 'farm1.images.example.co.uk', - 'bare_domains'), - array('example.museum', - 'example.museum', - 'bare_domains'), - array('example.travel', - 'example.travel', - 'bare_domains'), - array('example.com.', - 'example.com.', - 'bare_domains'), - array('example.com?', - 'example.com?', - 'bare_domains'), - array('example.com!', - 'example.com!', - 'bare_domains'), - array('example.com,', - 'example.com,', - 'bare_domains'), - array('example.com;', - 'example.com;', - 'bare_domains'), - array('example.com:', - 'example.com:', - 'bare_domains'), - array('\'example.com\'', - '\'example.com\'', - 'bare_domains'), - array('"example.com"', - '"example.com"', - 'bare_domains'), - array('example.com', - 'example.com', - 'bare_domains'), - array('(example.com)', - '(example.com)', - 'bare_domains'), - array('[example.com]', - '[example.com]', - 'bare_domains'), - array('', - '<example.com>', - 'bare_domains'), - array('Hey, check out my cool site example.com okay?', - 'Hey, check out my cool site example.com okay?', - 'bare_domains'), - array('Hey, check out my cool site example.com.I made it.', - 'Hey, check out my cool site example.com.I made it.', - 'bare_domains'), - array('Hey, check out my cool site example.com.Funny thing...', - 'Hey, check out my cool site example.com.Funny thing...', - 'bare_domains'), - array('Hey, check out my cool site example.com.You will love it.', - 'Hey, check out my cool site example.com.You will love it.', - 'bare_domains'), - array('example.com:8080/test.php', - 'example.com:8080/test.php', - 'bare_domains'), - array('user_name+other@example.com', - 'user_name+other@example.com', - 'bare_domains'), - array('user@example.com', - 'user@example.com', - 'bare_domains'), - ); - } -} - diff --git a/tests/UUIDTest.php b/tests/UUIDTest.php deleted file mode 100644 index ce330d7ac6..0000000000 --- a/tests/UUIDTest.php +++ /dev/null @@ -1,38 +0,0 @@ -assertRegExp('/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/', - $result); - // Check version number - $this->assertEquals(0x4000, hexdec(substr($result, 14, 4)) & 0xF000); - $this->assertEquals(0x8000, hexdec(substr($result, 19, 4)) & 0xC000); - } - - public function testUnique() - { - $reps = 100; - $ids = array(); - - for ($i = 0; $i < $reps; $i++) { - $ids[] = UUID::gen(); - } - - $this->assertEquals(count($ids), count(array_unique($ids)), "UUIDs must be unique"); - } -} -