Merge pull request #1575 from ArthurHoaro/feature/php8

This commit is contained in:
ArthurHoaro 2020-10-03 12:59:16 +02:00 committed by GitHub
commit 7b18876361
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
115 changed files with 690 additions and 785 deletions

View file

@ -3,6 +3,14 @@ dist: bionic
matrix:
include:
# jobs for each supported php version
- language: php
php: nightly # PHP 8.0
install:
- composer self-update --2
- composer update --ignore-platform-req=php
- composer remove --dev --ignore-platform-req=php phpunit/phpunit
- composer require --dev --ignore-platform-req=php phpunit/php-text-template ^2.0
- composer require --dev --ignore-platform-req=php phpunit/phpunit ^9.0
- language: php
php: 7.4
- language: php

View file

@ -46,7 +46,7 @@ class ConfigJson implements ConfigIO
// JSON_PRETTY_PRINT is available from PHP 5.4.
$print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
$data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
if (!file_put_contents($filepath, $data)) {
if (empty($filepath) || !file_put_contents($filepath, $data)) {
throw new \Shaarli\Exceptions\IOException(
$filepath,
t('Shaarli could not create the config file. '.

View file

@ -27,9 +27,8 @@
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpcov": "*",
"phpunit/phpunit": "^7.5 || ^8.0",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
},
"suggest": {
"ext-curl": "Allows fetching web pages and thumbnails in a more robust way",

805
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ require_once 'tests/utils/FakeApplicationUtils.php';
/**
* Unitary tests for Shaarli utilities
*/
class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
class ApplicationUtilsTest extends \Shaarli\TestCase
{
protected static $testUpdateFile = 'sandbox/update.txt';
protected static $testVersion = '0.5.0';
@ -144,10 +144,10 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
/**
* Test update checks - invalid Git branch
* @expectedException Exception
*/
public function testCheckUpdateInvalidGitBranch()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid branch selected for updates/');
ApplicationUtils::checkUpdate('', 'null', 0, true, true, 'unstable');
@ -261,10 +261,10 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
/**
* Check a unsupported PHP version
* @expectedException Exception
*/
public function testCheckSupportedPHPVersion51()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
$this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.1.0'));
@ -272,10 +272,10 @@ class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
/**
* Check another unsupported PHP version
* @expectedException Exception
*/
public function testCheckSupportedPHPVersion52()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Your PHP version is obsolete/');
$this->assertTrue(ApplicationUtils::checkPHPVersion('5.3', '5.2'));

View file

@ -9,7 +9,7 @@ use Exception;
*
* Test file utility class.
*/
class FileUtilsTest extends \PHPUnit\Framework\TestCase
class FileUtilsTest extends \Shaarli\TestCase
{
/**
* @var string Test file path.

View file

@ -3,10 +3,9 @@
namespace Shaarli;
use DateTime;
use Exception;
use Shaarli\Bookmark\Bookmark;
class HistoryTest extends \PHPUnit\Framework\TestCase
class HistoryTest extends \Shaarli\TestCase
{
/**
* @var string History file path

View file

@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager;
/**
* Class LanguagesTest.
*/
class LanguagesTest extends \PHPUnit\Framework\TestCase
class LanguagesTest extends \Shaarli\TestCase
{
/**
* @var string Config file path (without extension).

View file

@ -1,4 +1,5 @@
<?php
namespace Shaarli\Plugin;
use Shaarli\Config\ConfigManager;
@ -6,7 +7,7 @@ use Shaarli\Config\ConfigManager;
/**
* Unit tests for Plugins
*/
class PluginManagerTest extends \PHPUnit\Framework\TestCase
class PluginManagerTest extends \Shaarli\TestCase
{
/**
* Path to tests plugin.
@ -81,8 +82,8 @@ class PluginManagerTest extends \PHPUnit\Framework\TestCase
$data = [];
$this->pluginManager->executeHooks('error', $data);
$this->assertSame(
'test [plugin incompatibility]: Class \'Unknown\' not found',
$this->assertRegExp(
'/test \[plugin incompatibility\]: Class [\'"]Unknown[\'"] not found/',
$this->pluginManager->getErrors()[0]
);
}

77
tests/TestCase.php Normal file
View file

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Shaarli;
/**
* Helper class extending \PHPUnit\Framework\TestCase.
* Used to make Shaarli UT run on multiple versions of PHPUnit.
*/
class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* expectExceptionMessageRegExp has been removed and replaced by expectExceptionMessageMatches in PHPUnit 9.
*/
public function expectExceptionMessageRegExp(string $regularExpression): void
{
if (method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches($regularExpression);
} else {
parent::expectExceptionMessageRegExp($regularExpression);
}
}
/**
* assertContains is now used for iterable, strings should use assertStringContainsString
*/
public function assertContainsPolyfill($expected, $actual, string $message = ''): void
{
if (is_string($actual) && method_exists($this, 'assertStringContainsString')) {
static::assertStringContainsString($expected, $actual, $message);
} else {
static::assertContains($expected, $actual, $message);
}
}
/**
* assertNotContains is now used for iterable, strings should use assertStringNotContainsString
*/
public function assertNotContainsPolyfill($expected, $actual, string $message = ''): void
{
if (is_string($actual) && method_exists($this, 'assertStringNotContainsString')) {
static::assertStringNotContainsString($expected, $actual, $message);
} else {
static::assertNotContains($expected, $actual, $message);
}
}
/**
* assertFileNotExists has been renamed in assertFileDoesNotExist
*/
public static function assertFileNotExists(string $filename, string $message = ''): void
{
if (method_exists(TestCase::class, 'assertFileDoesNotExist')) {
static::assertFileDoesNotExist($filename, $message);
} else {
parent::assertFileNotExists($filename, $message);
}
}
/**
* assertRegExp has been renamed in assertMatchesRegularExpression
*/
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
{
if (method_exists(TestCase::class, 'assertMatchesRegularExpression')) {
static::assertMatchesRegularExpression($pattern, $string, $message);
} else {
parent::assertRegExp($pattern, $string, $message);
}
}
public function isInTestsContext(): bool
{
return true;
}
}

View file

@ -2,7 +2,6 @@
namespace Shaarli;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use WebThumbnailer\Application\ConfigManager as WTConfigManager;

View file

@ -8,7 +8,7 @@ require_once 'application/TimeZone.php';
/**
* Unitary tests for timezone utilities
*/
class TimeZoneTest extends PHPUnit\Framework\TestCase
class TimeZoneTest extends \Shaarli\TestCase
{
/**
* @var array of timezones

View file

@ -10,7 +10,7 @@ require_once 'application/Languages.php';
/**
* Unitary tests for Shaarli utilities
*/
class UtilsTest extends PHPUnit\Framework\TestCase
class UtilsTest extends \Shaarli\TestCase
{
// Log file
protected static $testLogFile = 'tests.log';

View file

@ -18,7 +18,7 @@ use Slim\Http\Response;
*
* @package Api
*/
class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
class ApiMiddlewareTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations
@ -26,7 +26,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
protected static $testDatastore = 'sandbox/datastore.php';
/**
* @var \ConfigManager instance
* @var ConfigManager instance
*/
protected $conf;
@ -156,7 +156,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: API is disabled', $body->message);
$this->assertContains('ApiAuthorizationException', $body->stacktrace);
$this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
@ -179,7 +179,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: JWT token not provided', $body->message);
$this->assertContains('ApiAuthorizationException', $body->stacktrace);
$this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
@ -204,7 +204,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Token secret must be set in Shaarli\'s administration', $body->message);
$this->assertContains('ApiAuthorizationException', $body->stacktrace);
$this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
@ -227,7 +227,7 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Invalid JWT header', $body->message);
$this->assertContains('ApiAuthorizationException', $body->stacktrace);
$this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
/**
@ -253,6 +253,6 @@ class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(401, $response->getStatusCode());
$body = json_decode((string) $response->getBody());
$this->assertEquals('Not authorized: Malformed JWT token', $body->message);
$this->assertContains('ApiAuthorizationException', $body->stacktrace);
$this->assertContainsPolyfill('ApiAuthorizationException', $body->stacktrace);
}
}

View file

@ -8,7 +8,7 @@ use Shaarli\Http\Base64Url;
/**
* Class ApiUtilsTest
*/
class ApiUtilsTest extends \PHPUnit\Framework\TestCase
class ApiUtilsTest extends \Shaarli\TestCase
{
/**
* Force the timezone for ISO datetimes.

View file

@ -11,7 +11,7 @@ use Slim\Http\Response;
require_once 'tests/utils/ReferenceHistory.php';
class HistoryTest extends \PHPUnit\Framework\TestCase
class HistoryTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -1,10 +1,10 @@
<?php
namespace Shaarli\Api\Controllers;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;

View file

@ -11,7 +11,7 @@ use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Http\Response;
class DeleteLinkTest extends \PHPUnit\Framework\TestCase
class DeleteLinkTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -20,7 +20,7 @@ use Slim\Http\Response;
*
* @package Shaarli\Api\Controllers
*/
class GetLinkIdTest extends \PHPUnit\Framework\TestCase
class GetLinkIdTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -20,7 +20,7 @@ use Slim\Http\Response;
*
* @package Shaarli\Api\Controllers
*/
class GetLinksTest extends \PHPUnit\Framework\TestCase
class GetLinksTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -2,11 +2,11 @@
namespace Shaarli\Api\Controllers;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
use Slim\Container;
use Slim\Http\Environment;
use Slim\Http\Request;

View file

@ -12,7 +12,7 @@ use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Http\Response;
class PutLinkTest extends \PHPUnit\Framework\TestCase
class PutLinkTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -12,7 +12,7 @@ use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Http\Response;
class DeleteTagTest extends \PHPUnit\Framework\TestCase
class DeleteTagTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -18,7 +18,7 @@ use Slim\Http\Response;
*
* @package Shaarli\Api\Controllers
*/
class GetTagNameTest extends \PHPUnit\Framework\TestCase
class GetTagNameTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -17,7 +17,7 @@ use Slim\Http\Response;
*
* @package Shaarli\Api\Controllers
*/
class GetTagsTest extends \PHPUnit\Framework\TestCase
class GetTagsTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -12,7 +12,7 @@ use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Http\Response;
class PutTagTest extends \PHPUnit\Framework\TestCase
class PutTagTest extends \Shaarli\TestCase
{
/**
* @var string datastore to test write operations

View file

@ -2,10 +2,7 @@
namespace Shaarli\Bookmark;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Exception\InvalidBookmarkException;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
/**
* Class BookmarkArrayTest

View file

@ -6,7 +6,6 @@
namespace Shaarli\Bookmark;
use DateTime;
use PHPUnit\Framework\TestCase;
use ReferenceLinkDB;
use ReflectionClass;
use Shaarli;
@ -14,6 +13,7 @@ use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\BookmarkMarkdownFormatter;
use Shaarli\History;
use Shaarli\TestCase;
/**
* Unitary tests for LegacyLinkDBTest
@ -637,11 +637,10 @@ class BookmarkFileServiceTest extends TestCase
*/
/**
* Attempt to instantiate a LinkDB whereas the datastore is not writable
*
* @expectedException Shaarli\Bookmark\Exception\NotWritableDataStoreException
*/
public function testConstructDatastoreNotWriteable()
{
$this->expectException(\Shaarli\Bookmark\Exception\NotWritableDataStoreException::class);
$this->expectExceptionMessageRegExp('#Couldn\'t load data from the data store file "null".*#');
$conf = new ConfigManager('tests/utils/config/configJson');
@ -748,7 +747,7 @@ class BookmarkFileServiceTest extends TestCase
$link = $this->publicLinkDB->findByUrl('http://mediagoblin.org/');
$this->assertNotEquals(false, $link);
$this->assertContains(
$this->assertContainsPolyfill(
'A free software media publishing platform',
$link->getDescription()
);

View file

@ -3,10 +3,10 @@
namespace Shaarli\Bookmark;
use Exception;
use PHPUnit\Framework\TestCase;
use ReferenceLinkDB;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
/**
* Class BookmarkFilterTest.
@ -212,10 +212,10 @@ class BookmarkFilterTest extends TestCase
/**
* Use an invalid date format
* @expectedException Exception
*/
public function testFilterInvalidDayWithChars()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid date format/');
self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, 'Rainy day, dream away');
@ -223,10 +223,10 @@ class BookmarkFilterTest extends TestCase
/**
* Use an invalid date format
* @expectedException Exception
*/
public function testFilterInvalidDayDigits()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid date format/');
self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20');

View file

@ -2,9 +2,9 @@
namespace Shaarli\Bookmark;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
/**
* Class BookmarkInitializerTest

View file

@ -2,8 +2,8 @@
namespace Shaarli\Bookmark;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Exception\InvalidBookmarkException;
use Shaarli\TestCase;
/**
* Class BookmarkTest
@ -150,7 +150,7 @@ class BookmarkTest extends TestCase
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContains('- ID: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- ID: '. PHP_EOL, $exception->getMessage());
}
/**
@ -169,7 +169,7 @@ class BookmarkTest extends TestCase
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContains('- ID: str'. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- ID: str'. PHP_EOL, $exception->getMessage());
}
/**
@ -188,7 +188,7 @@ class BookmarkTest extends TestCase
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContains('- ShortUrl: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- ShortUrl: '. PHP_EOL, $exception->getMessage());
}
/**
@ -207,7 +207,7 @@ class BookmarkTest extends TestCase
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContains('- Created: '. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- Created: '. PHP_EOL, $exception->getMessage());
}
/**
@ -226,7 +226,7 @@ class BookmarkTest extends TestCase
$exception = $e;
}
$this->assertNotNull($exception);
$this->assertContains('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage());
$this->assertContainsPolyfill('- Created: Not a DateTime object'. PHP_EOL, $exception->getMessage());
}
/**

View file

@ -2,7 +2,7 @@
namespace Shaarli\Bookmark;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
require_once 'tests/utils/CurlUtils.php';
@ -450,13 +450,13 @@ class LinkUtilsTest extends TestCase
カタカナ #カタカナ」カタカナ\n';
$autolinkedDescription = hashtag_autolink($rawDescription, $index);
$this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
$this->assertNotContains(' #hashtag', $autolinkedDescription);
$this->assertNotContains('>#nothashtag', $autolinkedDescription);
$this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription);
$this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
$this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
$this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
$this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
$this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
$this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
$this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription);
$this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
$this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
$this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
}
/**
@ -467,9 +467,9 @@ class LinkUtilsTest extends TestCase
$rawDescription = 'blabla #hashtag x#nothashtag';
$autolinkedDescription = hashtag_autolink($rawDescription);
$this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription);
$this->assertNotContains(' #hashtag', $autolinkedDescription);
$this->assertNotContains('>#nothashtag', $autolinkedDescription);
$this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription);
$this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
$this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
}
/**

View file

@ -18,6 +18,7 @@ require_once 'application/bookmark/LinkUtils.php';
require_once 'application/Utils.php';
require_once 'application/http/UrlUtils.php';
require_once 'application/http/HttpUtils.php';
require_once 'tests/TestCase.php';
require_once 'tests/container/ShaarliTestContainer.php';
require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php';
require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php';

View file

@ -4,7 +4,7 @@ namespace Shaarli\Config;
/**
* Class ConfigJsonTest
*/
class ConfigJsonTest extends \PHPUnit\Framework\TestCase
class ConfigJsonTest extends \Shaarli\TestCase
{
/**
* @var ConfigJson
@ -42,7 +42,7 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
public function testReadInvalidJson()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp(' /An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/');
$this->expectExceptionMessageRegExp('/An error occurred while parsing JSON configuration file \\([\\w\\/\\.]+\\): error code #4/');
$this->configIO->read('tests/utils/config/configInvalid.json.php');
}
@ -108,17 +108,6 @@ class ConfigJsonTest extends \PHPUnit\Framework\TestCase
unlink($dest);
}
/**
* Write to invalid path.
*/
public function testWriteInvalidArray()
{
$this->expectException(\Shaarli\Exceptions\IOException::class);
$conf = array('conf' => 'value');
@$this->configIO->write(array(), $conf);
}
/**
* Write to invalid path.
*/

View file

@ -7,7 +7,7 @@ namespace Shaarli\Config;
* Note: it only test the manager with ConfigJson,
* ConfigPhp is only a workaround to handle the transition to JSON type.
*/
class ConfigManagerTest extends \PHPUnit\Framework\TestCase
class ConfigManagerTest extends \Shaarli\TestCase
{
/**
* @var ConfigManager

View file

@ -8,7 +8,7 @@ namespace Shaarli\Config;
* which are kept between tests.
* @runTestsInSeparateProcesses
*/
class ConfigPhpTest extends \PHPUnit\Framework\TestCase
class ConfigPhpTest extends \Shaarli\TestCase
{
/**
* @var ConfigPhp

View file

@ -9,7 +9,7 @@ require_once 'application/config/ConfigPlugin.php';
/**
* Unitary tests for Shaarli config related functions
*/
class ConfigPluginTest extends \PHPUnit\Framework\TestCase
class ConfigPluginTest extends \Shaarli\TestCase
{
/**
* Test save_plugin_config with valid data.

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Container;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
use Shaarli\Feed\FeedBuilder;
@ -20,6 +19,7 @@ use Shaarli\Render\PageCacheManager;
use Shaarli\Security\CookieManager;
use Shaarli\Security\LoginManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Shaarli\Updater\Updater;
use Slim\Http\Environment;

View file

@ -7,7 +7,7 @@ namespace Shaarli\Feed;
/**
* Unitary tests for cached pages
*/
class CachedPageTest extends \PHPUnit\Framework\TestCase
class CachedPageTest extends \Shaarli\TestCase
{
// test cache directory
protected static $testCacheDir = 'sandbox/pagecache';

View file

@ -3,7 +3,6 @@
namespace Shaarli\Feed;
use DateTime;
use PHPUnit\Framework\TestCase;
use ReferenceLinkDB;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
@ -11,6 +10,7 @@ use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\FormatterFactory;
use Shaarli\History;
use Shaarli\TestCase;
/**
* FeedBuilderTest class.
@ -97,9 +97,9 @@ class FeedBuilderTest extends TestCase
$pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
$up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
$this->assertEquals($pub, $up);
$this->assertContains('Stallman has a beard', $link['description']);
$this->assertContains('Permalink', $link['description']);
$this->assertContains('http://host.tld/shaare/WDWyig', $link['description']);
$this->assertContainsPolyfill('Stallman has a beard', $link['description']);
$this->assertContainsPolyfill('Permalink', $link['description']);
$this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
$this->assertEquals(1, count($link['taglist']));
$this->assertEquals('sTuff', $link['taglist'][0]);
@ -201,16 +201,16 @@ class FeedBuilderTest extends TestCase
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['guid']);
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
$this->assertContains('Direct link', $link['description']);
$this->assertContains('http://host.tld/shaare/WDWyig', $link['description']);
$this->assertContainsPolyfill('Direct link', $link['description']);
$this->assertContainsPolyfill('http://host.tld/shaare/WDWyig', $link['description']);
// Second link is a direct link
$link = $data['links'][array_keys($data['links'])[1]];
$this->assertEquals(8, $link['id']);
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
$this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
$this->assertContains('Direct link', $link['description']);
$this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
$this->assertContainsPolyfill('Direct link', $link['description']);
$this->assertContainsPolyfill('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
}
/**
@ -274,6 +274,6 @@ class FeedBuilderTest extends TestCase
$link = $data['links'][array_keys($data['links'])[0]];
$this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['guid']);
$this->assertEquals('http://host.tld:8080/~user/shaarli/shaare/WDWyig', $link['url']);
$this->assertContains('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
$this->assertContainsPolyfill('http://host.tld:8080/~user/shaarli/./add-tag/hashtag', $link['description']);
}
}

View file

@ -3,9 +3,9 @@
namespace Shaarli\Formatter;
use DateTime;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\TestCase;
/**
* Class BookmarkDefaultFormatterTest

View file

@ -3,9 +3,9 @@
namespace Shaarli\Formatter;
use DateTime;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\TestCase;
/**
* Class BookmarkMarkdownFormatterTest

View file

@ -3,9 +3,9 @@
namespace Shaarli\Formatter;
use DateTime;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\TestCase;
/**
* Class BookmarkRawFormatterTest

View file

@ -2,8 +2,8 @@
namespace Shaarli\Formatter;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\TestCase;
/**
* Class FormatterFactoryTest

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Container\ShaarliContainer;
use Shaarli\Security\LoginManager;
use Shaarli\TestCase;
use Shaarli\Updater\Updater;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Front;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Container\ShaarliContainer;
use Shaarli\Front\Exception\LoginBannedException;
@ -12,6 +11,7 @@ use Shaarli\Front\Exception\UnauthorizedException;
use Shaarli\Render\PageBuilder;
use Shaarli\Render\PageCacheManager;
use Shaarli\Security\LoginManager;
use Shaarli\TestCase;
use Shaarli\Updater\Updater;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Formatter\BookmarkFormatter;
use Shaarli\Formatter\BookmarkRawFormatter;
use Shaarli\Netscape\NetscapeBookmarkUtils;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UploadedFileInterface;
use Shaarli\Netscape\NetscapeBookmarkUtils;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\UploadedFile;

View file

@ -4,10 +4,9 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Security\CookieManager;
use Shaarli\Security\LoginManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Formatter\BookmarkFormatter;
@ -14,6 +13,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Formatter\BookmarkFormatter;
@ -13,6 +12,7 @@ use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
@ -96,12 +96,14 @@ class DisplayCreateFormTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_editlink'], ['render_includes'])
->willReturnCallback(function (string $hook, array $data) use ($remoteTitle, $remoteDesc): array {
static::assertSame('render_editlink', $hook);
static::assertSame($remoteTitle, $data['link']['title']);
static::assertSame($remoteDesc, $data['link']['description']);
if ('render_editlink' === $hook) {
static::assertSame($remoteTitle, $data['link']['title']);
static::assertSame($remoteDesc, $data['link']['description']);
}
return $data;
})

View file

@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Http\HttpAccess;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin\ManageShaareControllerTest;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Controller\Admin\FrontAdminControllerMockHelper;
@ -12,6 +11,7 @@ use Shaarli\Front\Controller\Admin\ManageShaareController;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Http\HttpAccess;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;
@ -88,17 +88,18 @@ class SaveBookmarkTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['save_link'])
->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
static::assertSame('save_link', $hook);
static::assertSame($id, $data['id']);
static::assertSame($parameters['lf_url'], $data['url']);
static::assertSame($parameters['lf_title'], $data['title']);
static::assertSame($parameters['lf_description'], $data['description']);
static::assertSame($parameters['lf_tags'], $data['tags']);
static::assertTrue($data['private']);
if ('save_link' === $hook) {
static::assertSame($id, $data['id']);
static::assertSame($parameters['lf_url'], $data['url']);
static::assertSame($parameters['lf_title'], $data['title']);
static::assertSame($parameters['lf_description'], $data['description']);
static::assertSame($parameters['lf_tags'], $data['tags']);
static::assertTrue($data['private']);
}
return $data;
})
@ -174,17 +175,18 @@ class SaveBookmarkTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['save_link'])
->willReturnCallback(function (string $hook, array $data) use ($parameters, $id): array {
static::assertSame('save_link', $hook);
static::assertSame($id, $data['id']);
static::assertSame($parameters['lf_url'], $data['url']);
static::assertSame($parameters['lf_title'], $data['title']);
static::assertSame($parameters['lf_description'], $data['description']);
static::assertSame($parameters['lf_tags'], $data['tags']);
static::assertTrue($data['private']);
if ('save_link' === $hook) {
static::assertSame($id, $data['id']);
static::assertSame($parameters['lf_url'], $data['url']);
static::assertSame($parameters['lf_title'], $data['title']);
static::assertSame($parameters['lf_description'], $data['description']);
static::assertSame($parameters['lf_tags'], $data['tags']);
static::assertTrue($data['private']);
}
return $data;
})

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\OpenShaarliPasswordException;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Plugin\PluginManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Security\LoginManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
/**

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Admin;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Config\ConfigManager;
use Shaarli\Security\LoginManager;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Feed\CachedPage;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
@ -78,19 +78,20 @@ class DailyControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_daily'])
->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
static::assertSame('render_daily', $hook);
if ('render_daily' === $hook) {
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(3, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame($currentDay->getTimestamp(), $data['day']);
static::assertSame('20200510', $data['previousday']);
static::assertSame('20200516', $data['nextday']);
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(3, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame($currentDay->getTimestamp(), $data['day']);
static::assertSame('20200510', $data['previousday']);
static::assertSame('20200516', $data['nextday']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -203,19 +204,20 @@ class DailyControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_daily'])
->willReturnCallback(function (string $hook, array $data, array $param) use ($currentDay): array {
static::assertSame('render_daily', $hook);
if ('render_daily' === $hook) {
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(1, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame($currentDay->getTimestamp(), $data['day']);
static::assertEmpty($data['previousday']);
static::assertEmpty($data['nextday']);
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(1, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame($currentDay->getTimestamp(), $data['day']);
static::assertEmpty($data['previousday']);
static::assertEmpty($data['nextday']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
});
@ -281,7 +283,7 @@ class DailyControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->willReturnCallback(function (string $hook, array $data, array $param): array {
return $data;
@ -333,7 +335,7 @@ class DailyControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->willReturnCallback(function (string $hook, array $data, array $param): array {
return $data;

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Front\Exception\ShaarliFrontException;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\Uri;

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Feed\FeedBuilder;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
@ -45,14 +45,16 @@ class FeedControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_feed'])
->willReturnCallback(function (string $hook, array $data, array $param): void {
static::assertSame('render_feed', $hook);
static::assertSame('data', $data['content']);
if ('render_feed' === $hook) {
static::assertSame('data', $data['content']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.rss', $param['target']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.rss', $param['target']);
}
})
;
@ -84,14 +86,16 @@ class FeedControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_feed'])
->willReturnCallback(function (string $hook, array $data, array $param): void {
static::assertSame('render_feed', $hook);
static::assertSame('data', $data['content']);
if ('render_feed' === $hook) {
static::assertSame('data', $data['content']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.atom', $param['target']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.atom', $param['target']);
}
})
;
@ -124,14 +128,16 @@ class FeedControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_feed'])
->willReturnCallback(function (string $hook, array $data, array $param): void {
static::assertSame('render_feed', $hook);
static::assertSame('data', $data['content']);
if ('render_feed' === $hook) {
static::assertSame('data', $data['content']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.atom', $param['target']);
static::assertArrayHasKey('loggedin', $param);
static::assertSame('feed.atom', $param['target']);
}
})
;

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\MockObject\MockObject;
use Shaarli\Bookmark\BookmarkServiceInterface;
use Shaarli\Config\ConfigManager;
use Shaarli\Container\ShaarliTestContainer;
@ -115,5 +114,5 @@ trait FrontControllerMockHelper
/**
* Force to be used in PHPUnit context.
*/
protected abstract function createMock($originalClassName): MockObject;
protected abstract function isInTestsContext(): bool;
}

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\AlreadyInstalledException;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\LoginBannedException;
use Shaarli\Front\Exception\WrongTokenException;
use Shaarli\Render\TemplatePage;
use Shaarli\Security\CookieManager;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\Front\Exception\ThumbnailsDisabledException;
use Shaarli\TestCase;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;
@ -67,15 +67,17 @@ class PictureWallControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_picwall'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_picwall', $hook);
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(2, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame(3, $data['linksToDisplay'][1]['id']);
static::assertArrayHasKey('loggedin', $param);
if ('render_picwall' === $hook) {
static::assertArrayHasKey('linksToDisplay', $data);
static::assertCount(2, $data['linksToDisplay']);
static::assertSame(1, $data['linksToDisplay'][0]['id']);
static::assertSame(3, $data['linksToDisplay'][1]['id']);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
});

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Security\SessionManager;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;
@ -53,14 +53,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_tagcloud'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_tagcloud', $hook);
static::assertSame('', $data['search_tags']);
static::assertCount(3, $data['tags']);
if ('render_tagcloud' === $hook) {
static::assertSame('', $data['search_tags']);
static::assertCount(3, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -124,14 +126,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_tagcloud'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_tagcloud', $hook);
static::assertSame('ghi def', $data['search_tags']);
static::assertCount(1, $data['tags']);
if ('render_tagcloud' === $hook) {
static::assertSame('ghi def', $data['search_tags']);
static::assertCount(1, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -175,14 +179,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_tagcloud'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_tagcloud', $hook);
static::assertSame('', $data['search_tags']);
static::assertCount(0, $data['tags']);
if ('render_tagcloud' === $hook) {
static::assertSame('', $data['search_tags']);
static::assertCount(0, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -227,14 +233,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_taglist'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_taglist', $hook);
static::assertSame('', $data['search_tags']);
static::assertCount(3, $data['tags']);
if ('render_taglist' === $hook) {
static::assertSame('', $data['search_tags']);
static::assertCount(3, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -297,14 +305,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_taglist'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_taglist', $hook);
static::assertSame('ghi def', $data['search_tags']);
static::assertCount(1, $data['tags']);
if ('render_taglist' === $hook) {
static::assertSame('ghi def', $data['search_tags']);
static::assertCount(1, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})
@ -344,14 +354,16 @@ class TagCloudControllerTest extends TestCase
// Make sure that PluginManager hook is triggered
$this->container->pluginManager
->expects(static::at(0))
->expects(static::atLeastOnce())
->method('executeHooks')
->withConsecutive(['render_taglist'])
->willReturnCallback(function (string $hook, array $data, array $param): array {
static::assertSame('render_taglist', $hook);
static::assertSame('', $data['search_tags']);
static::assertCount(0, $data['tags']);
if ('render_taglist' === $hook) {
static::assertSame('', $data['search_tags']);
static::assertCount(0, $data['tags']);
static::assertArrayHasKey('loggedin', $param);
static::assertArrayHasKey('loggedin', $param);
}
return $data;
})

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Front\Controller\Visitor;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
/**
* Unitary tests for client_ip_id()
*/
class ClientIpIdTest extends \PHPUnit\Framework\TestCase
class ClientIpIdTest extends \Shaarli\TestCase
{
/**
* Get a remote client ID based on its IP

View file

@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
/**
* Unitary tests for get_http_response()
*/
class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
class GetHttpUrlTest extends \Shaarli\TestCase
{
/**
* Get an invalid local URL

View file

@ -7,7 +7,7 @@ require_once 'application/http/HttpUtils.php';
/**
* Unitary tests for getIpAddressFromProxy()
*/
class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
class GetIpAdressFromProxyTest extends \Shaarli\TestCase
{
/**

View file

@ -5,7 +5,7 @@
namespace Shaarli\Http;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
require_once 'application/http/HttpUtils.php';

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Shaarli\Http;
use PHPUnit\Framework\TestCase;
use Shaarli\TestCase;
/**
* Test index_url with SHAARLI_ROOT_URL defined to override automatic retrieval.

View file

@ -9,7 +9,7 @@ require_once 'application/http/HttpUtils.php';
*
* Test class for is_https() function.
*/
class IsHttpsTest extends \PHPUnit\Framework\TestCase
class IsHttpsTest extends \Shaarli\TestCase
{
/**

View file

@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
/**
* Unitary tests for page_url()
*/
class PageUrlTest extends \PHPUnit\Framework\TestCase
class PageUrlTest extends \Shaarli\TestCase
{
/**
* If on the main page, remove "index.php" from the URL resource

View file

@ -10,7 +10,7 @@ require_once 'application/http/HttpUtils.php';
/**
* Unitary tests for server_url()
*/
class ServerUrlTest extends \PHPUnit\Framework\TestCase
class ServerUrlTest extends \Shaarli\TestCase
{
/**
* Detect if the server uses SSL

View file

@ -8,7 +8,7 @@ namespace Shaarli\Http;
/**
* Unitary tests for URL utilities
*/
class UrlTest extends \PHPUnit\Framework\TestCase
class UrlTest extends \Shaarli\TestCase
{
// base URL for tests
protected static $baseUrl = 'http://domain.tld:3000';

View file

@ -7,7 +7,7 @@ namespace Shaarli\Http;
require_once 'application/http/UrlUtils.php';
class CleanupUrlTest extends \PHPUnit\Framework\TestCase
class CleanupUrlTest extends \Shaarli\TestCase
{
/**
* @var string reference URL

View file

@ -7,7 +7,7 @@ namespace Shaarli\Http;
require_once 'application/http/UrlUtils.php';
class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase
class GetUrlSchemeTest extends \Shaarli\TestCase
{
/**
* Get empty scheme string for empty UrlUtils

View file

@ -10,7 +10,7 @@ require_once 'application/http/UrlUtils.php';
/**
* Unitary tests for unparse_url()
*/
class UnparseUrlTest extends \PHPUnit\Framework\TestCase
class UnparseUrlTest extends \Shaarli\TestCase
{
/**
* Thanks for building nothing

View file

@ -9,7 +9,7 @@ require_once 'application/http/UrlUtils.php';
*
* Test whitelist_protocols() function of UrlUtils.
*/
class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
class WhitelistProtocolsTest extends \Shaarli\TestCase
{
/**
* Test whitelist_protocols() on a note (relative URL).

View file

@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager;
*
* @package Shaarli
*/
class LanguagesFrTest extends \PHPUnit\Framework\TestCase
class LanguagesFrTest extends \Shaarli\TestCase
{
/**
* @var string Config file path (without extension).

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Shaarli\Legacy;
use PHPUnit\Framework\TestCase;
use Shaarli\Front\Controller\Visitor\FrontControllerMockHelper;
use Shaarli\TestCase;
use Slim\Http\Request;
use Slim\Http\Response;

View file

@ -18,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php';
/**
* Unitary tests for LegacyLinkDBTest
*/
class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
class LegacyLinkDBTest extends \Shaarli\TestCase
{
// datastore to test write operations
protected static $testDatastore = 'sandbox/datastore.php';
@ -99,11 +99,10 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
/**
* Attempt to instantiate a LinkDB whereas the datastore is not writable
*
* @expectedException Shaarli\Exceptions\IOException
*/
public function testConstructDatastoreNotWriteable()
{
$this->expectException(\Shaarli\Exceptions\IOException::class);
$this->expectExceptionMessageRegExp('/Error accessing "null"/');
new LegacyLinkDB('null/store.db', false, false);
@ -258,7 +257,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
$link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/');
$this->assertNotEquals(false, $link);
$this->assertContains(
$this->assertContainsPolyfill(
'A free software media publishing platform',
$link['description']
);
@ -471,9 +470,9 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
$res = $linkDB->renameTag('cartoon', 'Taz');
$this->assertEquals(3, count($res));
$this->assertContains(' Taz ', $linkDB[4]['tags']);
$this->assertContains(' Taz ', $linkDB[1]['tags']);
$this->assertContains(' Taz ', $linkDB[0]['tags']);
$this->assertContainsPolyfill(' Taz ', $linkDB[4]['tags']);
$this->assertContainsPolyfill(' Taz ', $linkDB[1]['tags']);
$this->assertContainsPolyfill(' Taz ', $linkDB[0]['tags']);
}
/**
@ -513,7 +512,7 @@ class LegacyLinkDBTest extends \PHPUnit\Framework\TestCase
$res = $linkDB->renameTag('cartoon', null);
$this->assertEquals(3, count($res));
$this->assertNotContains('cartoon', $linkDB[4]['tags']);
$this->assertNotContainsPolyfill('cartoon', $linkDB[4]['tags']);
}
/**

View file

@ -10,7 +10,7 @@ use Shaarli\Legacy\LegacyLinkFilter;
/**
* Class LegacyLinkFilterTest.
*/
class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
class LegacyLinkFilterTest extends \Shaarli\TestCase
{
/**
* @var string Test datastore path.
@ -197,10 +197,10 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
/**
* Use an invalid date format
* @expectedException Exception
*/
public function testFilterInvalidDayWithChars()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid date format/');
self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, 'Rainy day, dream away');
@ -208,10 +208,10 @@ class LegacyLinkFilterTest extends \PHPUnit\Framework\TestCase
/**
* Use an invalid date format
* @expectedException Exception
*/
public function testFilterInvalidDayDigits()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid date format/');
self::$linkFilter->filter(LegacyLinkFilter::$FILTER_DAY, '20');

View file

@ -20,7 +20,7 @@ require_once 'inc/rain.tpl.class.php';
* Class UpdaterTest.
* Runs unit tests against the updater class.
*/
class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
class LegacyUpdaterTest extends \Shaarli\TestCase
{
/**
* @var string Path to test datastore.
@ -80,11 +80,10 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
/**
* Test errors in UpdaterUtils::write_updates_file(): empty updates file.
*
* @expectedException Exception
*/
public function testWriteEmptyUpdatesFile()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
UpdaterUtils::write_updates_file('', array('test'));
@ -92,11 +91,10 @@ class LegacyUpdaterTest extends \PHPUnit\Framework\TestCase
/**
* Test errors in UpdaterUtils::write_updates_file(): not writable updates file.
*
* @expectedException Exception
*/
public function testWriteUpdatesFileNotWritable()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Unable to write(.*)/');
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
@ -725,7 +723,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
$this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode'));
$this->assertEquals(125, $this->conf->get('thumbnails.width'));
$this->assertEquals(90, $this->conf->get('thumbnails.height'));
$this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
$this->assertContainsPolyfill('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
}
/**

View file

@ -2,12 +2,12 @@
namespace Shaarli\Netscape;
use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\BookmarkFormatter;
use Shaarli\Formatter\FormatterFactory;
use Shaarli\History;
use Shaarli\TestCase;
require_once 'tests/utils/ReferenceLinkDB.php';
@ -77,10 +77,10 @@ class BookmarkExportTest extends TestCase
/**
* Attempt to export an invalid link selection
* @expectedException Exception
*/
public function testFilterAndFormatInvalid()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/Invalid export selection/');
$this->netscapeBookmarkUtils->filterAndFormat(

View file

@ -3,13 +3,13 @@
namespace Shaarli\Netscape;
use DateTime;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UploadedFileInterface;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\Config\ConfigManager;
use Shaarli\History;
use Shaarli\TestCase;
use Slim\Http\UploadedFile;
/**

View file

@ -9,7 +9,7 @@ require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
/**
* Unit test for the Addlink toolbar plugin
*/
class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
class PluginAddlinkTest extends \Shaarli\TestCase
{
/**
* Reset plugin path.

Some files were not shown because too many files have changed in this diff Show more