[CORE] Make tests great gain

This commit is contained in:
Diogo Cordeiro 2019-07-12 16:31:14 +01:00
parent 39845444cc
commit 9f30c299ee
51 changed files with 1507 additions and 1151 deletions

64
composer.lock generated
View File

@ -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",

View File

@ -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) {

View File

@ -1,25 +1,28 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008-2010, StatusNet, Inc.
*
* 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 <http://www.gnu.org/licenses/>.
*/
// 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 <http://www.gnu.org/licenses/>.
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';

View File

@ -1,35 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* utilities for defining and running event handlers
*
* PHP version 5
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Event
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @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 <http://www.gnu.org/licenses/>.
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 <evan@status.net>
* @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 */

View File

@ -1,24 +1,20 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009-2010 StatusNet, Inc.
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
// 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 <http://www.gnu.org/licenses/>.
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)

View File

@ -1,34 +1,33 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* 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 <http://www.gnu.org/licenses/>.
*
* @category I18n
* @package GNU social
* @author Matthew Gregg <matthew.gregg@gmail.com>
* @author Ciaran Gultnieks <ciaran@ciarang.com>
* @author Evan Prodromou <evan@status.net>
* @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 <matthew.gregg@gmail.com>
* @author Ciaran Gultnieks <ciaran@ciarang.com>
* @author Evan Prodromou <evan@status.net>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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.

View File

@ -1,35 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Utility class for plugins
*
* PHP version 5
*
* 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 <http://www.gnu.org/licenses/>.
*
* @category Plugin
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @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 <http://www.gnu.org/licenses/>.
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 <evan@status.net>
* @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()

View File

@ -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)
{

26
phpunit.xml Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Core">
<directory suffix="Test.php">./tests/Core</directory>
</testsuite>
<testsuite name="Media">
<directory suffix="Test.php">./tests/Media</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
</phpunit>

View File

@ -1,19 +1,49 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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)); // <activity: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 = '<?xml version="1.0" encoding="utf-8"?>'."\n\n";
$xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n\n";
$xml .= '<feed';
if ($namespace) {
$xml .= ' xmlns="http://www.w3.org/2005/Atom"';
@ -558,7 +588,8 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
$xml .= ' xmlns:statusnet="http://status.net/schema/api/1/"';
}
$xml .= '>' . "\n" . $entry . "\n" . '</feed>' . "\n";
$doc = DOMDocument::loadXML($xml);
$doc = new DOMDocument();
$doc->loadXML($xml);
$feed = $doc->documentElement;
$entries = $feed->getElementsByTagName('entry');

View File

@ -1,24 +1,48 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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 <content type="html"> correctly with a typical payload?
$this->assertEquals("<p>Geraldine posted a Photo on PhotoPanic</p>\n " .
"<img src=\"/geraldine/photo1.jpg\">", trim($act->content));
"<img src=\"/geraldine/photo1.jpg\">", 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,
'@<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>');
'@<span class="vcard"><a href="http://example.net/user/1" class="url"><span class="fn nickname">evan</span></a></span> now is the time for all good men to come to the aid of their country. #<span class="tag"><a href="http://example.net/tag/thetime" rel="tag">thetime</a></span>');
$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("<content>Some regular plain text.</content>",
"Some regular plain text."),
array("<content>&lt;b&gt;this is not HTML&lt;/b&gt;</content>",
"&lt;b&gt;this is not HTML&lt;/b&gt;"),
array("<content type='html'>Some regular plain HTML.</content>",
"Some regular plain HTML."),
array("<content type='html'>&lt;b&gt;this is too HTML&lt;/b&gt;</content>",
"<b>this is too HTML</b>"),
array("<content type='html'>&amp;lt;b&amp;gt;but this is not HTML!&amp;lt;/b&amp;gt;</content>",
"&lt;b&gt;but this is not HTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
"Some regular plain XHTML."),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is some XHTML!</b></div></content>",
"<b>This is some XHTML!</b>"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML!&lt;/b&gt;</div></content>",
"&lt;b&gt;This is not some XHTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;</div></content>",
"&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;"));
"Some regular plain text."),
array("<content>&lt;b&gt;this is not HTML&lt;/b&gt;</content>",
"&lt;b&gt;this is not HTML&lt;/b&gt;"),
array("<content type='html'>Some regular plain HTML.</content>",
"Some regular plain HTML."),
array("<content type='html'>&lt;b&gt;this is too HTML&lt;/b&gt;</content>",
"<b>this is too HTML</b>"),
array("<content type='html'>&amp;lt;b&amp;gt;but this is not HTML!&amp;lt;/b&amp;gt;</content>",
"&lt;b&gt;but this is not HTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>Some regular plain XHTML.</div></content>",
"Some regular plain XHTML."),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><b>This is some XHTML!</b></div></content>",
"<b>This is some XHTML!</b>"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&lt;b&gt;This is not some XHTML!&lt;/b&gt;</div></content>",
"&lt;b&gt;This is not some XHTML!&lt;/b&gt;"),
array("<content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'>&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;</div></content>",
"&amp;lt;b&amp;gt;This is not some XHTML either!&amp;lt;/b&amp;gt;"));
foreach ($tests as $data) {
list($source, $output) = $data;
$xml = "<entry xmlns='http://www.w3.org/2005/Atom'>" .
"<id>http://example.com/fakeid</id>" .
"<author><name>Test</name></author>" .
"<title>Atom content tests</title>" .
$source .
"</entry>";
$dom = DOMDocument::loadXML($xml);
"<id>http://example.com/fakeid</id>" .
"<author><name>Test</name></author>" .
"<title>Atom content tests</title>" .
$source .
"</entry>";
$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("<content:encoded>Some regular plain HTML.</content:encoded>",
"Some regular plain HTML."),
array("<content:encoded>Some &lt;b&gt;exciting bold HTML&lt;/b&gt;</content:encoded>",
"Some <b>exciting bold HTML</b>"),
array("<content:encoded>Some &amp;lt;b&amp;gt;escaped non-HTML.&amp;lt;/b&amp;gt;</content:encoded>",
"Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;"),
array("<description>Some plain text.</description>",
"Some plain text."),
array("<description>Some &lt;b&gt;non-HTML text&lt;/b&gt;</description>",
"Some &lt;b&gt;non-HTML text&lt;/b&gt;"),
array("<description>Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;</description>",
"Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;"));
"Some regular plain HTML."),
array("<content:encoded>Some &lt;b&gt;exciting bold HTML&lt;/b&gt;</content:encoded>",
"Some <b>exciting bold HTML</b>"),
array("<content:encoded>Some &amp;lt;b&amp;gt;escaped non-HTML.&amp;lt;/b&amp;gt;</content:encoded>",
"Some &lt;b&gt;escaped non-HTML.&lt;/b&gt;"),
array("<description>Some plain text.</description>",
"Some plain text."),
array("<description>Some &lt;b&gt;non-HTML text&lt;/b&gt;</description>",
"Some &lt;b&gt;non-HTML text&lt;/b&gt;"),
array("<description>Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;</description>",
"Some &amp;lt;b&amp;gt;double-escaped text&amp;lt;/b&amp;gt;"));
foreach ($tests as $data) {
list($source, $output) = $data;
$xml = "<item xmlns:content='http://purl.org/rss/1.0/modules/content/'>" .
"<guid>http://example.com/fakeid</guid>" .
"<title>RSS content tests</title>" .
$source .
"</item>";
$dom = DOMDocument::loadXML($xml);
"<guid>http://example.com/fakeid</guid>" .
"<title>RSS content tests</title>" .
$source .
"</item>";
$dom = new DOMDocument();
$dom->loadXML($xml);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));

View File

@ -0,0 +1,91 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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;
}
}

View File

@ -1,23 +1,46 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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'),

View File

@ -0,0 +1,83 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span> people'),
array('"#hello" people',
'&quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
array('say "#hello" people',
'say &quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
array('say (#hello) people',
'say (#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>) people'),
array('say [#hello] people',
'say [#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>] people'),
array('say {#hello} people',
'say {#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>} people'),
array('say \'#hello\' people',
'say \'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>\' people'),
// Unicode legit letters
array('#éclair yummy',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('éclair'))) . '" rel="tag">éclair</a></span> yummy'),
array('#维基百科 zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span> zh.wikipedia!'),
array('#Россия russia',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('Россия'))) . '" rel="tag">Россия</a></span> russia'),
// Unicode punctuators -- the ideographic "" separates the tag, just as "," does
array('#维基百科,zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
array('#维基百科zh.wikipedia!',
'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>zh.wikipedia!'),
);
}
}

124
tests/Core/LocationTest.php Normal file
View File

@ -0,0 +1,124 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
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);