Merge pull request #1733 from ArthurHoaro/feature/phpcs-tests
This commit is contained in:
commit
5bf3deb815
103 changed files with 801 additions and 693 deletions
|
@ -71,5 +71,11 @@
|
||||||
"Shaarli\\Updater\\": "application/updater",
|
"Shaarli\\Updater\\": "application/updater",
|
||||||
"Shaarli\\Updater\\Exception\\": "application/updater/exception"
|
"Shaarli\\Updater\\Exception\\": "application/updater/exception"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Shaarli\\Tests\\": "tests",
|
||||||
|
"Shaarli\\Tests\\Utils\\": "tests/utils"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,13 +169,11 @@ Patches should try to stick to the [PHP Standard Recommendations](http://www.php
|
||||||
- [PSR-2](http://www.php-fig.org/psr/psr-2/) - Coding Style Guide
|
- [PSR-2](http://www.php-fig.org/psr/psr-2/) - Coding Style Guide
|
||||||
- [PSR-12](http://www.php-fig.org/psr/psr-12/) - Extended Coding Style Guide
|
- [PSR-12](http://www.php-fig.org/psr/psr-12/) - Extended Coding Style Guide
|
||||||
|
|
||||||
These are enforced on pull requests using our Continuous Integration tools.
|
These are enforced on pull requests using our Continuous Integration tools with [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer).
|
||||||
|
|
||||||
**Work in progress:** Static analysis is currently being discussed here: in [#95 - Fix coding style (static analysis)](https://github.com/shaarli/Shaarli/issues/95), [#130 - Continuous Integration tools & features](https://github.com/shaarli/Shaarli/issues/130)
|
Static analysis tools are installed with Composer dependencies, and used through Shaarli's [Makefile](https://github.com/shaarli/Shaarli/blob/master/Makefile) with `make code_sniffer`.
|
||||||
|
|
||||||
Static analysis tools can be installed with Composer, and used through Shaarli's [Makefile](https://github.com/shaarli/Shaarli/blob/master/Makefile).
|
|
||||||
|
|
||||||
For an overview of the available features, see:
|
For an overview of the available features, see:
|
||||||
|
|
||||||
- [Code quality: Makefile to run static code checkers](https://github.com/shaarli/Shaarli/pull/124) (#124)
|
- [Code quality: Makefile to run static code checkers](https://github.com/shaarli/Shaarli/pull/124) (#124)
|
||||||
- [Run PHPCS against different coding standards](https://github.com/shaarli/Shaarli/pull/276) (#276)
|
- [Apply PHP Code Sniffer to Shaarli code base](https://github.com/shaarli/Shaarli/pull/1635) (#1635)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<file>index.php</file>
|
<file>index.php</file>
|
||||||
<file>application</file>
|
<file>application</file>
|
||||||
<file>plugins</file>
|
<file>plugins</file>
|
||||||
<!-- <file>tests</file>-->
|
<file>tests</file>
|
||||||
|
|
||||||
<exclude-pattern>*/*.css</exclude-pattern>
|
<exclude-pattern>*/*.css</exclude-pattern>
|
||||||
<exclude-pattern>*/*.js</exclude-pattern>
|
<exclude-pattern>*/*.js</exclude-pattern>
|
||||||
|
@ -19,5 +19,11 @@
|
||||||
<!-- index.php bootstraps everything, so yes mixed symbols with side effects -->
|
<!-- index.php bootstraps everything, so yes mixed symbols with side effects -->
|
||||||
<exclude-pattern>index.php</exclude-pattern>
|
<exclude-pattern>index.php</exclude-pattern>
|
||||||
<exclude-pattern>plugins/*</exclude-pattern>
|
<exclude-pattern>plugins/*</exclude-pattern>
|
||||||
|
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
|
||||||
|
<exclude-pattern>tests/utils/RainTPL.php</exclude-pattern>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
|
||||||
|
<exclude-pattern>tests/utils/RainTPL.php</exclude-pattern>
|
||||||
</rule>
|
</rule>
|
||||||
</ruleset>
|
</ruleset>
|
||||||
|
|
|
@ -39,7 +39,7 @@ public function setUp(): void
|
||||||
public function testPlugin(): void
|
public function testPlugin(): void
|
||||||
{
|
{
|
||||||
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||||
$this->pluginManager->load(array(self::$pluginName));
|
$this->pluginManager->load([self::$pluginName]);
|
||||||
|
|
||||||
$this->assertTrue(function_exists('hook_test_random'));
|
$this->assertTrue(function_exists('hook_test_random'));
|
||||||
|
|
||||||
|
@ -50,19 +50,19 @@ public function testPlugin(): void
|
||||||
static::assertSame('woot', $data[1]);
|
static::assertSame('woot', $data[1]);
|
||||||
|
|
||||||
$data = [0 => 'woot'];
|
$data = [0 => 'woot'];
|
||||||
$this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
|
$this->pluginManager->executeHooks('random', $data, ['target' => 'test']);
|
||||||
|
|
||||||
static::assertCount(2, $data);
|
static::assertCount(2, $data);
|
||||||
static::assertSame('page test', $data[1]);
|
static::assertSame('page test', $data[1]);
|
||||||
|
|
||||||
$data = [0 => 'woot'];
|
$data = [0 => 'woot'];
|
||||||
$this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
|
$this->pluginManager->executeHooks('random', $data, ['loggedin' => true]);
|
||||||
|
|
||||||
static::assertCount(2, $data);
|
static::assertCount(2, $data);
|
||||||
static::assertEquals('loggedin', $data[1]);
|
static::assertEquals('loggedin', $data[1]);
|
||||||
|
|
||||||
$data = [0 => 'woot'];
|
$data = [0 => 'woot'];
|
||||||
$this->pluginManager->executeHooks('random', $data, array('loggedin' => null));
|
$this->pluginManager->executeHooks('random', $data, ['loggedin' => null]);
|
||||||
|
|
||||||
static::assertCount(3, $data);
|
static::assertCount(3, $data);
|
||||||
static::assertEquals('loggedin', $data[1]);
|
static::assertEquals('loggedin', $data[1]);
|
||||||
|
@ -76,7 +76,7 @@ public function testPlugin(): void
|
||||||
public function testPluginWithPhpError(): void
|
public function testPluginWithPhpError(): void
|
||||||
{
|
{
|
||||||
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||||
$this->pluginManager->load(array(self::$pluginName));
|
$this->pluginManager->load([self::$pluginName]);
|
||||||
|
|
||||||
$this->assertTrue(function_exists('hook_test_error'));
|
$this->assertTrue(function_exists('hook_test_error'));
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
class ThumbnailerTest extends TestCase
|
class ThumbnailerTest extends TestCase
|
||||||
{
|
{
|
||||||
const WIDTH = 190;
|
protected const WIDTH = 190;
|
||||||
|
|
||||||
const HEIGHT = 210;
|
protected const HEIGHT = 210;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Thumbnailer;
|
* @var Thumbnailer;
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TimeZone's tests
|
* TimeZone's tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/TimeZone.php';
|
namespace Shaarli\Tests;
|
||||||
|
|
||||||
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for timezone utilities
|
* Unitary tests for timezone utilities
|
||||||
*/
|
*/
|
||||||
class TimeZoneTest extends \Shaarli\TestCase
|
class TimeZoneTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array of timezones
|
* @var array of timezones
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities' tests
|
* Utilities' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once 'application/Utils.php';
|
namespace Shaarli\Tests;
|
||||||
require_once 'application/Languages.php';
|
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for Shaarli utilities
|
* Unitary tests for Shaarli utilities
|
||||||
*/
|
*/
|
||||||
class UtilsTest extends \Shaarli\TestCase
|
class UtilsTest extends TestCase
|
||||||
{
|
{
|
||||||
// Log file
|
// Log file
|
||||||
protected static $testLogFile = 'tests.log';
|
protected static $testLogFile = 'tests.log';
|
||||||
|
@ -54,7 +56,7 @@ protected function setUp(): void
|
||||||
/**
|
/**
|
||||||
* Returns a list of the elements from the last logged entry
|
* Returns a list of the elements from the last logged entry
|
||||||
*
|
*
|
||||||
* @return list (date, ip address, message)
|
* @return array (date, ip address, message)
|
||||||
*/
|
*/
|
||||||
protected function getLastLogEntry()
|
protected function getLastLogEntry()
|
||||||
{
|
{
|
||||||
|
@ -187,7 +189,7 @@ public function testGenerateLocation()
|
||||||
public function testGenerateLocationLoop()
|
public function testGenerateLocationLoop()
|
||||||
{
|
{
|
||||||
$ref = 'http://localhost/?test';
|
$ref = 'http://localhost/?test';
|
||||||
$this->assertEquals('./?', generateLocation($ref, 'localhost', array('test')));
|
$this->assertEquals('./?', generateLocation($ref, 'localhost', ['test']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Api;
|
namespace Shaarli\Api;
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +34,7 @@ class ApiMiddlewareTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -49,7 +51,7 @@ protected function setUp(): void
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('api.secret', 'NapoleonWasALizard');
|
$this->conf->set('api.secret', 'NapoleonWasALizard');
|
||||||
|
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
|
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
use Slim\Http\Response;
|
use Slim\Http\Response;
|
||||||
|
|
||||||
require_once 'tests/utils/ReferenceHistory.php';
|
class HistoryTest extends TestCase
|
||||||
|
|
||||||
class HistoryTest extends \Shaarli\TestCase
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string datastore to test write operations
|
* @var string datastore to test write operations
|
||||||
|
@ -24,7 +24,7 @@ class HistoryTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceHistory instance.
|
* @var ReferenceHistory instance.
|
||||||
*/
|
*/
|
||||||
protected $refHistory = null;
|
protected $refHistory = null;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class HistoryTest extends \Shaarli\TestCase
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->refHistory = new \ReferenceHistory();
|
$this->refHistory = new ReferenceHistory();
|
||||||
$this->refHistory->write(self::$testHistory);
|
$this->refHistory->write(self::$testHistory);
|
||||||
$this->container = new Container();
|
$this->container = new Container();
|
||||||
$this->container['conf'] = $this->conf;
|
$this->container['conf'] = $this->conf;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +34,7 @@ class InfoTest extends TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -54,7 +56,7 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
|
@ -95,7 +97,7 @@ public function testGetInfo()
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$data = json_decode((string) $response->getBody(), true);
|
$data = json_decode((string) $response->getBody(), true);
|
||||||
|
|
||||||
$this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
||||||
$this->assertEquals(2, $data['private_counter']);
|
$this->assertEquals(2, $data['private_counter']);
|
||||||
$this->assertEquals('Shaarli', $data['settings']['title']);
|
$this->assertEquals('Shaarli', $data['settings']['title']);
|
||||||
$this->assertEquals('?', $data['settings']['header_link']);
|
$this->assertEquals('?', $data['settings']['header_link']);
|
||||||
|
@ -106,7 +108,7 @@ public function testGetInfo()
|
||||||
$title = 'My bookmarks';
|
$title = 'My bookmarks';
|
||||||
$headerLink = 'http://shaarli.tld';
|
$headerLink = 'http://shaarli.tld';
|
||||||
$timezone = 'Europe/Paris';
|
$timezone = 'Europe/Paris';
|
||||||
$enabledPlugins = array('foo', 'bar');
|
$enabledPlugins = ['foo', 'bar'];
|
||||||
$defaultPrivateLinks = true;
|
$defaultPrivateLinks = true;
|
||||||
$this->conf->set('general.title', $title);
|
$this->conf->set('general.title', $title);
|
||||||
$this->conf->set('general.header_link', $headerLink);
|
$this->conf->set('general.header_link', $headerLink);
|
||||||
|
@ -118,7 +120,7 @@ public function testGetInfo()
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$data = json_decode((string) $response->getBody(), true);
|
$data = json_decode((string) $response->getBody(), true);
|
||||||
|
|
||||||
$this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
||||||
$this->assertEquals(2, $data['private_counter']);
|
$this->assertEquals(2, $data['private_counter']);
|
||||||
$this->assertEquals($title, $data['settings']['title']);
|
$this->assertEquals($title, $data['settings']['title']);
|
||||||
$this->assertEquals($headerLink, $data['settings']['header_link']);
|
$this->assertEquals($headerLink, $data['settings']['header_link']);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -8,6 +7,8 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -31,7 +32,7 @@ class DeleteLinkTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -69,9 +70,9 @@ protected function setUp(): void
|
||||||
$this->mutex = new NoMutex();
|
$this->mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$refHistory = new \ReferenceHistory();
|
$refHistory = new ReferenceHistory();
|
||||||
$refHistory->write(self::$testHistory);
|
$refHistory->write(self::$testHistory);
|
||||||
$this->history = new History(self::$testHistory);
|
$this->history = new History(self::$testHistory);
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -35,7 +36,7 @@ class GetLinkIdTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ class GetLinkIdTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON fields per link.
|
* Number of JSON fields per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_LINK = 9;
|
protected const NB_FIELDS_LINK = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -62,7 +63,7 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -35,7 +37,7 @@ class GetLinksTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ class GetLinksTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON field per link.
|
* Number of JSON field per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_LINK = 9;
|
protected const NB_FIELDS_LINK = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -62,7 +64,7 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
|
|
||||||
|
@ -430,7 +432,7 @@ public function testGetLinksSearchTags()
|
||||||
$response = $this->controller->getLinks($request, new Response());
|
$response = $this->controller->getLinks($request, new Response());
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$data = json_decode((string) $response->getBody(), true);
|
$data = json_decode((string) $response->getBody(), true);
|
||||||
$this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, count($data));
|
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data));
|
||||||
$this->assertEquals(10, $data[0]['id']);
|
$this->assertEquals(10, $data[0]['id']);
|
||||||
$this->assertEquals(41, $data[2]['id']);
|
$this->assertEquals(41, $data[2]['id']);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -40,7 +42,7 @@ class PostLinkTest extends TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -67,7 +69,7 @@ class PostLinkTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON field per link.
|
* Number of JSON field per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_LINK = 9;
|
protected const NB_FIELDS_LINK = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -77,9 +79,9 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$refHistory = new \ReferenceHistory();
|
$refHistory = new ReferenceHistory();
|
||||||
$refHistory->write(self::$testHistory);
|
$refHistory->write(self::$testHistory);
|
||||||
$this->history = new History(self::$testHistory);
|
$this->history = new History(self::$testHistory);
|
||||||
$pluginManager = new PluginManager($this->conf);
|
$pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -9,6 +8,8 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +33,7 @@ class PutLinkTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ class PutLinkTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON field per link.
|
* Number of JSON field per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_LINK = 9;
|
protected const NB_FIELDS_LINK = 9;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -69,9 +70,9 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$refHistory = new \ReferenceHistory();
|
$refHistory = new ReferenceHistory();
|
||||||
$refHistory->write(self::$testHistory);
|
$refHistory->write(self::$testHistory);
|
||||||
$this->history = new History(self::$testHistory);
|
$this->history = new History(self::$testHistory);
|
||||||
$pluginManager = new PluginManager($this->conf);
|
$pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -9,6 +8,8 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +33,7 @@ class DeleteTagTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -70,9 +71,9 @@ protected function setUp(): void
|
||||||
$this->mutex = new NoMutex();
|
$this->mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$refHistory = new \ReferenceHistory();
|
$refHistory = new ReferenceHistory();
|
||||||
$refHistory->write(self::$testHistory);
|
$refHistory->write(self::$testHistory);
|
||||||
$this->history = new History(self::$testHistory);
|
$this->history = new History(self::$testHistory);
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -33,7 +34,7 @@ class GetTagNameTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ class GetTagNameTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON fields per link.
|
* Number of JSON fields per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_TAG = 2;
|
protected const NB_FIELDS_TAG = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before each test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -63,7 +64,7 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Api\Controllers;
|
namespace Shaarli\Api\Controllers;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +34,7 @@ class GetTagsTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ class GetTagsTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON field per link.
|
* Number of JSON field per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_TAG = 2;
|
protected const NB_FIELDS_TAG = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -67,7 +69,7 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceHistory;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Slim\Container;
|
use Slim\Container;
|
||||||
use Slim\Http\Environment;
|
use Slim\Http\Environment;
|
||||||
use Slim\Http\Request;
|
use Slim\Http\Request;
|
||||||
|
@ -32,7 +34,7 @@ class PutTagTest extends \Shaarli\TestCase
|
||||||
protected $conf;
|
protected $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected $refDB = null;
|
protected $refDB = null;
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ class PutTagTest extends \Shaarli\TestCase
|
||||||
/**
|
/**
|
||||||
* Number of JSON field per link.
|
* Number of JSON field per link.
|
||||||
*/
|
*/
|
||||||
const NB_FIELDS_TAG = 2;
|
protected const NB_FIELDS_TAG = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
* Before every test, instantiate a new Api with its config, plugins and bookmarks.
|
||||||
|
@ -72,9 +74,9 @@ protected function setUp(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
$this->conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$refHistory = new \ReferenceHistory();
|
$refHistory = new ReferenceHistory();
|
||||||
$refHistory->write(self::$testHistory);
|
$refHistory->write(self::$testHistory);
|
||||||
$this->history = new History(self::$testHistory);
|
$this->history = new History(self::$testHistory);
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Shaarli\Bookmark;
|
namespace Shaarli\Bookmark;
|
||||||
|
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BookmarkArrayTest
|
* Class BookmarkArrayTest
|
||||||
|
@ -194,7 +195,7 @@ public function testArrayAccessIterate()
|
||||||
*/
|
*/
|
||||||
public function testReorder()
|
public function testReorder()
|
||||||
{
|
{
|
||||||
$refDB = new \ReferenceLinkDB();
|
$refDB = new ReferenceLinkDB();
|
||||||
$refDB->write('sandbox/datastore.php');
|
$refDB->write('sandbox/datastore.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link datastore tests
|
* Link datastore tests
|
||||||
*/
|
*/
|
||||||
|
@ -7,7 +8,6 @@
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
use ReferenceLinkDB;
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Shaarli;
|
use Shaarli;
|
||||||
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
|
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\FakeBookmarkService;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for LegacyLinkDBTest
|
* Unitary tests for LegacyLinkDBTest
|
||||||
|
@ -94,7 +96,7 @@ protected function setUp(): void
|
||||||
$this->conf = new ConfigManager(self::$testConf);
|
$this->conf = new ConfigManager(self::$testConf);
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
$this->conf->set('resource.updates', self::$testUpdates);
|
$this->conf->set('resource.updates', self::$testUpdates);
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$this->history = new History('sandbox/history.php');
|
$this->history = new History('sandbox/history.php');
|
||||||
$this->pluginManager = new PluginManager($this->conf);
|
$this->pluginManager = new PluginManager($this->conf);
|
||||||
|
@ -123,12 +125,12 @@ public function testDatabaseMigration()
|
||||||
define('SHAARLI_VERSION', 'dev');
|
define('SHAARLI_VERSION', 'dev');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->refDB = new \ReferenceLinkDB(true);
|
$this->refDB = new ReferenceLinkDB(true);
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
$db = self::getMethod('migrate');
|
$db = self::getMethod('migrate');
|
||||||
$db->invokeArgs($this->privateLinkDB, []);
|
$db->invokeArgs($this->privateLinkDB, []);
|
||||||
|
|
||||||
$db = new \FakeBookmarkService(
|
$db = new FakeBookmarkService(
|
||||||
$this->conf,
|
$this->conf,
|
||||||
$this->pluginManager,
|
$this->pluginManager,
|
||||||
$this->history,
|
$this->history,
|
||||||
|
@ -203,7 +205,7 @@ public function testAddFull()
|
||||||
$this->assertEquals($updated, $bookmark->getUpdated());
|
$this->assertEquals($updated, $bookmark->getUpdated());
|
||||||
|
|
||||||
// reload from file
|
// reload from file
|
||||||
$this->privateLinkDB = new \FakeBookmarkService(
|
$this->privateLinkDB = new FakeBookmarkService(
|
||||||
$this->conf,
|
$this->conf,
|
||||||
$this->pluginManager,
|
$this->pluginManager,
|
||||||
$this->history,
|
$this->history,
|
||||||
|
@ -714,7 +716,7 @@ public function testCheckDBNewLoggedOut()
|
||||||
{
|
{
|
||||||
unlink(self::$testDatastore);
|
unlink(self::$testDatastore);
|
||||||
$this->assertFileNotExists(self::$testDatastore);
|
$this->assertFileNotExists(self::$testDatastore);
|
||||||
$db = new \FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
|
$db = new FakeBookmarkService($this->conf, $this->pluginManager, $this->history, $this->mutex, false);
|
||||||
$this->assertFileNotExists(self::$testDatastore);
|
$this->assertFileNotExists(self::$testDatastore);
|
||||||
$this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
|
$this->assertInstanceOf(BookmarkArray::class, $db->getBookmarks());
|
||||||
$this->assertCount(0, $db->getBookmarks());
|
$this->assertCount(0, $db->getBookmarks());
|
||||||
|
|
|
@ -3,11 +3,12 @@
|
||||||
namespace Shaarli\Bookmark;
|
namespace Shaarli\Bookmark;
|
||||||
|
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
use ReferenceLinkDB;
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\FakeBookmarkService;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BookmarkFilterTest.
|
* Class BookmarkFilterTest.
|
||||||
|
@ -46,10 +47,10 @@ public static function setUpBeforeClass(): void
|
||||||
$conf = new ConfigManager('tests/utils/config/configJson');
|
$conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$conf->set('resource.datastore', self::$testDatastore);
|
$conf->set('resource.datastore', self::$testDatastore);
|
||||||
static::$pluginManager = new PluginManager($conf);
|
static::$pluginManager = new PluginManager($conf);
|
||||||
self::$refDB = new \ReferenceLinkDB();
|
self::$refDB = new ReferenceLinkDB();
|
||||||
self::$refDB->write(self::$testDatastore);
|
self::$refDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
self::$bookmarkService = new \FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true);
|
self::$bookmarkService = new FakeBookmarkService($conf, static::$pluginManager, $history, $mutex, true);
|
||||||
self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager);
|
self::$linkFilter = new BookmarkFilter(self::$bookmarkService->getBookmarks(), $conf, static::$pluginManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,28 +418,28 @@ public function testFilterCrossedSearch()
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
||||||
array($tags, $terms)
|
[$tags, $terms]
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
2,
|
2,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
||||||
array('', $terms)
|
['', $terms]
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
||||||
array(false, 'PSR-2')
|
[false, 'PSR-2']
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
BookmarkFilter::$FILTER_TAG | BookmarkFilter::$FILTER_TEXT,
|
||||||
array($tags, '')
|
[$tags, '']
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BookmarkInitializerTest
|
* Class BookmarkInitializerTest
|
||||||
|
@ -73,7 +74,7 @@ public function setUp(): void
|
||||||
*/
|
*/
|
||||||
public function testInitializeNotEmptyDataStore(): void
|
public function testInitializeNotEmptyDataStore(): void
|
||||||
{
|
{
|
||||||
$refDB = new \ReferenceLinkDB();
|
$refDB = new ReferenceLinkDB();
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$this->bookmarkService = new BookmarkFileService(
|
$this->bookmarkService = new BookmarkFileService(
|
||||||
$this->conf,
|
$this->conf,
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
|
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
require_once 'tests/utils/CurlUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LinkUtilsTest.
|
* Class LinkUtilsTest.
|
||||||
*/
|
*/
|
||||||
|
@ -701,7 +699,10 @@ public function testTagsFilterWithSpaceSeparator(): void
|
||||||
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator));
|
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['tag1', 'tag2', 'tag3'], $separator));
|
||||||
static::assertSame(['tag1,', 'tag2@', 'tag3'], tags_filter(['tag1,', 'tag2@', 'tag3'], $separator));
|
static::assertSame(['tag1,', 'tag2@', 'tag3'], tags_filter(['tag1,', 'tag2@', 'tag3'], $separator));
|
||||||
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', 'tag2', 'tag3 '], $separator));
|
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', 'tag2', 'tag3 '], $separator));
|
||||||
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator));
|
static::assertSame(
|
||||||
|
['tag1', 'tag2', 'tag3'],
|
||||||
|
tags_filter([' tag1 ', ' ', 'tag2', ' ', 'tag3 '], $separator)
|
||||||
|
);
|
||||||
static::assertSame(['tag1'], tags_filter([' tag1 '], $separator));
|
static::assertSame(['tag1'], tags_filter([' tag1 '], $separator));
|
||||||
static::assertSame([], tags_filter([' '], $separator));
|
static::assertSame([], tags_filter([' '], $separator));
|
||||||
static::assertSame([], tags_filter([], $separator));
|
static::assertSame([], tags_filter([], $separator));
|
||||||
|
@ -721,7 +722,10 @@ public function testTagsArrayFilterWithSpaceSeparator(): void
|
||||||
['tag1', 'tag2, and other', 'tag3'],
|
['tag1', 'tag2, and other', 'tag3'],
|
||||||
tags_filter(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator)
|
tags_filter(['@@@@ tag1@@@', ' @tag2, and other @', 'tag3@@@@'], $separator)
|
||||||
);
|
);
|
||||||
static::assertSame(['tag1', 'tag2', 'tag3'], tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator));
|
static::assertSame(
|
||||||
|
['tag1', 'tag2', 'tag3'],
|
||||||
|
tags_filter(['@@@tag1@@@', '@', 'tag2', '@@@', 'tag3@@@'], $separator)
|
||||||
|
);
|
||||||
static::assertSame(['tag1'], tags_filter(['@@@@tag1@@@@'], $separator));
|
static::assertSame(['tag1'], tags_filter(['@@@@tag1@@@@'], $separator));
|
||||||
static::assertSame([], tags_filter(['@@@'], $separator));
|
static::assertSame([], tags_filter(['@@@'], $separator));
|
||||||
static::assertSame([], tags_filter([], $separator));
|
static::assertSame([], tags_filter([], $separator));
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
use Shaarli\Tests\Utils\ReferenceSessionIdHashes;
|
||||||
|
|
||||||
$conf = new \Shaarli\Config\ConfigManager('tests/utils/config/configJson');
|
$conf = new \Shaarli\Config\ConfigManager('tests/utils/config/configJson');
|
||||||
new \Shaarli\Languages('en', $conf);
|
new \Shaarli\Languages('en', $conf);
|
||||||
|
|
||||||
|
@ -13,23 +15,26 @@ function is_iterable($var)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this after fixing UT
|
// raw functions
|
||||||
|
require_once 'application/config/ConfigPlugin.php';
|
||||||
require_once 'application/bookmark/LinkUtils.php';
|
require_once 'application/bookmark/LinkUtils.php';
|
||||||
require_once 'application/Utils.php';
|
|
||||||
require_once 'application/http/UrlUtils.php';
|
require_once 'application/http/UrlUtils.php';
|
||||||
require_once 'application/http/HttpUtils.php';
|
require_once 'application/http/HttpUtils.php';
|
||||||
|
require_once 'application/Utils.php';
|
||||||
|
require_once 'application/TimeZone.php';
|
||||||
|
require_once 'tests/utils/CurlUtils.php';
|
||||||
|
require_once 'tests/utils/RainTPL.php';
|
||||||
|
|
||||||
|
// TODO: remove this after fixing UT
|
||||||
require_once 'tests/TestCase.php';
|
require_once 'tests/TestCase.php';
|
||||||
require_once 'tests/container/ShaarliTestContainer.php';
|
require_once 'tests/container/ShaarliTestContainer.php';
|
||||||
require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php';
|
require_once 'tests/front/controller/visitor/FrontControllerMockHelper.php';
|
||||||
require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php';
|
require_once 'tests/front/controller/admin/FrontAdminControllerMockHelper.php';
|
||||||
require_once 'tests/updater/DummyUpdater.php';
|
|
||||||
require_once 'tests/utils/FakeBookmarkService.php';
|
|
||||||
require_once 'tests/utils/FakeConfigManager.php';
|
require_once 'tests/utils/FakeConfigManager.php';
|
||||||
require_once 'tests/utils/ReferenceHistory.php';
|
require_once 'tests/utils/ReferenceHistory.php';
|
||||||
require_once 'tests/utils/ReferenceLinkDB.php';
|
require_once 'tests/utils/ReferenceLinkDB.php';
|
||||||
require_once 'tests/utils/ReferenceSessionIdHashes.php';
|
|
||||||
|
|
||||||
\ReferenceSessionIdHashes::genAllHashes();
|
ReferenceSessionIdHashes::genAllHashes();
|
||||||
|
|
||||||
if (!defined('SHAARLI_MUTEX_FILE')) {
|
if (!defined('SHAARLI_MUTEX_FILE')) {
|
||||||
define('SHAARLI_MUTEX_FILE', __FILE__);
|
define('SHAARLI_MUTEX_FILE', __FILE__);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Config;
|
namespace Shaarli\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,13 +30,13 @@ public function testSetGet()
|
||||||
$this->conf->set('paramInt', 42);
|
$this->conf->set('paramInt', 42);
|
||||||
$this->conf->set('paramString', 'value1');
|
$this->conf->set('paramString', 'value1');
|
||||||
$this->conf->set('paramBool', false);
|
$this->conf->set('paramBool', false);
|
||||||
$this->conf->set('paramArray', array('foo' => 'bar'));
|
$this->conf->set('paramArray', ['foo' => 'bar']);
|
||||||
$this->conf->set('paramNull', null);
|
$this->conf->set('paramNull', null);
|
||||||
|
|
||||||
$this->assertEquals(42, $this->conf->get('paramInt'));
|
$this->assertEquals(42, $this->conf->get('paramInt'));
|
||||||
$this->assertEquals('value1', $this->conf->get('paramString'));
|
$this->assertEquals('value1', $this->conf->get('paramString'));
|
||||||
$this->assertFalse($this->conf->get('paramBool'));
|
$this->assertFalse($this->conf->get('paramBool'));
|
||||||
$this->assertEquals(array('foo' => 'bar'), $this->conf->get('paramArray'));
|
$this->assertEquals(['foo' => 'bar'], $this->conf->get('paramArray'));
|
||||||
$this->assertEquals(null, $this->conf->get('paramNull'));
|
$this->assertEquals(null, $this->conf->get('paramNull'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ public function testSetWriteGet()
|
||||||
$this->conf->set('paramInt', 42);
|
$this->conf->set('paramInt', 42);
|
||||||
$this->conf->set('paramString', 'value1');
|
$this->conf->set('paramString', 'value1');
|
||||||
$this->conf->set('paramBool', false);
|
$this->conf->set('paramBool', false);
|
||||||
$this->conf->set('paramArray', array('foo' => 'bar'));
|
$this->conf->set('paramArray', ['foo' => 'bar']);
|
||||||
$this->conf->set('paramNull', null);
|
$this->conf->set('paramNull', null);
|
||||||
|
|
||||||
$this->conf->setConfigFile('tests/utils/config/configTmp');
|
$this->conf->setConfigFile('tests/utils/config/configTmp');
|
||||||
|
@ -62,7 +63,7 @@ public function testSetWriteGet()
|
||||||
$this->assertEquals(42, $this->conf->get('paramInt'));
|
$this->assertEquals(42, $this->conf->get('paramInt'));
|
||||||
$this->assertEquals('value1', $this->conf->get('paramString'));
|
$this->assertEquals('value1', $this->conf->get('paramString'));
|
||||||
$this->assertFalse($this->conf->get('paramBool'));
|
$this->assertFalse($this->conf->get('paramBool'));
|
||||||
$this->assertEquals(array('foo' => 'bar'), $this->conf->get('paramArray'));
|
$this->assertEquals(['foo' => 'bar'], $this->conf->get('paramArray'));
|
||||||
$this->assertEquals(null, $this->conf->get('paramNull'));
|
$this->assertEquals(null, $this->conf->get('paramNull'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ public function testSetArrayKey()
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
$this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
|
$this->expectExceptionMessageRegExp('#^Invalid setting key parameter. String expected, got.*#');
|
||||||
|
|
||||||
$this->conf->set(array('foo' => 'bar'), 'stuff');
|
$this->conf->set(['foo' => 'bar'], 'stuff');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Config;
|
namespace Shaarli\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +38,7 @@ public function testRead()
|
||||||
*/
|
*/
|
||||||
public function testReadNonExistent()
|
public function testReadNonExistent()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(), $this->configIO->read('nope'));
|
$this->assertEquals([], $this->configIO->read('nope'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,16 +61,16 @@ public function testReadEmpty()
|
||||||
public function testWriteNew()
|
public function testWriteNew()
|
||||||
{
|
{
|
||||||
$dataFile = 'tests/utils/config/configWrite.php';
|
$dataFile = 'tests/utils/config/configWrite.php';
|
||||||
$data = array(
|
$data = [
|
||||||
'login' => 'root',
|
'login' => 'root',
|
||||||
'redirector' => 'lala',
|
'redirector' => 'lala',
|
||||||
'config' => array(
|
'config' => [
|
||||||
'DATASTORE' => 'data/datastore.php',
|
'DATASTORE' => 'data/datastore.php',
|
||||||
),
|
],
|
||||||
'plugins' => array(
|
'plugins' => [
|
||||||
'WALLABAG_VERSION' => '1',
|
'WALLABAG_VERSION' => '1',
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
$this->configIO->write($dataFile, $data);
|
$this->configIO->write($dataFile, $data);
|
||||||
$expected = '<?php
|
$expected = '<?php
|
||||||
$GLOBALS[\'login\'] = \'root\';
|
$GLOBALS[\'login\'] = \'root\';
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Config;
|
namespace Shaarli\Config;
|
||||||
|
|
||||||
use Shaarli\Config\Exception\PluginConfigOrderException;
|
use Shaarli\Config\Exception\PluginConfigOrderException;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
use Shaarli\TestCase;
|
||||||
require_once 'application/config/ConfigPlugin.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for Shaarli config related functions
|
* Unitary tests for Shaarli config related functions
|
||||||
*/
|
*/
|
||||||
class ConfigPluginTest extends \Shaarli\TestCase
|
class ConfigPluginTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test save_plugin_config with valid data.
|
* Test save_plugin_config with valid data.
|
||||||
|
@ -35,12 +35,16 @@ public function testSavePluginConfigValid()
|
||||||
|
|
||||||
mkdir($path = __DIR__ . '/folder');
|
mkdir($path = __DIR__ . '/folder');
|
||||||
PluginManager::$PLUGINS_PATH = $path;
|
PluginManager::$PLUGINS_PATH = $path;
|
||||||
array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, $expected);
|
array_map(function (string $plugin) use ($path) {
|
||||||
|
touch($path . '/' . $plugin);
|
||||||
|
}, $expected);
|
||||||
|
|
||||||
$out = save_plugin_config($data);
|
$out = save_plugin_config($data);
|
||||||
$this->assertEquals($expected, $out);
|
$this->assertEquals($expected, $out);
|
||||||
|
|
||||||
array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, $expected);
|
array_map(function (string $plugin) use ($path) {
|
||||||
|
unlink($path . '/' . $plugin);
|
||||||
|
}, $expected);
|
||||||
rmdir($path);
|
rmdir($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,15 +53,15 @@ public function testSavePluginConfigValid()
|
||||||
*/
|
*/
|
||||||
public function testSavePluginConfigInvalid()
|
public function testSavePluginConfigInvalid()
|
||||||
{
|
{
|
||||||
$this->expectException(\Shaarli\Config\Exception\PluginConfigOrderException::class);
|
$this->expectException(PluginConfigOrderException::class);
|
||||||
|
|
||||||
$data = array(
|
$data = [
|
||||||
'plugin2' => 0,
|
'plugin2' => 0,
|
||||||
'plugin3' => 0,
|
'plugin3' => 0,
|
||||||
'order_plugin3' => 0,
|
'order_plugin3' => 0,
|
||||||
'plugin4' => 0,
|
'plugin4' => 0,
|
||||||
'order_plugin4' => 0,
|
'order_plugin4' => 0,
|
||||||
);
|
];
|
||||||
|
|
||||||
save_plugin_config($data);
|
save_plugin_config($data);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +71,7 @@ public function testSavePluginConfigInvalid()
|
||||||
*/
|
*/
|
||||||
public function testSavePluginConfigEmpty()
|
public function testSavePluginConfigEmpty()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(), save_plugin_config(array()));
|
$this->assertEquals([], save_plugin_config([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,14 +79,14 @@ public function testSavePluginConfigEmpty()
|
||||||
*/
|
*/
|
||||||
public function testValidatePluginOrderValid()
|
public function testValidatePluginOrderValid()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = [
|
||||||
'order_plugin1' => 2,
|
'order_plugin1' => 2,
|
||||||
'plugin2' => 0,
|
'plugin2' => 0,
|
||||||
'plugin3' => 0,
|
'plugin3' => 0,
|
||||||
'order_plugin3' => 1,
|
'order_plugin3' => 1,
|
||||||
'plugin4' => 0,
|
'plugin4' => 0,
|
||||||
'order_plugin4' => 5,
|
'order_plugin4' => 5,
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->assertTrue(validate_plugin_order($data));
|
$this->assertTrue(validate_plugin_order($data));
|
||||||
}
|
}
|
||||||
|
@ -92,11 +96,11 @@ public function testValidatePluginOrderValid()
|
||||||
*/
|
*/
|
||||||
public function testValidatePluginOrderInvalid()
|
public function testValidatePluginOrderInvalid()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = [
|
||||||
'order_plugin1' => 2,
|
'order_plugin1' => 2,
|
||||||
'order_plugin3' => 1,
|
'order_plugin3' => 1,
|
||||||
'order_plugin4' => 1,
|
'order_plugin4' => 1,
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->assertFalse(validate_plugin_order($data));
|
$this->assertFalse(validate_plugin_order($data));
|
||||||
}
|
}
|
||||||
|
@ -106,20 +110,20 @@ public function testValidatePluginOrderInvalid()
|
||||||
*/
|
*/
|
||||||
public function testLoadPluginParameterValues()
|
public function testLoadPluginParameterValues()
|
||||||
{
|
{
|
||||||
$plugins = array(
|
$plugins = [
|
||||||
'plugin_name' => array(
|
'plugin_name' => [
|
||||||
'parameters' => array(
|
'parameters' => [
|
||||||
'param1' => array('value' => true),
|
'param1' => ['value' => true],
|
||||||
'param2' => array('value' => false),
|
'param2' => ['value' => false],
|
||||||
'param3' => array('value' => ''),
|
'param3' => ['value' => ''],
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$parameters = array(
|
$parameters = [
|
||||||
'param1' => 'value1',
|
'param1' => 'value1',
|
||||||
'param2' => 'value2',
|
'param2' => 'value2',
|
||||||
);
|
];
|
||||||
|
|
||||||
$result = load_plugin_parameter_values($plugins, $parameters);
|
$result = load_plugin_parameter_values($plugins, $parameters);
|
||||||
$this->assertEquals('value1', $result['plugin_name']['parameters']['param1']['value']);
|
$this->assertEquals('value1', $result['plugin_name']['parameters']['param1']['value']);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PageCache tests
|
* PageCache tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Feed;
|
namespace Shaarli\Feed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use malkusch\lock\mutex\NoMutex;
|
use malkusch\lock\mutex\NoMutex;
|
||||||
use ReferenceLinkDB;
|
|
||||||
use Shaarli\Bookmark\Bookmark;
|
use Shaarli\Bookmark\Bookmark;
|
||||||
use Shaarli\Bookmark\BookmarkFileService;
|
use Shaarli\Bookmark\BookmarkFileService;
|
||||||
use Shaarli\Bookmark\LinkDB;
|
use Shaarli\Bookmark\LinkDB;
|
||||||
|
@ -13,6 +12,7 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FeedBuilderTest class.
|
* FeedBuilderTest class.
|
||||||
|
@ -52,7 +52,7 @@ public static function setUpBeforeClass(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$conf = new ConfigManager('tests/utils/config/configJson');
|
$conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
$conf->set('resource.datastore', self::$testDatastore);
|
$conf->set('resource.datastore', self::$testDatastore);
|
||||||
$refLinkDB = new \ReferenceLinkDB();
|
$refLinkDB = new ReferenceLinkDB();
|
||||||
$refLinkDB->write(self::$testDatastore);
|
$refLinkDB->write(self::$testDatastore);
|
||||||
$history = new History('sandbox/history.php');
|
$history = new History('sandbox/history.php');
|
||||||
$factory = new FormatterFactory($conf, true);
|
$factory = new FormatterFactory($conf, true);
|
||||||
|
@ -66,13 +66,13 @@ public static function setUpBeforeClass(): void
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
self::$serverInfo = array(
|
self::$serverInfo = [
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/index.php',
|
'SCRIPT_NAME' => '/index.php',
|
||||||
'REQUEST_URI' => '/feed/atom',
|
'REQUEST_URI' => '/feed/atom',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +100,10 @@ public function testRSSBuildData()
|
||||||
// Test first not pinned link (note link)
|
// Test first not pinned link (note link)
|
||||||
$link = $data['links'][array_keys($data['links'])[0]];
|
$link = $data['links'][array_keys($data['links'])[0]];
|
||||||
$this->assertEquals(41, $link['id']);
|
$this->assertEquals(41, $link['id']);
|
||||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
$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['guid']);
|
||||||
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
|
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
|
||||||
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
|
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
|
||||||
|
@ -149,10 +152,10 @@ public function testAtomBuildData()
|
||||||
*/
|
*/
|
||||||
public function testBuildDataFiltered()
|
public function testBuildDataFiltered()
|
||||||
{
|
{
|
||||||
$criteria = array(
|
$criteria = [
|
||||||
'searchtags' => 'stuff',
|
'searchtags' => 'stuff',
|
||||||
'searchterm' => 'beard',
|
'searchterm' => 'beard',
|
||||||
);
|
];
|
||||||
$feedBuilder = new FeedBuilder(
|
$feedBuilder = new FeedBuilder(
|
||||||
self::$bookmarkService,
|
self::$bookmarkService,
|
||||||
self::$formatter,
|
self::$formatter,
|
||||||
|
@ -164,7 +167,10 @@ public function testBuildDataFiltered()
|
||||||
$this->assertEquals(1, count($data['links']));
|
$this->assertEquals(1, count($data['links']));
|
||||||
$link = array_shift($data['links']);
|
$link = array_shift($data['links']);
|
||||||
$this->assertEquals(41, $link['id']);
|
$this->assertEquals(41, $link['id']);
|
||||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
$this->assertEquals(
|
||||||
|
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'),
|
||||||
|
$link['created']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,9 +178,9 @@ public function testBuildDataFiltered()
|
||||||
*/
|
*/
|
||||||
public function testBuildDataCount()
|
public function testBuildDataCount()
|
||||||
{
|
{
|
||||||
$criteria = array(
|
$criteria = [
|
||||||
'nb' => '3',
|
'nb' => '3',
|
||||||
);
|
];
|
||||||
$feedBuilder = new FeedBuilder(
|
$feedBuilder = new FeedBuilder(
|
||||||
self::$bookmarkService,
|
self::$bookmarkService,
|
||||||
self::$formatter,
|
self::$formatter,
|
||||||
|
@ -186,7 +192,10 @@ public function testBuildDataCount()
|
||||||
$this->assertEquals(3, count($data['links']));
|
$this->assertEquals(3, count($data['links']));
|
||||||
$link = $data['links'][array_keys($data['links'])[0]];
|
$link = $data['links'][array_keys($data['links'])[0]];
|
||||||
$this->assertEquals(41, $link['id']);
|
$this->assertEquals(41, $link['id']);
|
||||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
$this->assertEquals(
|
||||||
|
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'),
|
||||||
|
$link['created']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,7 +217,10 @@ public function testBuildDataPermalinks()
|
||||||
// First link is a permalink
|
// First link is a permalink
|
||||||
$link = $data['links'][array_keys($data['links'])[0]];
|
$link = $data['links'][array_keys($data['links'])[0]];
|
||||||
$this->assertEquals(41, $link['id']);
|
$this->assertEquals(41, $link['id']);
|
||||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
|
$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['guid']);
|
||||||
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
|
$this->assertEquals('http://host.tld/shaare/WDWyig', $link['url']);
|
||||||
$this->assertContainsPolyfill('Direct link', $link['description']);
|
$this->assertContainsPolyfill('Direct link', $link['description']);
|
||||||
|
@ -216,7 +228,10 @@ public function testBuildDataPermalinks()
|
||||||
// Second link is a direct link
|
// Second link is a direct link
|
||||||
$link = $data['links'][array_keys($data['links'])[1]];
|
$link = $data['links'][array_keys($data['links'])[1]];
|
||||||
$this->assertEquals(8, $link['id']);
|
$this->assertEquals(8, $link['id']);
|
||||||
$this->assertEquals(DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
|
$this->assertEquals(
|
||||||
|
DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150310_114633'),
|
||||||
|
$link['created']
|
||||||
|
);
|
||||||
$this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
|
$this->assertEquals('http://host.tld/shaare/RttfEw', $link['guid']);
|
||||||
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
|
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
|
||||||
$this->assertContainsPolyfill('Direct link', $link['description']);
|
$this->assertContainsPolyfill('Direct link', $link['description']);
|
||||||
|
@ -259,13 +274,13 @@ public function testBuildDataHideDates()
|
||||||
*/
|
*/
|
||||||
public function testBuildDataServerSubdir()
|
public function testBuildDataServerSubdir()
|
||||||
{
|
{
|
||||||
$serverInfo = array(
|
$serverInfo = [
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '8080',
|
'SERVER_PORT' => '8080',
|
||||||
'SCRIPT_NAME' => '/~user/shaarli/index.php',
|
'SCRIPT_NAME' => '/~user/shaarli/index.php',
|
||||||
'REQUEST_URI' => '/~user/shaarli/feed/atom',
|
'REQUEST_URI' => '/~user/shaarli/feed/atom',
|
||||||
);
|
];
|
||||||
$feedBuilder = new FeedBuilder(
|
$feedBuilder = new FeedBuilder(
|
||||||
self::$bookmarkService,
|
self::$bookmarkService,
|
||||||
self::$formatter,
|
self::$formatter,
|
||||||
|
|
|
@ -63,7 +63,8 @@ public function testMiddlewareWhileLoggedOut(): void
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
|
|
||||||
/** @var Response $result */
|
/** @var Response $result */
|
||||||
$result = $this->middleware->__invoke($request, $response, function () {});
|
$result = $this->middleware->__invoke($request, $response, function () {
|
||||||
|
});
|
||||||
|
|
||||||
static::assertSame(302, $result->getStatusCode());
|
static::assertSame(302, $result->getStatusCode());
|
||||||
static::assertSame(
|
static::assertSame(
|
||||||
|
|
|
@ -91,7 +91,7 @@ public function testMiddlewareExecutionWithFrontException(): void
|
||||||
$controller = function (): void {
|
$controller = function (): void {
|
||||||
$exception = new LoginBannedException();
|
$exception = new LoginBannedException();
|
||||||
|
|
||||||
throw new $exception;
|
throw new $exception();
|
||||||
};
|
};
|
||||||
|
|
||||||
$pageBuilder = $this->createMock(PageBuilder::class);
|
$pageBuilder = $this->createMock(PageBuilder::class);
|
||||||
|
@ -148,7 +148,8 @@ public function testMiddlewareExecutionWithServerException(): void
|
||||||
return $uri;
|
return $uri;
|
||||||
});
|
});
|
||||||
|
|
||||||
$dummyException = new class() extends \Exception {};
|
$dummyException = new class () extends \Exception {
|
||||||
|
};
|
||||||
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
$controller = function () use ($dummyException): void {
|
$controller = function () use ($dummyException): void {
|
||||||
|
|
|
@ -122,8 +122,7 @@ public function testSaveNewConfig(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
return $parameters[$key];
|
return $parameters[$key];
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
$response = new Response();
|
$response = new Response();
|
||||||
|
|
||||||
|
@ -137,8 +136,7 @@ public function testSaveNewConfig(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
static::assertSame($parametersConfigMapping[$key], $value);
|
static::assertSame($parametersConfigMapping[$key], $value);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
$result = $this->controller->save($request, $response);
|
$result = $this->controller->save($request, $response);
|
||||||
static::assertSame(302, $result->getStatusCode());
|
static::assertSame(302, $result->getStatusCode());
|
||||||
|
|
|
@ -80,7 +80,10 @@ function (
|
||||||
string $selection,
|
string $selection,
|
||||||
bool $prependNoteUrl,
|
bool $prependNoteUrl,
|
||||||
string $indexUrl
|
string $indexUrl
|
||||||
) use ($parameters, $bookmarks): array {
|
) use (
|
||||||
|
$parameters,
|
||||||
|
$bookmarks
|
||||||
|
): array {
|
||||||
static::assertInstanceOf(BookmarkRawFormatter::class, $formatter);
|
static::assertInstanceOf(BookmarkRawFormatter::class, $formatter);
|
||||||
static::assertSame($parameters['selection'], $selection);
|
static::assertSame($parameters['selection'], $selection);
|
||||||
static::assertTrue($prependNoteUrl);
|
static::assertTrue($prependNoteUrl);
|
||||||
|
|
|
@ -74,7 +74,10 @@ public function testImportDefault(): void
|
||||||
function (
|
function (
|
||||||
array $post,
|
array $post,
|
||||||
UploadedFileInterface $file
|
UploadedFileInterface $file
|
||||||
) use ($parameters, $requestFile): string {
|
) use (
|
||||||
|
$parameters,
|
||||||
|
$requestFile
|
||||||
|
): string {
|
||||||
static::assertSame($parameters, $post);
|
static::assertSame($parameters, $post);
|
||||||
static::assertSame($requestFile, $file);
|
static::assertSame($requestFile, $file);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class PluginsControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
use FrontAdminControllerMockHelper;
|
use FrontAdminControllerMockHelper;
|
||||||
|
|
||||||
const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4'];
|
protected const PLUGIN_NAMES = ['plugin1', 'plugin2', 'plugin3', 'plugin4'];
|
||||||
|
|
||||||
/** @var PluginsController */
|
/** @var PluginsController */
|
||||||
protected $controller;
|
protected $controller;
|
||||||
|
@ -29,13 +29,17 @@ public function setUp(): void
|
||||||
|
|
||||||
mkdir($path = __DIR__ . '/folder');
|
mkdir($path = __DIR__ . '/folder');
|
||||||
PluginManager::$PLUGINS_PATH = $path;
|
PluginManager::$PLUGINS_PATH = $path;
|
||||||
array_map(function (string $plugin) use ($path) { touch($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
array_map(function (string $plugin) use ($path) {
|
||||||
|
touch($path . '/' . $plugin);
|
||||||
|
}, static::PLUGIN_NAMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
$path = __DIR__ . '/folder';
|
$path = __DIR__ . '/folder';
|
||||||
array_map(function (string $plugin) use ($path) { unlink($path . '/' . $plugin); }, static::PLUGIN_NAMES);
|
array_map(function (string $plugin) use ($path) {
|
||||||
|
unlink($path . '/' . $plugin);
|
||||||
|
}, static::PLUGIN_NAMES);
|
||||||
rmdir($path);
|
rmdir($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -365,5 +365,4 @@ public function testSaveBookmarkWrongToken(): void
|
||||||
|
|
||||||
$this->controller->save($request, $response);
|
$this->controller->save($request, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,7 @@ public function testIndexDefaultFirstPage(): void
|
||||||
(new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
|
(new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'),
|
||||||
(new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'),
|
(new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'),
|
||||||
(new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'),
|
(new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'),
|
||||||
], 0, 2)
|
], 0, 2));
|
||||||
);
|
|
||||||
|
|
||||||
$this->container->sessionManager
|
$this->container->sessionManager
|
||||||
->method('getSessionParameter')
|
->method('getSessionParameter')
|
||||||
|
|
|
@ -285,7 +285,9 @@ public function testValidIndexControllerInvokeHeightAdjustment(): void
|
||||||
static::assertCount(7, $assignedVariables['linksToDisplay']);
|
static::assertCount(7, $assignedVariables['linksToDisplay']);
|
||||||
|
|
||||||
$columnIds = function (array $column): array {
|
$columnIds = function (array $column): array {
|
||||||
return array_map(function (array $item): int { return $item['id']; }, $column);
|
return array_map(function (array $item): int {
|
||||||
|
return $item['id'];
|
||||||
|
}, $column);
|
||||||
};
|
};
|
||||||
|
|
||||||
static::assertSame([1, 4, 6], $columnIds($assignedVariables['cols'][0]));
|
static::assertSame([1, 4, 6], $columnIds($assignedVariables['cols'][0]));
|
||||||
|
@ -366,8 +368,7 @@ public function testValidRssControllerInvokeDefault(): void
|
||||||
$cachedPage->expects(static::once())->method('cache')->with('dailyrss');
|
$cachedPage->expects(static::once())->method('cache')->with('dailyrss');
|
||||||
|
|
||||||
return $cachedPage;
|
return $cachedPage;
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Save RainTPL assigned variables
|
// Save RainTPL assigned variables
|
||||||
$assignedVariables = [];
|
$assignedVariables = [];
|
||||||
|
|
|
@ -41,7 +41,8 @@ public function testDisplayFrontExceptionError(): void
|
||||||
$result = ($this->controller)(
|
$result = ($this->controller)(
|
||||||
$request,
|
$request,
|
||||||
$response,
|
$response,
|
||||||
new class($message, $errorCode) extends ShaarliFrontException {}
|
new class ($message, $errorCode) extends ShaarliFrontException {
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
static::assertSame($errorCode, $result->getStatusCode());
|
static::assertSame($errorCode, $result->getStatusCode());
|
||||||
|
|
|
@ -118,5 +118,5 @@ protected static function generateString(int $length): string
|
||||||
/**
|
/**
|
||||||
* Force to be used in PHPUnit context.
|
* Force to be used in PHPUnit context.
|
||||||
*/
|
*/
|
||||||
protected abstract function isInTestsContext(): bool;
|
abstract protected function isInTestsContext(): bool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class InstallControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
use FrontControllerMockHelper;
|
use FrontControllerMockHelper;
|
||||||
|
|
||||||
const MOCK_FILE = '.tmp';
|
protected const MOCK_FILE = '.tmp';
|
||||||
|
|
||||||
/** @var InstallController */
|
/** @var InstallController */
|
||||||
protected $controller;
|
protected $controller;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Helper;
|
namespace Shaarli\Helper;
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\FakeApplicationUtils;
|
use Shaarli\Tests\Utils\FakeApplicationUtils;
|
||||||
|
|
||||||
require_once 'tests/utils/FakeApplicationUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for Shaarli utilities
|
* Unitary tests for Shaarli utilities
|
||||||
|
@ -301,7 +300,7 @@ public function testCheckCurrentResourcePermissions()
|
||||||
$conf->set('resource.update_check', 'data/lastupdatecheck.txt');
|
$conf->set('resource.update_check', 'data/lastupdatecheck.txt');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(),
|
[],
|
||||||
ApplicationUtils::checkResourcePermissions($conf)
|
ApplicationUtils::checkResourcePermissions($conf)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +323,7 @@ public function testCheckCurrentResourcePermissionsErrors()
|
||||||
$conf->set('resource.raintpl_theme', 'null/tpl/default');
|
$conf->set('resource.raintpl_theme', 'null/tpl/default');
|
||||||
$conf->set('resource.update_check', 'null/data/lastupdatecheck.txt');
|
$conf->set('resource.update_check', 'null/data/lastupdatecheck.txt');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'"null/tpl" directory is not readable',
|
'"null/tpl" directory is not readable',
|
||||||
'"null/tpl/default" directory is not readable',
|
'"null/tpl/default" directory is not readable',
|
||||||
'"null/cache" directory is not readable',
|
'"null/cache" directory is not readable',
|
||||||
|
@ -335,7 +334,7 @@ public function testCheckCurrentResourcePermissionsErrors()
|
||||||
'"null/pagecache" directory is not writable',
|
'"null/pagecache" directory is not writable',
|
||||||
'"null/tmp" directory is not readable',
|
'"null/tmp" directory is not readable',
|
||||||
'"null/tmp" directory is not writable'
|
'"null/tmp" directory is not writable'
|
||||||
),
|
],
|
||||||
ApplicationUtils::checkResourcePermissions($conf)
|
ApplicationUtils::checkResourcePermissions($conf)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
namespace Shaarli\Helper;
|
namespace Shaarli\Helper;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Shaarli\Bookmark\Bookmark;
|
use Shaarli\Bookmark\Bookmark;
|
||||||
|
@ -147,7 +148,8 @@ public function getDescriptionByTypeExceptionUnknownType(): void
|
||||||
/**
|
/**
|
||||||
* @dataProvider getRssLengthsByType
|
* @dataProvider getRssLengthsByType
|
||||||
*/
|
*/
|
||||||
public function testGeRssLengthsByType(string $type): void {
|
public function testGeRssLengthsByType(string $type): void
|
||||||
|
{
|
||||||
$length = DailyPageHelper::getRssLengthByType($type);
|
$length = DailyPageHelper::getRssLengthByType($type);
|
||||||
|
|
||||||
static::assertIsInt($length);
|
static::assertIsInt($length);
|
||||||
|
@ -208,31 +210,31 @@ public function getRequestedTypes(): array
|
||||||
public function getRequestedDateTimes(): array
|
public function getRequestedDateTimes(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[DailyPageHelper::DAY, '20201013', null, new \DateTime('2020-10-13')],
|
[DailyPageHelper::DAY, '20201013', null, new DateTime('2020-10-13')],
|
||||||
[
|
[
|
||||||
DailyPageHelper::DAY,
|
DailyPageHelper::DAY,
|
||||||
'',
|
'',
|
||||||
(new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')),
|
(new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')),
|
||||||
$date,
|
$date,
|
||||||
],
|
],
|
||||||
[DailyPageHelper::DAY, '', null, new \DateTime()],
|
[DailyPageHelper::DAY, '', null, new DateTime()],
|
||||||
[DailyPageHelper::WEEK, '202030', null, new \DateTime('2020-07-20')],
|
[DailyPageHelper::WEEK, '202030', null, new DateTime('2020-07-20')],
|
||||||
[
|
[
|
||||||
DailyPageHelper::WEEK,
|
DailyPageHelper::WEEK,
|
||||||
'',
|
'',
|
||||||
(new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')),
|
(new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')),
|
||||||
new \DateTime('2020-10-13'),
|
new DateTime('2020-10-13'),
|
||||||
],
|
],
|
||||||
[DailyPageHelper::WEEK, '', null, new \DateTime(), 'Ym'],
|
[DailyPageHelper::WEEK, '', null, new DateTime(), 'Ym'],
|
||||||
[DailyPageHelper::MONTH, '202008', null, new \DateTime('2020-08-01'), 'Ym'],
|
[DailyPageHelper::MONTH, '202008', null, new DateTime('2020-08-01'), 'Ym'],
|
||||||
[
|
[
|
||||||
DailyPageHelper::MONTH,
|
DailyPageHelper::MONTH,
|
||||||
'',
|
'',
|
||||||
(new Bookmark())->setCreated($date = new \DateTime('2020-10-13 12:05:31')),
|
(new Bookmark())->setCreated($date = new DateTime('2020-10-13 12:05:31')),
|
||||||
new \DateTime('2020-10-13'),
|
new DateTime('2020-10-13'),
|
||||||
'Ym'
|
'Ym'
|
||||||
],
|
],
|
||||||
[DailyPageHelper::MONTH, '', null, new \DateTime(), 'Ym'],
|
[DailyPageHelper::MONTH, '', null, new DateTime(), 'Ym'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,9 +256,9 @@ public function getFormatsByType(): array
|
||||||
public function getStartDatesByType(): array
|
public function getStartDatesByType(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-09 00:00:00')],
|
[DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-09 00:00:00')],
|
||||||
[DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-05 00:00:00')],
|
[DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-05 00:00:00')],
|
||||||
[DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-01 00:00:00')],
|
[DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-01 00:00:00')],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,9 +268,9 @@ public function getStartDatesByType(): array
|
||||||
public function getEndDatesByType(): array
|
public function getEndDatesByType(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-09 23:59:59')],
|
[DailyPageHelper::DAY, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-09 23:59:59')],
|
||||||
[DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-11 23:59:59')],
|
[DailyPageHelper::WEEK, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-11 23:59:59')],
|
||||||
[DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new \DateTime('2020-10-31 23:59:59')],
|
[DailyPageHelper::MONTH, new DateTimeImmutable('2020-10-09 04:05:06'), new DateTime('2020-10-31 23:59:59')],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,20 +323,20 @@ public function getCacheDatePeriodByType(): array
|
||||||
[
|
[
|
||||||
DailyPageHelper::DAY,
|
DailyPageHelper::DAY,
|
||||||
new DateTimeImmutable('2020-10-09 04:05:06'),
|
new DateTimeImmutable('2020-10-09 04:05:06'),
|
||||||
new \DateTime('2020-10-09 00:00:00'),
|
new DateTime('2020-10-09 00:00:00'),
|
||||||
new \DateTime('2020-10-09 23:59:59'),
|
new DateTime('2020-10-09 23:59:59'),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
DailyPageHelper::WEEK,
|
DailyPageHelper::WEEK,
|
||||||
new DateTimeImmutable('2020-10-09 04:05:06'),
|
new DateTimeImmutable('2020-10-09 04:05:06'),
|
||||||
new \DateTime('2020-10-05 00:00:00'),
|
new DateTime('2020-10-05 00:00:00'),
|
||||||
new \DateTime('2020-10-11 23:59:59'),
|
new DateTime('2020-10-11 23:59:59'),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
DailyPageHelper::MONTH,
|
DailyPageHelper::MONTH,
|
||||||
new DateTimeImmutable('2020-10-09 04:05:06'),
|
new DateTimeImmutable('2020-10-09 04:05:06'),
|
||||||
new \DateTime('2020-10-01 00:00:00'),
|
new DateTime('2020-10-01 00:00:00'),
|
||||||
new \DateTime('2020-10-31 23:59:59'),
|
new DateTime('2020-10-31 23:59:59'),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for client_ip_id()
|
* Unitary tests for client_ip_id()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for get_http_response()
|
* Unitary tests for get_http_response()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for getIpAddressFromProxy()
|
* Unitary tests for getIpAddressFromProxy()
|
||||||
*/
|
*/
|
||||||
|
@ -15,7 +13,7 @@ class GetIpAdressFromProxyTest extends \Shaarli\TestCase
|
||||||
*/
|
*/
|
||||||
public function testWithoutProxy()
|
public function testWithoutProxy()
|
||||||
{
|
{
|
||||||
$this->assertFalse(getIpAddressFromProxy(array(), array()));
|
$this->assertFalse(getIpAddressFromProxy([], []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,8 +22,8 @@ public function testWithoutProxy()
|
||||||
public function testWithOneForwardedIp()
|
public function testWithOneForwardedIp()
|
||||||
{
|
{
|
||||||
$ip = '1.1.1.1';
|
$ip = '1.1.1.1';
|
||||||
$server = array('HTTP_X_FORWARDED_FOR' => $ip);
|
$server = ['HTTP_X_FORWARDED_FOR' => $ip];
|
||||||
$this->assertEquals($ip, getIpAddressFromProxy($server, array()));
|
$this->assertEquals($ip, getIpAddressFromProxy($server, []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,11 +34,11 @@ public function testWithMultipleForwardedIp()
|
||||||
$ip = '1.1.1.1';
|
$ip = '1.1.1.1';
|
||||||
$ip2 = '2.2.2.2';
|
$ip2 = '2.2.2.2';
|
||||||
|
|
||||||
$server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
|
$server = ['HTTP_X_FORWARDED_FOR' => $ip . ',' . $ip2];
|
||||||
$this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
|
$this->assertEquals($ip2, getIpAddressFromProxy($server, []));
|
||||||
|
|
||||||
$server = array('HTTP_X_FORWARDED_FOR' => $ip .' , '. $ip2);
|
$server = ['HTTP_X_FORWARDED_FOR' => $ip . ' , ' . $ip2];
|
||||||
$this->assertEquals($ip2, getIpAddressFromProxy($server, array()));
|
$this->assertEquals($ip2, getIpAddressFromProxy($server, []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,11 +49,11 @@ public function testWithTrustedIp()
|
||||||
$ip = '1.1.1.1';
|
$ip = '1.1.1.1';
|
||||||
$ip2 = '2.2.2.2';
|
$ip2 = '2.2.2.2';
|
||||||
|
|
||||||
$server = array('HTTP_X_FORWARDED_FOR' => $ip);
|
$server = ['HTTP_X_FORWARDED_FOR' => $ip];
|
||||||
$this->assertFalse(getIpAddressFromProxy($server, array($ip)));
|
$this->assertFalse(getIpAddressFromProxy($server, [$ip]));
|
||||||
|
|
||||||
$server = array('HTTP_X_FORWARDED_FOR' => $ip .','. $ip2);
|
$server = ['HTTP_X_FORWARDED_FOR' => $ip . ',' . $ip2];
|
||||||
$this->assertEquals($ip2, getIpAddressFromProxy($server, array($ip)));
|
$this->assertEquals($ip2, getIpAddressFromProxy($server, [$ip]));
|
||||||
$this->assertFalse(getIpAddressFromProxy($server, array($ip, $ip2)));
|
$this->assertFalse(getIpAddressFromProxy($server, [$ip, $ip2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
@ -7,8 +8,6 @@
|
||||||
|
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for index_url()
|
* Unitary tests for index_url()
|
||||||
*/
|
*/
|
||||||
|
@ -22,24 +21,24 @@ public function testRemoveIndex()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/',
|
'http://host.tld/',
|
||||||
index_url(
|
index_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/index.php'
|
'SCRIPT_NAME' => '/index.php'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/admin/',
|
'http://host.tld/admin/',
|
||||||
index_url(
|
index_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/index.php'
|
'SCRIPT_NAME' => '/admin/index.php'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -52,24 +51,24 @@ public function testOtherResource()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/page.php',
|
'http://host.tld/page.php',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/page.php'
|
'SCRIPT_NAME' => '/page.php'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/admin/page.php',
|
'http://host.tld/admin/page.php',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/page.php'
|
'SCRIPT_NAME' => '/admin/page.php'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -82,26 +81,26 @@ public function testPageUrlWithRoute()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/picture-wall',
|
'http://host.tld/picture-wall',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/index.php',
|
'SCRIPT_NAME' => '/index.php',
|
||||||
'REQUEST_URI' => '/picture-wall',
|
'REQUEST_URI' => '/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/admin/picture-wall',
|
'http://host.tld/admin/picture-wall',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/index.php',
|
'SCRIPT_NAME' => '/admin/index.php',
|
||||||
'REQUEST_URI' => '/admin/picture-wall',
|
'REQUEST_URI' => '/admin/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -114,26 +113,26 @@ public function testPageUrlWithRouteUnderSubfolder()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/subfolder/picture-wall',
|
'http://host.tld/subfolder/picture-wall',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/subfolder/index.php',
|
'SCRIPT_NAME' => '/subfolder/index.php',
|
||||||
'REQUEST_URI' => '/subfolder/picture-wall',
|
'REQUEST_URI' => '/subfolder/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/subfolder/admin/picture-wall',
|
'http://host.tld/subfolder/admin/picture-wall',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/subfolder/admin/index.php',
|
'SCRIPT_NAME' => '/subfolder/admin/index.php',
|
||||||
'REQUEST_URI' => '/subfolder/admin/picture-wall',
|
'REQUEST_URI' => '/subfolder/admin/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,26 +25,26 @@ public function testIndexUrlWithConstantDefined()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://other-host.tld/subfolder/',
|
'http://other-host.tld/subfolder/',
|
||||||
index_url(
|
index_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/index.php',
|
'SCRIPT_NAME' => '/index.php',
|
||||||
'REQUEST_URI' => '/picture-wall',
|
'REQUEST_URI' => '/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://other-host.tld/subfolder/',
|
'http://other-host.tld/subfolder/',
|
||||||
index_url(
|
index_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/index.php',
|
'SCRIPT_NAME' => '/admin/index.php',
|
||||||
'REQUEST_URI' => '/admin/picture-wall',
|
'REQUEST_URI' => '/admin/picture-wall',
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class IsHttpsTest
|
* Class IsHttpsTest
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for page_url()
|
* Unitary tests for page_url()
|
||||||
*/
|
*/
|
||||||
|
@ -20,26 +19,26 @@ public function testRemoveIndex()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/?p1=v1&p2=v2',
|
'http://host.tld/?p1=v1&p2=v2',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/index.php',
|
'SCRIPT_NAME' => '/index.php',
|
||||||
'QUERY_STRING' => 'p1=v1&p2=v2'
|
'QUERY_STRING' => 'p1=v1&p2=v2'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/admin/?action=edit_tag',
|
'http://host.tld/admin/?action=edit_tag',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/index.php',
|
'SCRIPT_NAME' => '/admin/index.php',
|
||||||
'QUERY_STRING' => 'action=edit_tag'
|
'QUERY_STRING' => 'action=edit_tag'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -52,26 +51,26 @@ public function testOtherResource()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/page.php?p1=v1&p2=v2',
|
'http://host.tld/page.php?p1=v1&p2=v2',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/page.php',
|
'SCRIPT_NAME' => '/page.php',
|
||||||
'QUERY_STRING' => 'p1=v1&p2=v2'
|
'QUERY_STRING' => 'p1=v1&p2=v2'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld/admin/page.php?action=edit_tag',
|
'http://host.tld/admin/page.php?action=edit_tag',
|
||||||
page_url(
|
page_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'SCRIPT_NAME' => '/admin/page.php',
|
'SCRIPT_NAME' => '/admin/page.php',
|
||||||
'QUERY_STRING' => 'action=edit_tag'
|
'QUERY_STRING' => 'action=edit_tag'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HttpUtils' tests
|
* HttpUtils' tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/HttpUtils.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for server_url()
|
* Unitary tests for server_url()
|
||||||
*/
|
*/
|
||||||
|
@ -20,22 +19,22 @@ public function testHttpsScheme()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'ON',
|
'HTTPS' => 'ON',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '443'
|
'SERVER_PORT' => '443'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:8080',
|
'https://host.tld:8080',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'ON',
|
'HTTPS' => 'ON',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '8080'
|
'SERVER_PORT' => '8080'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -48,22 +47,22 @@ public function testHttpsProxyForwardedHost()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:8080',
|
'https://host.tld:8080',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https',
|
'HTTP_X_FORWARDED_PROTO' => 'https',
|
||||||
'HTTP_X_FORWARDED_PORT' => '8080',
|
'HTTP_X_FORWARDED_PORT' => '8080',
|
||||||
'HTTP_X_FORWARDED_HOST' => 'host.tld'
|
'HTTP_X_FORWARDED_HOST' => 'host.tld'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:4974',
|
'https://host.tld:4974',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https, https',
|
'HTTP_X_FORWARDED_PROTO' => 'https, https',
|
||||||
'HTTP_X_FORWARDED_PORT' => '4974, 80',
|
'HTTP_X_FORWARDED_PORT' => '4974, 80',
|
||||||
'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com'
|
'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -76,51 +75,51 @@ public function testHttpsProxyForward()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:8080',
|
'https://host.tld:8080',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https',
|
'HTTP_X_FORWARDED_PROTO' => 'https',
|
||||||
'HTTP_X_FORWARDED_PORT' => '8080'
|
'HTTP_X_FORWARDED_PORT' => '8080'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https'
|
'HTTP_X_FORWARDED_PROTO' => 'https'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https',
|
'HTTP_X_FORWARDED_PROTO' => 'https',
|
||||||
'HTTP_X_FORWARDED_PORT' => '443'
|
'HTTP_X_FORWARDED_PORT' => '443'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:4974',
|
'https://host.tld:4974',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https, https',
|
'HTTP_X_FORWARDED_PROTO' => 'https, https',
|
||||||
'HTTP_X_FORWARDED_PORT' => '4974, 80'
|
'HTTP_X_FORWARDED_PORT' => '4974, 80'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -134,11 +133,11 @@ public function testPort()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld:8080',
|
'http://host.tld:8080',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'OFF',
|
'HTTPS' => 'OFF',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '8080'
|
'SERVER_PORT' => '8080'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -146,11 +145,11 @@ public function testPort()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:8080',
|
'https://host.tld:8080',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'ON',
|
'HTTPS' => 'ON',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '8080'
|
'SERVER_PORT' => '8080'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -163,11 +162,11 @@ public function testStandardHttpPort()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'http://host.tld',
|
'http://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'OFF',
|
'HTTPS' => 'OFF',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80'
|
'SERVER_PORT' => '80'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -180,11 +179,11 @@ public function testStandardHttpsPort()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'ON',
|
'HTTPS' => 'ON',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '443'
|
'SERVER_PORT' => '443'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -197,26 +196,26 @@ public function testHttpWithPort433()
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'http',
|
'HTTP_X_FORWARDED_PROTO' => 'http',
|
||||||
'HTTP_X_FORWARDED_PORT' => '443'
|
'HTTP_X_FORWARDED_PORT' => '443'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld',
|
'https://host.tld',
|
||||||
server_url(
|
server_url(
|
||||||
array(
|
[
|
||||||
'HTTPS' => 'Off',
|
'HTTPS' => 'Off',
|
||||||
'SERVER_NAME' => 'host.tld',
|
'SERVER_NAME' => 'host.tld',
|
||||||
'SERVER_PORT' => '80',
|
'SERVER_PORT' => '80',
|
||||||
'HTTP_X_FORWARDED_PROTO' => 'https, http',
|
'HTTP_X_FORWARDED_PROTO' => 'https, http',
|
||||||
'HTTP_X_FORWARDED_PORT' => '443, 80'
|
'HTTP_X_FORWARDED_PORT' => '443, 80'
|
||||||
)
|
]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,12 @@ function (&$charset) use (
|
||||||
->expects(static::once())
|
->expects(static::once())
|
||||||
->method('getCurlDownloadCallback')
|
->method('getCurlDownloadCallback')
|
||||||
->willReturnCallback(
|
->willReturnCallback(
|
||||||
function (&$charset, &$title, &$description, &$tags) use (
|
function (
|
||||||
|
&$charset,
|
||||||
|
&$title,
|
||||||
|
&$description,
|
||||||
|
&$tags
|
||||||
|
) use (
|
||||||
$remoteCharset,
|
$remoteCharset,
|
||||||
$remoteTitle,
|
$remoteTitle,
|
||||||
$remoteDesc,
|
$remoteDesc,
|
||||||
|
@ -124,7 +129,8 @@ public function testEmptyRetrieval(): void
|
||||||
->method('getCurlDownloadCallback')
|
->method('getCurlDownloadCallback')
|
||||||
->willReturnCallback(
|
->willReturnCallback(
|
||||||
function (): callable {
|
function (): callable {
|
||||||
return function (): void {};
|
return function (): void {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
@ -133,7 +139,8 @@ function (): callable {
|
||||||
->method('getCurlHeaderCallback')
|
->method('getCurlHeaderCallback')
|
||||||
->willReturnCallback(
|
->willReturnCallback(
|
||||||
function (): callable {
|
function (): callable {
|
||||||
return function (): void {};
|
return function (): void {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UrlUtils's tests
|
* UrlUtils's tests
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for cleanup_url()
|
* Unitary tests for cleanup_url()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/UrlUtils.php';
|
|
||||||
|
|
||||||
class CleanupUrlTest extends \Shaarli\TestCase
|
class CleanupUrlTest extends \Shaarli\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for get_url_scheme()
|
* Unitary tests for get_url_scheme()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/UrlUtils.php';
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
class GetUrlSchemeTest extends \Shaarli\TestCase
|
class GetUrlSchemeTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get empty scheme string for empty UrlUtils
|
* Get empty scheme string for empty UrlUtils
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unpares UrlUtils's tests
|
* Unpares UrlUtils's tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/UrlUtils.php';
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for unparse_url()
|
* Unitary tests for unparse_url()
|
||||||
*/
|
*/
|
||||||
class UnparseUrlTest extends \Shaarli\TestCase
|
class UnparseUrlTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Thanks for building nothing
|
* Thanks for building nothing
|
||||||
*/
|
*/
|
||||||
public function testUnparseEmptyArray()
|
public function testUnparseEmptyArray()
|
||||||
{
|
{
|
||||||
$this->assertEquals('', unparse_url(array()));
|
$this->assertEquals('', unparse_url([]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
namespace Shaarli\Http;
|
namespace Shaarli\Http;
|
||||||
|
|
||||||
require_once 'application/http/UrlUtils.php';
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WhitelistProtocolsTest
|
* Class WhitelistProtocolsTest
|
||||||
*
|
*
|
||||||
* Test whitelist_protocols() function of UrlUtils.
|
* Test whitelist_protocols() function of UrlUtils.
|
||||||
*/
|
*/
|
||||||
class WhitelistProtocolsTest extends \Shaarli\TestCase
|
class WhitelistProtocolsTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Test whitelist_protocols() on a note (relative URL).
|
* Test whitelist_protocols() on a note (relative URL).
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'tests/bootstrap.php';
|
require_once 'tests/bootstrap.php';
|
||||||
|
|
||||||
if (! empty(getenv('UT_LOCALE'))) {
|
if (! empty(getenv('UT_LOCALE'))) {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'tests/UtilsTest.php';
|
namespace Shaarli\Tests;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class UtilsDeTest extends UtilsTest
|
class UtilsDeTest extends UtilsTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'tests/UtilsTest.php';
|
namespace Shaarli\Tests;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class UtilsEnTest extends UtilsTest
|
class UtilsEnTest extends UtilsTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Tests;
|
||||||
namespace Shaarli;
|
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
|
use Shaarli\Languages;
|
||||||
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LanguagesFrTest
|
* Class LanguagesFrTest
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @package Shaarli
|
* @package Shaarli
|
||||||
*/
|
*/
|
||||||
class LanguagesFrTest extends \Shaarli\TestCase
|
class LanguagesFrTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string Config file path (without extension).
|
* @var string Config file path (without extension).
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'tests/UtilsTest.php';
|
namespace Shaarli\Tests;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
class UtilsFrTest extends UtilsTest
|
class UtilsFrTest extends UtilsTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Updater;
|
namespace Shaarli\Updater;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link datastore tests
|
* Link datastore tests
|
||||||
*/
|
*/
|
||||||
|
@ -6,14 +7,10 @@
|
||||||
namespace Shaarli\Legacy;
|
namespace Shaarli\Legacy;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use ReferenceLinkDB;
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use Shaarli;
|
use Shaarli;
|
||||||
use Shaarli\Bookmark\Bookmark;
|
use Shaarli\Bookmark\Bookmark;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
require_once 'application/Utils.php';
|
|
||||||
require_once 'tests/utils/ReferenceLinkDB.php';
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for LegacyLinkDBTest
|
* Unitary tests for LegacyLinkDBTest
|
||||||
|
@ -118,7 +115,7 @@ public function testCheckDBNew()
|
||||||
$this->assertFileNotExists(self::$testDatastore);
|
$this->assertFileNotExists(self::$testDatastore);
|
||||||
|
|
||||||
$checkDB = self::getMethod('check');
|
$checkDB = self::getMethod('check');
|
||||||
$checkDB->invokeArgs($linkDB, array());
|
$checkDB->invokeArgs($linkDB, []);
|
||||||
$this->assertFileExists(self::$testDatastore);
|
$this->assertFileExists(self::$testDatastore);
|
||||||
|
|
||||||
// ensure the correct data has been written
|
// ensure the correct data has been written
|
||||||
|
@ -135,7 +132,7 @@ public function testCheckDBLoad()
|
||||||
$this->assertGreaterThan(0, $datastoreSize);
|
$this->assertGreaterThan(0, $datastoreSize);
|
||||||
|
|
||||||
$checkDB = self::getMethod('check');
|
$checkDB = self::getMethod('check');
|
||||||
$checkDB->invokeArgs($linkDB, array());
|
$checkDB->invokeArgs($linkDB, []);
|
||||||
|
|
||||||
// ensure the datastore is left unmodified
|
// ensure the datastore is left unmodified
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -185,7 +182,7 @@ public function testSave()
|
||||||
$testDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$testDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
$dbSize = sizeof($testDB);
|
$dbSize = sizeof($testDB);
|
||||||
|
|
||||||
$link = array(
|
$link = [
|
||||||
'id' => 43,
|
'id' => 43,
|
||||||
'title' => 'an additional link',
|
'title' => 'an additional link',
|
||||||
'url' => 'http://dum.my',
|
'url' => 'http://dum.my',
|
||||||
|
@ -193,7 +190,7 @@ public function testSave()
|
||||||
'private' => 0,
|
'private' => 0,
|
||||||
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150518_190000'),
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, '20150518_190000'),
|
||||||
'tags' => 'unit test'
|
'tags' => 'unit test'
|
||||||
);
|
];
|
||||||
$testDB[$link['id']] = $link;
|
$testDB[$link['id']] = $link;
|
||||||
$testDB->save('tests');
|
$testDB->save('tests');
|
||||||
|
|
||||||
|
@ -239,12 +236,12 @@ public function testCountHiddenPublic()
|
||||||
public function testDays()
|
public function testDays()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('20100309', '20100310', '20121206', '20121207', '20130614', '20150310'),
|
['20100309', '20100310', '20121206', '20121207', '20130614', '20150310'],
|
||||||
self::$publicLinkDB->days()
|
self::$publicLinkDB->days()
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'),
|
['20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'],
|
||||||
self::$privateLinkDB->days()
|
self::$privateLinkDB->days()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -280,7 +277,7 @@ public function testGetUnknownLinkFromURL()
|
||||||
public function testAllTags()
|
public function testAllTags()
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'web' => 3,
|
'web' => 3,
|
||||||
'cartoon' => 2,
|
'cartoon' => 2,
|
||||||
'gnu' => 2,
|
'gnu' => 2,
|
||||||
|
@ -300,12 +297,12 @@ public function testAllTags()
|
||||||
'coding-style' => 1,
|
'coding-style' => 1,
|
||||||
'quality' => 1,
|
'quality' => 1,
|
||||||
'standards' => 1,
|
'standards' => 1,
|
||||||
),
|
],
|
||||||
self::$publicLinkDB->linksCountPerTag()
|
self::$publicLinkDB->linksCountPerTag()
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'web' => 4,
|
'web' => 4,
|
||||||
'cartoon' => 3,
|
'cartoon' => 3,
|
||||||
'gnu' => 2,
|
'gnu' => 2,
|
||||||
|
@ -332,11 +329,11 @@ public function testAllTags()
|
||||||
'coding-style' => 1,
|
'coding-style' => 1,
|
||||||
'quality' => 1,
|
'quality' => 1,
|
||||||
'standards' => 1,
|
'standards' => 1,
|
||||||
),
|
],
|
||||||
self::$privateLinkDB->linksCountPerTag()
|
self::$privateLinkDB->linksCountPerTag()
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'web' => 4,
|
'web' => 4,
|
||||||
'cartoon' => 2,
|
'cartoon' => 2,
|
||||||
'gnu' => 1,
|
'gnu' => 1,
|
||||||
|
@ -349,17 +346,17 @@ public function testAllTags()
|
||||||
'Mercurial' => 1,
|
'Mercurial' => 1,
|
||||||
'.hidden' => 1,
|
'.hidden' => 1,
|
||||||
'hashtag' => 1,
|
'hashtag' => 1,
|
||||||
),
|
],
|
||||||
self::$privateLinkDB->linksCountPerTag(['web'])
|
self::$privateLinkDB->linksCountPerTag(['web'])
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array(
|
[
|
||||||
'web' => 1,
|
'web' => 1,
|
||||||
'html' => 1,
|
'html' => 1,
|
||||||
'w3c' => 1,
|
'w3c' => 1,
|
||||||
'css' => 1,
|
'css' => 1,
|
||||||
'Mercurial' => 1,
|
'Mercurial' => 1,
|
||||||
),
|
],
|
||||||
self::$privateLinkDB->linksCountPerTag(['web'], 'private')
|
self::$privateLinkDB->linksCountPerTag(['web'], 'private')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +367,7 @@ public function testAllTags()
|
||||||
public function testFilterString()
|
public function testFilterString()
|
||||||
{
|
{
|
||||||
$tags = 'dev cartoon';
|
$tags = 'dev cartoon';
|
||||||
$request = array('searchtags' => $tags);
|
$request = ['searchtags' => $tags];
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
2,
|
2,
|
||||||
count(self::$privateLinkDB->filterSearch($request, true, false))
|
count(self::$privateLinkDB->filterSearch($request, true, false))
|
||||||
|
@ -382,8 +379,8 @@ public function testFilterString()
|
||||||
*/
|
*/
|
||||||
public function testFilterArray()
|
public function testFilterArray()
|
||||||
{
|
{
|
||||||
$tags = array('dev', 'cartoon');
|
$tags = ['dev', 'cartoon'];
|
||||||
$request = array('searchtags' => $tags);
|
$request = ['searchtags' => $tags];
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
2,
|
2,
|
||||||
count(self::$privateLinkDB->filterSearch($request, true, false))
|
count(self::$privateLinkDB->filterSearch($request, true, false))
|
||||||
|
@ -397,7 +394,7 @@ public function testFilterArray()
|
||||||
public function testHiddenTags()
|
public function testHiddenTags()
|
||||||
{
|
{
|
||||||
$tags = '.hidden';
|
$tags = '.hidden';
|
||||||
$request = array('searchtags' => $tags);
|
$request = ['searchtags' => $tags];
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
count(self::$privateLinkDB->filterSearch($request, true, false))
|
count(self::$privateLinkDB->filterSearch($request, true, false))
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
namespace Shaarli\Bookmark;
|
namespace Shaarli\Bookmark;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use ReferenceLinkDB;
|
|
||||||
use Shaarli\Legacy\LegacyLinkDB;
|
use Shaarli\Legacy\LegacyLinkDB;
|
||||||
use Shaarli\Legacy\LegacyLinkFilter;
|
use Shaarli\Legacy\LegacyLinkFilter;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class LegacyLinkFilterTest.
|
* Class LegacyLinkFilterTest.
|
||||||
|
@ -450,28 +449,28 @@ public function testFilterCrossedSearch()
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
||||||
array($tags, $terms)
|
[$tags, $terms]
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
2,
|
2,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
||||||
array('', $terms)
|
['', $terms]
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
||||||
array(false, 'PSR-2')
|
[false, 'PSR-2']
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
count(self::$linkFilter->filter(
|
count(self::$linkFilter->filter(
|
||||||
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
LegacyLinkFilter::$FILTER_TAG | LegacyLinkFilter::$FILTER_TEXT,
|
||||||
array($tags, '')
|
[$tags, '']
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Updater;
|
namespace Shaarli\Updater;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
@ -9,18 +10,16 @@
|
||||||
use Shaarli\Config\ConfigPhp;
|
use Shaarli\Config\ConfigPhp;
|
||||||
use Shaarli\Legacy\LegacyLinkDB;
|
use Shaarli\Legacy\LegacyLinkDB;
|
||||||
use Shaarli\Legacy\LegacyUpdater;
|
use Shaarli\Legacy\LegacyUpdater;
|
||||||
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\updater\DummyUpdater;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
use Shaarli\Thumbnailer;
|
use Shaarli\Thumbnailer;
|
||||||
|
|
||||||
require_once 'application/updater/UpdaterUtils.php';
|
|
||||||
require_once 'tests/updater/DummyUpdater.php';
|
|
||||||
require_once 'tests/utils/ReferenceLinkDB.php';
|
|
||||||
require_once 'inc/rain.tpl.class.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UpdaterTest.
|
* Class UpdaterTest.
|
||||||
* Runs unit tests against the updater class.
|
* Runs unit tests against the updater class.
|
||||||
*/
|
*/
|
||||||
class LegacyUpdaterTest extends \Shaarli\TestCase
|
class LegacyUpdaterTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string Path to test datastore.
|
* @var string Path to test datastore.
|
||||||
|
@ -51,10 +50,10 @@ protected function setUp(): void
|
||||||
*/
|
*/
|
||||||
public function testReadEmptyUpdatesFile()
|
public function testReadEmptyUpdatesFile()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(), UpdaterUtils::readUpdatesFile(''));
|
$this->assertEquals([], UpdaterUtils::readUpdatesFile(''));
|
||||||
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
||||||
touch($updatesFile);
|
touch($updatesFile);
|
||||||
$this->assertEquals(array(), UpdaterUtils::readUpdatesFile($updatesFile));
|
$this->assertEquals([], UpdaterUtils::readUpdatesFile($updatesFile));
|
||||||
unlink($updatesFile);
|
unlink($updatesFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ public function testReadEmptyUpdatesFile()
|
||||||
public function testReadWriteUpdatesFile()
|
public function testReadWriteUpdatesFile()
|
||||||
{
|
{
|
||||||
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
||||||
$updatesMethods = array('m1', 'm2', 'm3');
|
$updatesMethods = ['m1', 'm2', 'm3'];
|
||||||
|
|
||||||
UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
|
UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
|
||||||
$readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
|
$readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
|
||||||
|
@ -86,7 +85,7 @@ public function testWriteEmptyUpdatesFile()
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
$this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
|
$this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
|
||||||
|
|
||||||
UpdaterUtils::writeUpdatesFile('', array('test'));
|
UpdaterUtils::writeUpdatesFile('', ['test']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,7 +100,7 @@ public function testWriteUpdatesFileNotWritable()
|
||||||
touch($updatesFile);
|
touch($updatesFile);
|
||||||
chmod($updatesFile, 0444);
|
chmod($updatesFile, 0444);
|
||||||
try {
|
try {
|
||||||
@UpdaterUtils::writeUpdatesFile($updatesFile, array('test'));
|
@UpdaterUtils::writeUpdatesFile($updatesFile, ['test']);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
unlink($updatesFile);
|
unlink($updatesFile);
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -115,17 +114,17 @@ public function testWriteUpdatesFileNotWritable()
|
||||||
*/
|
*/
|
||||||
public function testNoUpdates()
|
public function testNoUpdates()
|
||||||
{
|
{
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
'updateMethodException',
|
'updateMethodException',
|
||||||
);
|
];
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals(array(), $updater->update());
|
$this->assertEquals([], $updater->update());
|
||||||
|
|
||||||
$updater = new DummyUpdater(array(), array(), $this->conf, false);
|
$updater = new DummyUpdater([], [], $this->conf, false);
|
||||||
$this->assertEquals(array(), $updater->update());
|
$this->assertEquals([], $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,13 +132,13 @@ public function testNoUpdates()
|
||||||
*/
|
*/
|
||||||
public function testUpdatesFirstTime()
|
public function testUpdatesFirstTime()
|
||||||
{
|
{
|
||||||
$updates = array('updateMethodException',);
|
$updates = ['updateMethodException',];
|
||||||
$expectedUpdates = array(
|
$expectedUpdates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
);
|
];
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals($expectedUpdates, $updater->update());
|
$this->assertEquals($expectedUpdates, $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,14 +147,14 @@ public function testUpdatesFirstTime()
|
||||||
*/
|
*/
|
||||||
public function testOneUpdate()
|
public function testOneUpdate()
|
||||||
{
|
{
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
'updateMethodException',
|
'updateMethodException',
|
||||||
);
|
];
|
||||||
$expectedUpdate = array('updateMethodDummy2');
|
$expectedUpdate = ['updateMethodDummy2'];
|
||||||
|
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals($expectedUpdate, $updater->update());
|
$this->assertEquals($expectedUpdate, $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,13 +165,13 @@ public function testUpdateFailed()
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
|
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
);
|
];
|
||||||
|
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$updater->update();
|
$updater->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +196,7 @@ public function testUpdateMergeDeprecatedConfig()
|
||||||
$this->conf->setConfigFile('tests/updater/config');
|
$this->conf->setConfigFile('tests/updater/config');
|
||||||
|
|
||||||
// merge configs
|
// merge configs
|
||||||
$updater = new LegacyUpdater(array(), array(), $this->conf, true);
|
$updater = new LegacyUpdater([], [], $this->conf, true);
|
||||||
// This writes a new config file in tests/updater/config.php
|
// This writes a new config file in tests/updater/config.php
|
||||||
$updater->updateMethodMergeDeprecatedConfigFile();
|
$updater->updateMethodMergeDeprecatedConfigFile();
|
||||||
|
|
||||||
|
@ -214,7 +213,7 @@ public function testUpdateMergeDeprecatedConfig()
|
||||||
*/
|
*/
|
||||||
public function testMergeDeprecatedConfigNoFile()
|
public function testMergeDeprecatedConfigNoFile()
|
||||||
{
|
{
|
||||||
$updater = new LegacyUpdater(array(), array(), $this->conf, true);
|
$updater = new LegacyUpdater([], [], $this->conf, true);
|
||||||
$updater->updateMethodMergeDeprecatedConfigFile();
|
$updater->updateMethodMergeDeprecatedConfigFile();
|
||||||
|
|
||||||
$this->assertEquals('root', $this->conf->get('credentials.login'));
|
$this->assertEquals('root', $this->conf->get('credentials.login'));
|
||||||
|
@ -225,14 +224,14 @@ public function testMergeDeprecatedConfigNoFile()
|
||||||
*/
|
*/
|
||||||
public function testRenameDashTags()
|
public function testRenameDashTags()
|
||||||
{
|
{
|
||||||
$refDB = new \ReferenceLinkDB(true);
|
$refDB = new ReferenceLinkDB(true);
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
|
||||||
$this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
|
$this->assertEmpty($linkDB->filterSearch(['searchtags' => 'exclude']));
|
||||||
$updater = new LegacyUpdater(array(), $linkDB, $this->conf, true);
|
$updater = new LegacyUpdater([], $linkDB, $this->conf, true);
|
||||||
$updater->updateMethodRenameDashTags();
|
$updater->updateMethodRenameDashTags();
|
||||||
$this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
|
$this->assertNotEmpty($linkDB->filterSearch(['searchtags' => 'exclude']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -247,7 +246,7 @@ public function testConfigToJson()
|
||||||
// The ConfigIO is initialized with ConfigPhp.
|
// The ConfigIO is initialized with ConfigPhp.
|
||||||
$this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp);
|
$this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp);
|
||||||
|
|
||||||
$updater = new LegacyUpdater(array(), array(), $this->conf, false);
|
$updater = new LegacyUpdater([], [], $this->conf, false);
|
||||||
$done = $updater->updateMethodConfigToJson();
|
$done = $updater->updateMethodConfigToJson();
|
||||||
$this->assertTrue($done);
|
$this->assertTrue($done);
|
||||||
|
|
||||||
|
@ -272,7 +271,7 @@ public function testConfigToJson()
|
||||||
public function testConfigToJsonNothingToDo()
|
public function testConfigToJsonNothingToDo()
|
||||||
{
|
{
|
||||||
$filetime = filemtime($this->conf->getConfigFileExt());
|
$filetime = filemtime($this->conf->getConfigFileExt());
|
||||||
$updater = new LegacyUpdater(array(), array(), $this->conf, false);
|
$updater = new LegacyUpdater([], [], $this->conf, false);
|
||||||
$done = $updater->updateMethodConfigToJson();
|
$done = $updater->updateMethodConfigToJson();
|
||||||
$this->assertTrue($done);
|
$this->assertTrue($done);
|
||||||
$expected = filemtime($this->conf->getConfigFileExt());
|
$expected = filemtime($this->conf->getConfigFileExt());
|
||||||
|
@ -291,7 +290,7 @@ public function testEscapeConfig()
|
||||||
$headerLink = '<script>alert("header_link");</script>';
|
$headerLink = '<script>alert("header_link");</script>';
|
||||||
$this->conf->set('general.title', $title);
|
$this->conf->set('general.title', $title);
|
||||||
$this->conf->set('general.header_link', $headerLink);
|
$this->conf->set('general.header_link', $headerLink);
|
||||||
$updater = new LegacyUpdater(array(), array(), $this->conf, true);
|
$updater = new LegacyUpdater([], [], $this->conf, true);
|
||||||
$done = $updater->updateMethodEscapeUnescapedConfig();
|
$done = $updater->updateMethodEscapeUnescapedConfig();
|
||||||
$this->assertTrue($done);
|
$this->assertTrue($done);
|
||||||
$this->conf->reload();
|
$this->conf->reload();
|
||||||
|
@ -308,7 +307,7 @@ public function testUpdateApiSettings()
|
||||||
$confFile = 'sandbox/config';
|
$confFile = 'sandbox/config';
|
||||||
copy(self::$configFile . '.json.php', $confFile . '.json.php');
|
copy(self::$configFile . '.json.php', $confFile . '.json.php');
|
||||||
$conf = new ConfigManager($confFile);
|
$conf = new ConfigManager($confFile);
|
||||||
$updater = new LegacyUpdater(array(), array(), $conf, true);
|
$updater = new LegacyUpdater([], [], $conf, true);
|
||||||
|
|
||||||
$this->assertFalse($conf->exists('api.enabled'));
|
$this->assertFalse($conf->exists('api.enabled'));
|
||||||
$this->assertFalse($conf->exists('api.secret'));
|
$this->assertFalse($conf->exists('api.secret'));
|
||||||
|
@ -329,7 +328,7 @@ public function testUpdateApiSettingsNothingToDo()
|
||||||
$conf = new ConfigManager($confFile);
|
$conf = new ConfigManager($confFile);
|
||||||
$conf->set('api.enabled', false);
|
$conf->set('api.enabled', false);
|
||||||
$conf->set('api.secret', '');
|
$conf->set('api.secret', '');
|
||||||
$updater = new LegacyUpdater(array(), array(), $conf, true);
|
$updater = new LegacyUpdater([], [], $conf, true);
|
||||||
$updater->updateMethodApiSettings();
|
$updater->updateMethodApiSettings();
|
||||||
$this->assertFalse($conf->get('api.enabled'));
|
$this->assertFalse($conf->get('api.enabled'));
|
||||||
$this->assertEmpty($conf->get('api.secret'));
|
$this->assertEmpty($conf->get('api.secret'));
|
||||||
|
@ -341,8 +340,8 @@ public function testUpdateApiSettingsNothingToDo()
|
||||||
*/
|
*/
|
||||||
public function testDatastoreIds()
|
public function testDatastoreIds()
|
||||||
{
|
{
|
||||||
$links = array(
|
$links = [
|
||||||
'20121206_182539' => array(
|
'20121206_182539' => [
|
||||||
'linkdate' => '20121206_182539',
|
'linkdate' => '20121206_182539',
|
||||||
'title' => 'Geek and Poke',
|
'title' => 'Geek and Poke',
|
||||||
'url' => 'http://geek-and-poke.com/',
|
'url' => 'http://geek-and-poke.com/',
|
||||||
|
@ -350,25 +349,25 @@ public function testDatastoreIds()
|
||||||
'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
|
'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
|
||||||
'updated' => '20121206_190301',
|
'updated' => '20121206_190301',
|
||||||
'private' => false,
|
'private' => false,
|
||||||
),
|
],
|
||||||
'20121206_172539' => array(
|
'20121206_172539' => [
|
||||||
'linkdate' => '20121206_172539',
|
'linkdate' => '20121206_172539',
|
||||||
'title' => 'UserFriendly - Samba',
|
'title' => 'UserFriendly - Samba',
|
||||||
'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
|
'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'tags' => 'samba cartoon web',
|
'tags' => 'samba cartoon web',
|
||||||
'private' => false,
|
'private' => false,
|
||||||
),
|
],
|
||||||
'20121206_142300' => array(
|
'20121206_142300' => [
|
||||||
'linkdate' => '20121206_142300',
|
'linkdate' => '20121206_142300',
|
||||||
'title' => 'UserFriendly - Web Designer',
|
'title' => 'UserFriendly - Web Designer',
|
||||||
'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
|
'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
|
||||||
'description' => 'Naming conventions... #private',
|
'description' => 'Naming conventions... #private',
|
||||||
'tags' => 'samba cartoon web',
|
'tags' => 'samba cartoon web',
|
||||||
'private' => true,
|
'private' => true,
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
$refDB = new \ReferenceLinkDB(true);
|
$refDB = new ReferenceLinkDB(true);
|
||||||
$refDB->setLinks($links);
|
$refDB->setLinks($links);
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
@ -378,7 +377,7 @@ public function testDatastoreIds()
|
||||||
$this->conf->set('resource.data_dir', 'sandbox');
|
$this->conf->set('resource.data_dir', 'sandbox');
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
|
|
||||||
$updater = new LegacyUpdater(array(), $linkDB, $this->conf, true);
|
$updater = new LegacyUpdater([], $linkDB, $this->conf, true);
|
||||||
$this->assertTrue($updater->updateMethodDatastoreIds());
|
$this->assertTrue($updater->updateMethodDatastoreIds());
|
||||||
|
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
@ -437,7 +436,7 @@ public function testDatastoreIds()
|
||||||
*/
|
*/
|
||||||
public function testDatastoreIdsNothingToDo()
|
public function testDatastoreIdsNothingToDo()
|
||||||
{
|
{
|
||||||
$refDB = new \ReferenceLinkDB(true);
|
$refDB = new ReferenceLinkDB(true);
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
|
||||||
|
@ -445,7 +444,7 @@ public function testDatastoreIdsNothingToDo()
|
||||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||||
|
|
||||||
$checksum = hash_file('sha1', self::$testDatastore);
|
$checksum = hash_file('sha1', self::$testDatastore);
|
||||||
$updater = new LegacyUpdater(array(), $linkDB, $this->conf, true);
|
$updater = new LegacyUpdater([], $linkDB, $this->conf, true);
|
||||||
$this->assertTrue($updater->updateMethodDatastoreIds());
|
$this->assertTrue($updater->updateMethodDatastoreIds());
|
||||||
$this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
|
$this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
|
||||||
}
|
}
|
||||||
|
@ -781,12 +780,12 @@ public function testUpdateStickyValid()
|
||||||
1 => ['id' => 1] + $blank,
|
1 => ['id' => 1] + $blank,
|
||||||
2 => ['id' => 2] + $blank,
|
2 => ['id' => 2] + $blank,
|
||||||
];
|
];
|
||||||
$refDB = new \ReferenceLinkDB(true);
|
$refDB = new ReferenceLinkDB(true);
|
||||||
$refDB->setLinks($links);
|
$refDB->setLinks($links);
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
|
||||||
$updater = new LegacyUpdater(array(), $linkDB, $this->conf, true);
|
$updater = new LegacyUpdater([], $linkDB, $this->conf, true);
|
||||||
$this->assertTrue($updater->updateMethodSetSticky());
|
$this->assertTrue($updater->updateMethodSetSticky());
|
||||||
|
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
@ -812,12 +811,12 @@ public function testUpdateStickyNothingToDo()
|
||||||
1 => ['id' => 1, 'sticky' => true] + $blank,
|
1 => ['id' => 1, 'sticky' => true] + $blank,
|
||||||
2 => ['id' => 2] + $blank,
|
2 => ['id' => 2] + $blank,
|
||||||
];
|
];
|
||||||
$refDB = new \ReferenceLinkDB(true);
|
$refDB = new ReferenceLinkDB(true);
|
||||||
$refDB->setLinks($links);
|
$refDB->setLinks($links);
|
||||||
$refDB->write(self::$testDatastore);
|
$refDB->write(self::$testDatastore);
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
|
||||||
$updater = new LegacyUpdater(array(), $linkDB, $this->conf, true);
|
$updater = new LegacyUpdater([], $linkDB, $this->conf, true);
|
||||||
$this->assertTrue($updater->updateMethodSetSticky());
|
$this->assertTrue($updater->updateMethodSetSticky());
|
||||||
|
|
||||||
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
$linkDB = new LegacyLinkDB(self::$testDatastore, true, false);
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
require_once 'tests/utils/ReferenceLinkDB.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Netscape bookmark export
|
* Netscape bookmark export
|
||||||
|
@ -29,7 +28,7 @@ class BookmarkExportTest extends TestCase
|
||||||
protected static $conf;
|
protected static $conf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \ReferenceLinkDB instance.
|
* @var ReferenceLinkDB instance.
|
||||||
*/
|
*/
|
||||||
protected static $refDb = null;
|
protected static $refDb = null;
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ public static function setUpBeforeClass(): void
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
static::$conf = new ConfigManager('tests/utils/config/configJson');
|
static::$conf = new ConfigManager('tests/utils/config/configJson');
|
||||||
static::$conf->set('resource.datastore', static::$testDatastore);
|
static::$conf->set('resource.datastore', static::$testDatastore);
|
||||||
static::$refDb = new \ReferenceLinkDB();
|
static::$refDb = new ReferenceLinkDB();
|
||||||
static::$refDb->write(static::$testDatastore);
|
static::$refDb->write(static::$testDatastore);
|
||||||
static::$history = new History('sandbox/history.php');
|
static::$history = new History('sandbox/history.php');
|
||||||
static::$pluginManager = new PluginManager(static::$conf);
|
static::$pluginManager = new PluginManager(static::$conf);
|
||||||
|
|
|
@ -365,7 +365,7 @@ public function testImportDefaultPrivacyNoPost()
|
||||||
*/
|
*/
|
||||||
public function testImportKeepPrivacy()
|
public function testImportKeepPrivacy()
|
||||||
{
|
{
|
||||||
$post = array('privacy' => 'default');
|
$post = ['privacy' => 'default'];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -408,7 +408,7 @@ public function testImportKeepPrivacy()
|
||||||
*/
|
*/
|
||||||
public function testImportAsPublic()
|
public function testImportAsPublic()
|
||||||
{
|
{
|
||||||
$post = array('privacy' => 'public');
|
$post = ['privacy' => 'public'];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -426,7 +426,7 @@ public function testImportAsPublic()
|
||||||
*/
|
*/
|
||||||
public function testImportAsPrivate()
|
public function testImportAsPrivate()
|
||||||
{
|
{
|
||||||
$post = array('privacy' => 'private');
|
$post = ['privacy' => 'private'];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -447,7 +447,7 @@ public function testOverwriteAsPublic()
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
|
|
||||||
// import bookmarks as private
|
// import bookmarks as private
|
||||||
$post = array('privacy' => 'private');
|
$post = ['privacy' => 'private'];
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
. ' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
||||||
|
@ -459,10 +459,10 @@ public function testOverwriteAsPublic()
|
||||||
$this->assertTrue($this->bookmarkService->get(1)->isPrivate());
|
$this->assertTrue($this->bookmarkService->get(1)->isPrivate());
|
||||||
|
|
||||||
// re-import as public, enable overwriting
|
// re-import as public, enable overwriting
|
||||||
$post = array(
|
$post = [
|
||||||
'privacy' => 'public',
|
'privacy' => 'public',
|
||||||
'overwrite' => 'true'
|
'overwrite' => 'true'
|
||||||
);
|
];
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
|
. ' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
|
||||||
|
@ -482,7 +482,7 @@ public function testOverwriteAsPrivate()
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
|
|
||||||
// import bookmarks as public
|
// import bookmarks as public
|
||||||
$post = array('privacy' => 'public');
|
$post = ['privacy' => 'public'];
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
. ' 2 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
||||||
|
@ -494,10 +494,10 @@ public function testOverwriteAsPrivate()
|
||||||
$this->assertFalse($this->bookmarkService->get(1)->isPrivate());
|
$this->assertFalse($this->bookmarkService->get(1)->isPrivate());
|
||||||
|
|
||||||
// re-import as private, enable overwriting
|
// re-import as private, enable overwriting
|
||||||
$post = array(
|
$post = [
|
||||||
'privacy' => 'private',
|
'privacy' => 'private',
|
||||||
'overwrite' => 'true'
|
'overwrite' => 'true'
|
||||||
);
|
];
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
|
. ' 2 bookmarks imported, 2 bookmarks overwritten, 0 bookmarks skipped.',
|
||||||
|
@ -514,7 +514,7 @@ public function testOverwriteAsPrivate()
|
||||||
*/
|
*/
|
||||||
public function testSkipOverwrite()
|
public function testSkipOverwrite()
|
||||||
{
|
{
|
||||||
$post = array('privacy' => 'public');
|
$post = ['privacy' => 'public'];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -525,7 +525,7 @@ public function testSkipOverwrite()
|
||||||
$this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE));
|
$this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE));
|
||||||
|
|
||||||
// re-import as private, DO NOT enable overwriting
|
// re-import as private, DO NOT enable overwriting
|
||||||
$post = array('privacy' => 'private');
|
$post = ['privacy' => 'private'];
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.',
|
. ' 0 bookmarks imported, 0 bookmarks overwritten, 2 bookmarks skipped.',
|
||||||
|
@ -540,10 +540,10 @@ public function testSkipOverwrite()
|
||||||
*/
|
*/
|
||||||
public function testSetDefaultTags()
|
public function testSetDefaultTags()
|
||||||
{
|
{
|
||||||
$post = array(
|
$post = [
|
||||||
'privacy' => 'public',
|
'privacy' => 'public',
|
||||||
'default_tags' => 'tag1 tag2 tag3'
|
'default_tags' => 'tag1 tag2 tag3'
|
||||||
);
|
];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -561,10 +561,10 @@ public function testSetDefaultTags()
|
||||||
*/
|
*/
|
||||||
public function testSanitizeDefaultTags()
|
public function testSanitizeDefaultTags()
|
||||||
{
|
{
|
||||||
$post = array(
|
$post = [
|
||||||
'privacy' => 'public',
|
'privacy' => 'public',
|
||||||
'default_tags' => 'tag1& tag2 "tag3"'
|
'default_tags' => 'tag1& tag2 "tag3"'
|
||||||
);
|
];
|
||||||
$files = file2array('netscape_basic.htm');
|
$files = file2array('netscape_basic.htm');
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
'File netscape_basic.htm (482 bytes) was successfully processed in %d seconds:'
|
||||||
|
@ -631,7 +631,7 @@ public function testImportSameDate()
|
||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
|
'File same_date.htm (453 bytes) was successfully processed in %d seconds:'
|
||||||
. ' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
. ' 3 bookmarks imported, 0 bookmarks overwritten, 0 bookmarks skipped.',
|
||||||
$this->netscapeBookmarkUtils->import(array(), $files)
|
$this->netscapeBookmarkUtils->import([], $files)
|
||||||
);
|
);
|
||||||
$this->assertEquals(3, $this->bookmarkService->count());
|
$this->assertEquals(3, $this->bookmarkService->count());
|
||||||
$this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE));
|
$this->assertEquals(0, $this->bookmarkService->count(BookmarkFilter::$PRIVATE));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Addlink;
|
namespace Shaarli\Plugin\Addlink;
|
||||||
|
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
|
@ -25,7 +26,7 @@ protected function setUp(): void
|
||||||
public function testAddlinkHeaderLoggedIn()
|
public function testAddlinkHeaderLoggedIn()
|
||||||
{
|
{
|
||||||
$str = 'stuff';
|
$str = 'stuff';
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
||||||
$data['_LOGGEDIN_'] = true;
|
$data['_LOGGEDIN_'] = true;
|
||||||
$data['_BASE_PATH_'] = '/subfolder';
|
$data['_BASE_PATH_'] = '/subfolder';
|
||||||
|
@ -34,7 +35,7 @@ public function testAddlinkHeaderLoggedIn()
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertEquals(1, count($data['fields_toolbar']));
|
$this->assertEquals(1, count($data['fields_toolbar']));
|
||||||
|
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = $str;
|
$data['_PAGE_'] = $str;
|
||||||
$data['_LOGGEDIN_'] = true;
|
$data['_LOGGEDIN_'] = true;
|
||||||
$data['_BASE_PATH_'] = '/subfolder';
|
$data['_BASE_PATH_'] = '/subfolder';
|
||||||
|
@ -50,7 +51,7 @@ public function testAddlinkHeaderLoggedIn()
|
||||||
public function testAddlinkHeaderLoggedOut()
|
public function testAddlinkHeaderLoggedOut()
|
||||||
{
|
{
|
||||||
$str = 'stuff';
|
$str = 'stuff';
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
||||||
$data['_LOGGEDIN_'] = false;
|
$data['_LOGGEDIN_'] = false;
|
||||||
$data['_BASE_PATH_'] = '/subfolder';
|
$data['_BASE_PATH_'] = '/subfolder';
|
||||||
|
|
|
@ -2,10 +2,6 @@
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Archiveorg;
|
namespace Shaarli\Plugin\Archiveorg;
|
||||||
|
|
||||||
/**
|
|
||||||
* PluginArchiveorgTest.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
|
||||||
|
@ -47,16 +43,16 @@ public function testArchiveorgLinklistOnExternalLinks(): void
|
||||||
{
|
{
|
||||||
$str = 'http://randomstr.com/test';
|
$str = 'http://randomstr.com/test';
|
||||||
|
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $str,
|
'title' => $str,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'url' => $str,
|
'url' => $str,
|
||||||
'private' => 0,
|
'private' => 0,
|
||||||
'real_url' => $str
|
'real_url' => $str
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$data = hook_archiveorg_render_linklist($data);
|
$data = hook_archiveorg_render_linklist($data);
|
||||||
|
|
||||||
|
@ -84,41 +80,41 @@ public function testArchiveorgLinklistOnInternalLinks(): void
|
||||||
$internalLink3 = 'http://shaarli.shaarli/shaare/z7u-_Q';
|
$internalLink3 = 'http://shaarli.shaarli/shaare/z7u-_Q';
|
||||||
$internalLinkRealURL3 = '/shaare/z7u-_Q';
|
$internalLinkRealURL3 = '/shaare/z7u-_Q';
|
||||||
|
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $internalLink1,
|
'title' => $internalLink1,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'url' => $internalLink1,
|
'url' => $internalLink1,
|
||||||
'private' => 0,
|
'private' => 0,
|
||||||
'real_url' => $internalLinkRealURL1
|
'real_url' => $internalLinkRealURL1
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'url' => $internalLink1,
|
'url' => $internalLink1,
|
||||||
'private' => 1,
|
'private' => 1,
|
||||||
'real_url' => $internalLinkRealURL1
|
'real_url' => $internalLinkRealURL1
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'url' => $internalLink2,
|
'url' => $internalLink2,
|
||||||
'private' => 0,
|
'private' => 0,
|
||||||
'real_url' => $internalLinkRealURL2
|
'real_url' => $internalLinkRealURL2
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'url' => $internalLink2,
|
'url' => $internalLink2,
|
||||||
'private' => 1,
|
'private' => 1,
|
||||||
'real_url' => $internalLinkRealURL2
|
'real_url' => $internalLinkRealURL2
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'url' => $internalLink3,
|
'url' => $internalLink3,
|
||||||
'private' => 0,
|
'private' => 0,
|
||||||
'real_url' => $internalLinkRealURL3
|
'real_url' => $internalLinkRealURL3
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'url' => $internalLink3,
|
'url' => $internalLink3,
|
||||||
'private' => 1,
|
'private' => 1,
|
||||||
'real_url' => $internalLinkRealURL3
|
'real_url' => $internalLinkRealURL3
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$data = hook_archiveorg_render_linklist($data);
|
$data = hook_archiveorg_render_linklist($data);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Isso;
|
namespace Shaarli\Plugin\Isso;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
@ -55,16 +56,16 @@ public function testIssoDisplayed(): void
|
||||||
|
|
||||||
$str = 'http://randomstr.com/test';
|
$str = 'http://randomstr.com/test';
|
||||||
$date = '20161118_100001';
|
$date = '20161118_100001';
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $str,
|
'title' => $str,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'id' => 12,
|
'id' => 12,
|
||||||
'url' => $str,
|
'url' => $str,
|
||||||
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$data = hook_isso_render_linklist($data, $conf);
|
$data = hook_isso_render_linklist($data, $conf);
|
||||||
|
|
||||||
|
@ -96,28 +97,34 @@ public function testIssoMultipleLinks(): void
|
||||||
$str = 'http://randomstr.com/test';
|
$str = 'http://randomstr.com/test';
|
||||||
$date1 = '20161118_100001';
|
$date1 = '20161118_100001';
|
||||||
$date2 = '20161118_100002';
|
$date2 = '20161118_100002';
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $str,
|
'title' => $str,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'id' => 12,
|
'id' => 12,
|
||||||
'url' => $str,
|
'url' => $str,
|
||||||
'shorturl' => $short1 = 'abcd',
|
'shorturl' => $short1 = 'abcd',
|
||||||
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date1),
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date1),
|
||||||
),
|
],
|
||||||
array(
|
[
|
||||||
'id' => 13,
|
'id' => 13,
|
||||||
'url' => $str . '2',
|
'url' => $str . '2',
|
||||||
'shorturl' => $short2 = 'efgh',
|
'shorturl' => $short2 = 'efgh',
|
||||||
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date2),
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date2),
|
||||||
),
|
],
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$processed = hook_isso_render_linklist($data, $conf);
|
$processed = hook_isso_render_linklist($data, $conf);
|
||||||
// link_plugin should be added for the icon
|
// link_plugin should be added for the icon
|
||||||
$this->assertContainsPolyfill('<a href="/shaare/'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
|
$this->assertContainsPolyfill(
|
||||||
$this->assertContainsPolyfill('<a href="/shaare/'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
|
'<a href="/shaare/' . $short1 . '#isso-thread">',
|
||||||
|
$processed['links'][0]['link_plugin'][0]
|
||||||
|
);
|
||||||
|
$this->assertContainsPolyfill(
|
||||||
|
'<a href="/shaare/' . $short2 . '#isso-thread">',
|
||||||
|
$processed['links'][1]['link_plugin'][0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,23 +137,26 @@ public function testIssoNotDisplayedWhenSearch(): void
|
||||||
|
|
||||||
$str = 'http://randomstr.com/test';
|
$str = 'http://randomstr.com/test';
|
||||||
$date = '20161118_100001';
|
$date = '20161118_100001';
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $str,
|
'title' => $str,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'id' => 12,
|
'id' => 12,
|
||||||
'url' => $str,
|
'url' => $str,
|
||||||
'shorturl' => $short1 = 'abcd',
|
'shorturl' => $short1 = 'abcd',
|
||||||
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
'created' => DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $date),
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
'search_term' => $str
|
'search_term' => $str
|
||||||
);
|
];
|
||||||
|
|
||||||
$processed = hook_isso_render_linklist($data, $conf);
|
$processed = hook_isso_render_linklist($data, $conf);
|
||||||
|
|
||||||
// link_plugin should be added for the icon
|
// link_plugin should be added for the icon
|
||||||
$this->assertContainsPolyfill('<a href="/shaare/'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
|
$this->assertContainsPolyfill(
|
||||||
|
'<a href="/shaare/' . $short1 . '#isso-thread">',
|
||||||
|
$processed['links'][0]['link_plugin'][0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Shaarli\Plugin\Playvideos;
|
|
||||||
|
|
||||||
/**
|
namespace Shaarli\Plugin\Playvideos;
|
||||||
* PluginPlayvideosTest.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\Render\TemplatePage;
|
use Shaarli\Render\TemplatePage;
|
||||||
|
@ -30,14 +27,14 @@ protected function setUp(): void
|
||||||
public function testPlayvideosHeader()
|
public function testPlayvideosHeader()
|
||||||
{
|
{
|
||||||
$str = 'stuff';
|
$str = 'stuff';
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
||||||
|
|
||||||
$data = hook_playvideos_render_header($data);
|
$data = hook_playvideos_render_header($data);
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertEquals(1, count($data['buttons_toolbar']));
|
$this->assertEquals(1, count($data['buttons_toolbar']));
|
||||||
|
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = $str;
|
$data['_PAGE_'] = $str;
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertArrayNotHasKey('buttons_toolbar', $data);
|
$this->assertArrayNotHasKey('buttons_toolbar', $data);
|
||||||
|
@ -49,14 +46,14 @@ public function testPlayvideosHeader()
|
||||||
public function testPlayvideosFooter()
|
public function testPlayvideosFooter()
|
||||||
{
|
{
|
||||||
$str = 'stuff';
|
$str = 'stuff';
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
||||||
|
|
||||||
$data = hook_playvideos_render_footer($data);
|
$data = hook_playvideos_render_footer($data);
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertEquals(2, count($data['js_files']));
|
$this->assertEquals(2, count($data['js_files']));
|
||||||
|
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = $str;
|
$data['_PAGE_'] = $str;
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertArrayNotHasKey('js_files', $data);
|
$this->assertArrayNotHasKey('js_files', $data);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Pubsubhubbub;
|
namespace Shaarli\Plugin\Pubsubhubbub;
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Shaarli\Plugin\Qrcode;
|
|
||||||
|
|
||||||
/**
|
namespace Shaarli\Plugin\Qrcode;
|
||||||
* PluginQrcodeTest.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\Render\TemplatePage;
|
use Shaarli\Render\TemplatePage;
|
||||||
|
@ -30,14 +27,14 @@ protected function setUp(): void
|
||||||
public function testQrcodeLinklist()
|
public function testQrcodeLinklist()
|
||||||
{
|
{
|
||||||
$str = 'http://randomstr.com/test';
|
$str = 'http://randomstr.com/test';
|
||||||
$data = array(
|
$data = [
|
||||||
'title' => $str,
|
'title' => $str,
|
||||||
'links' => array(
|
'links' => [
|
||||||
array(
|
[
|
||||||
'url' => $str,
|
'url' => $str,
|
||||||
)
|
]
|
||||||
)
|
]
|
||||||
);
|
];
|
||||||
|
|
||||||
$data = hook_qrcode_render_linklist($data);
|
$data = hook_qrcode_render_linklist($data);
|
||||||
$link = $data['links'][0];
|
$link = $data['links'][0];
|
||||||
|
@ -56,14 +53,14 @@ public function testQrcodeLinklist()
|
||||||
public function testQrcodeFooter()
|
public function testQrcodeFooter()
|
||||||
{
|
{
|
||||||
$str = 'stuff';
|
$str = 'stuff';
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
$data['_PAGE_'] = TemplatePage::LINKLIST;
|
||||||
|
|
||||||
$data = hook_qrcode_render_footer($data);
|
$data = hook_qrcode_render_footer($data);
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertEquals(1, count($data['js_files']));
|
$this->assertEquals(1, count($data['js_files']));
|
||||||
|
|
||||||
$data = array($str => $str);
|
$data = [$str => $str];
|
||||||
$data['_PAGE_'] = $str;
|
$data['_PAGE_'] = $str;
|
||||||
$this->assertEquals($str, $data[$str]);
|
$this->assertEquals($str, $data[$str]);
|
||||||
$this->assertArrayNotHasKey('js_files', $data);
|
$this->assertArrayNotHasKey('js_files', $data);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Wallabag;
|
namespace Shaarli\Plugin\Wallabag;
|
||||||
|
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Plugin\Wallabag;
|
namespace Shaarli\Plugin\Wallabag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ class PageCacheManagerTest extends TestCase
|
||||||
protected static $testCacheDir = 'sandbox/dummycache';
|
protected static $testCacheDir = 'sandbox/dummycache';
|
||||||
|
|
||||||
// dummy cached file names / content
|
// dummy cached file names / content
|
||||||
protected static $pages = array('a', 'toto', 'd7b59c');
|
protected static $pages = ['a', 'toto', 'd7b59c'];
|
||||||
|
|
||||||
/** @var PageCacheManager */
|
/** @var PageCacheManager */
|
||||||
protected $cacheManager;
|
protected $cacheManager;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Shaarli\Security;
|
namespace Shaarli\Security;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
|
@ -349,7 +349,11 @@ public function testCheckCredentialsFromLdapWrongLoginAndPassword()
|
||||||
{
|
{
|
||||||
$this->configManager->set('ldap.host', 'dummy');
|
$this->configManager->set('ldap.host', 'dummy');
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
$this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function() { return null; }, function() { return false; })
|
$this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function () {
|
||||||
|
return null;
|
||||||
|
}, function () {
|
||||||
|
return false;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +364,11 @@ public function testCheckCredentialsFromLdapGoodLoginAndPassword()
|
||||||
{
|
{
|
||||||
$this->configManager->set('ldap.host', 'dummy');
|
$this->configManager->set('ldap.host', 'dummy');
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function() { return null; }, function() { return true; })
|
$this->loginManager->checkCredentialsFromLdap($this->login, $this->password, function () {
|
||||||
|
return null;
|
||||||
|
}, function () {
|
||||||
|
return true;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use Shaarli\FakeConfigManager;
|
use Shaarli\FakeConfigManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceSessionIdHashes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test coverage for SessionManager
|
* Test coverage for SessionManager
|
||||||
|
@ -27,7 +28,7 @@ class SessionManagerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
self::$sidHashes = \ReferenceSessionIdHashes::getHashes();
|
self::$sidHashes = ReferenceSessionIdHashes::getHashes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Shaarli\Updater;
|
|
||||||
|
namespace Shaarli\Tests\updater;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
use Shaarli\Bookmark\BookmarkFileService;
|
use Shaarli\Bookmark\BookmarkFileService;
|
||||||
use Shaarli\Bookmark\LinkDB;
|
use Shaarli\Bookmark\LinkDB;
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
|
use Shaarli\Updater\Updater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DummyUpdater.
|
* Class DummyUpdater.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli\Updater;
|
namespace Shaarli\Updater;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
@ -9,7 +10,8 @@
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
use Shaarli\Plugin\PluginManager;
|
use Shaarli\Plugin\PluginManager;
|
||||||
use Shaarli\TestCase;
|
use Shaarli\TestCase;
|
||||||
|
use Shaarli\Tests\updater\DummyUpdater;
|
||||||
|
use Shaarli\Tests\Utils\ReferenceLinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UpdaterTest.
|
* Class UpdaterTest.
|
||||||
|
@ -35,7 +37,7 @@ class UpdaterTest extends TestCase
|
||||||
/** @var BookmarkServiceInterface */
|
/** @var BookmarkServiceInterface */
|
||||||
protected $bookmarkService;
|
protected $bookmarkService;
|
||||||
|
|
||||||
/** @var \ReferenceLinkDB */
|
/** @var ReferenceLinkDB */
|
||||||
protected $refDB;
|
protected $refDB;
|
||||||
|
|
||||||
/** @var Updater */
|
/** @var Updater */
|
||||||
|
@ -47,7 +49,7 @@ class UpdaterTest extends TestCase
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$mutex = new NoMutex();
|
$mutex = new NoMutex();
|
||||||
$this->refDB = new \ReferenceLinkDB();
|
$this->refDB = new ReferenceLinkDB();
|
||||||
$this->refDB->write(self::$testDatastore);
|
$this->refDB->write(self::$testDatastore);
|
||||||
|
|
||||||
copy('tests/utils/config/configJson.json.php', self::$configFile . '.json.php');
|
copy('tests/utils/config/configJson.json.php', self::$configFile . '.json.php');
|
||||||
|
@ -67,10 +69,10 @@ protected function setUp(): void
|
||||||
*/
|
*/
|
||||||
public function testReadEmptyUpdatesFile()
|
public function testReadEmptyUpdatesFile()
|
||||||
{
|
{
|
||||||
$this->assertEquals(array(), UpdaterUtils::readUpdatesFile(''));
|
$this->assertEquals([], UpdaterUtils::readUpdatesFile(''));
|
||||||
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
||||||
touch($updatesFile);
|
touch($updatesFile);
|
||||||
$this->assertEquals(array(), UpdaterUtils::readUpdatesFile($updatesFile));
|
$this->assertEquals([], UpdaterUtils::readUpdatesFile($updatesFile));
|
||||||
unlink($updatesFile);
|
unlink($updatesFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ public function testReadEmptyUpdatesFile()
|
||||||
public function testReadWriteUpdatesFile()
|
public function testReadWriteUpdatesFile()
|
||||||
{
|
{
|
||||||
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
$updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
|
||||||
$updatesMethods = array('m1', 'm2', 'm3');
|
$updatesMethods = ['m1', 'm2', 'm3'];
|
||||||
|
|
||||||
UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
|
UpdaterUtils::writeUpdatesFile($updatesFile, $updatesMethods);
|
||||||
$readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
|
$readMethods = UpdaterUtils::readUpdatesFile($updatesFile);
|
||||||
|
@ -102,7 +104,7 @@ public function testWriteEmptyUpdatesFile()
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
$this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
|
$this->expectExceptionMessageRegExp('/Updates file path is not set(.*)/');
|
||||||
|
|
||||||
UpdaterUtils::writeUpdatesFile('', array('test'));
|
UpdaterUtils::writeUpdatesFile('', ['test']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +119,7 @@ public function testWriteUpdatesFileNotWritable()
|
||||||
touch($updatesFile);
|
touch($updatesFile);
|
||||||
chmod($updatesFile, 0444);
|
chmod($updatesFile, 0444);
|
||||||
try {
|
try {
|
||||||
@UpdaterUtils::writeUpdatesFile($updatesFile, array('test'));
|
@UpdaterUtils::writeUpdatesFile($updatesFile, ['test']);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
unlink($updatesFile);
|
unlink($updatesFile);
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -131,17 +133,17 @@ public function testWriteUpdatesFileNotWritable()
|
||||||
*/
|
*/
|
||||||
public function testNoUpdates()
|
public function testNoUpdates()
|
||||||
{
|
{
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
'updateMethodException',
|
'updateMethodException',
|
||||||
);
|
];
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals(array(), $updater->update());
|
$this->assertEquals([], $updater->update());
|
||||||
|
|
||||||
$updater = new DummyUpdater(array(), array(), $this->conf, false);
|
$updater = new DummyUpdater([], [], $this->conf, false);
|
||||||
$this->assertEquals(array(), $updater->update());
|
$this->assertEquals([], $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,13 +151,13 @@ public function testNoUpdates()
|
||||||
*/
|
*/
|
||||||
public function testUpdatesFirstTime()
|
public function testUpdatesFirstTime()
|
||||||
{
|
{
|
||||||
$updates = array('updateMethodException',);
|
$updates = ['updateMethodException',];
|
||||||
$expectedUpdates = array(
|
$expectedUpdates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
);
|
];
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals($expectedUpdates, $updater->update());
|
$this->assertEquals($expectedUpdates, $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,14 +166,14 @@ public function testUpdatesFirstTime()
|
||||||
*/
|
*/
|
||||||
public function testOneUpdate()
|
public function testOneUpdate()
|
||||||
{
|
{
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
'updateMethodException',
|
'updateMethodException',
|
||||||
);
|
];
|
||||||
$expectedUpdate = array('updateMethodDummy2');
|
$expectedUpdate = ['updateMethodDummy2'];
|
||||||
|
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$this->assertEquals($expectedUpdate, $updater->update());
|
$this->assertEquals($expectedUpdate, $updater->update());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,13 +184,13 @@ public function testUpdateFailed()
|
||||||
{
|
{
|
||||||
$this->expectException(\Exception::class);
|
$this->expectException(\Exception::class);
|
||||||
|
|
||||||
$updates = array(
|
$updates = [
|
||||||
'updateMethodDummy1',
|
'updateMethodDummy1',
|
||||||
'updateMethodDummy2',
|
'updateMethodDummy2',
|
||||||
'updateMethodDummy3',
|
'updateMethodDummy3',
|
||||||
);
|
];
|
||||||
|
|
||||||
$updater = new DummyUpdater($updates, array(), $this->conf, true);
|
$updater = new DummyUpdater($updates, [], $this->conf, true);
|
||||||
$updater->update();
|
$updater->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions
|
* Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Shaarli;
|
namespace Shaarli\Tests\Utils;
|
||||||
|
|
||||||
use Shaarli\Helper\ApplicationUtils;
|
use Shaarli\Helper\ApplicationUtils;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Tests\Utils;
|
||||||
|
|
||||||
use Shaarli\Bookmark\BookmarkArray;
|
|
||||||
use Shaarli\Bookmark\BookmarkFilter;
|
|
||||||
use Shaarli\Bookmark\BookmarkIO;
|
|
||||||
use Shaarli\Bookmark\BookmarkFileService;
|
use Shaarli\Bookmark\BookmarkFileService;
|
||||||
use Shaarli\Bookmark\Exception\EmptyDataStoreException;
|
|
||||||
use Shaarli\Config\ConfigManager;
|
|
||||||
use Shaarli\History;
|
|
||||||
|
|
||||||
class FakeBookmarkService extends BookmarkFileService
|
class FakeBookmarkService extends BookmarkFileService
|
||||||
{
|
{
|
||||||
|
|
6
tests/utils/RainTPL.php
Normal file
6
tests/utils/RainTPL.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class RainTPL
|
||||||
|
{
|
||||||
|
public static $tpl_dir = '';
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Tests\Utils;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use Shaarli\Helper\FileUtils;
|
use Shaarli\Helper\FileUtils;
|
||||||
use Shaarli\History;
|
use Shaarli\History;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Tests\Utils;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use Shaarli\Bookmark\Bookmark;
|
use Shaarli\Bookmark\Bookmark;
|
||||||
use Shaarli\Bookmark\BookmarkArray;
|
use Shaarli\Bookmark\BookmarkArray;
|
||||||
|
|
||||||
|
@ -10,11 +13,11 @@ class ReferenceLinkDB
|
||||||
{
|
{
|
||||||
public static $NB_LINKS_TOTAL = 11;
|
public static $NB_LINKS_TOTAL = 11;
|
||||||
|
|
||||||
private $bookmarks = array();
|
protected $bookmarks = [];
|
||||||
private $_publicCount = 0;
|
protected $publicCount = 0;
|
||||||
private $_privateCount = 0;
|
protected $privateCount = 0;
|
||||||
|
|
||||||
private $isLegacy;
|
protected $isLegacy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates the test DB with reference data
|
* Populates the test DB with reference data
|
||||||
|
@ -164,7 +167,7 @@ protected function addLink(
|
||||||
$shorturl = '',
|
$shorturl = '',
|
||||||
$pinned = false
|
$pinned = false
|
||||||
) {
|
) {
|
||||||
$link = array(
|
$link = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
|
@ -175,7 +178,7 @@ protected function addLink(
|
||||||
'updated' => $updated,
|
'updated' => $updated,
|
||||||
'shorturl' => $shorturl ? $shorturl : smallHash($date->format(Bookmark::LINK_DATE_FORMAT) . $id),
|
'shorturl' => $shorturl ? $shorturl : smallHash($date->format(Bookmark::LINK_DATE_FORMAT) . $id),
|
||||||
'sticky' => $pinned
|
'sticky' => $pinned
|
||||||
);
|
];
|
||||||
if (! $this->isLegacy) {
|
if (! $this->isLegacy) {
|
||||||
$bookmark = new Bookmark();
|
$bookmark = new Bookmark();
|
||||||
$this->bookmarks[$id] = $bookmark->fromArray($link);
|
$this->bookmarks[$id] = $bookmark->fromArray($link);
|
||||||
|
@ -184,10 +187,10 @@ protected function addLink(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($private) {
|
if ($private) {
|
||||||
$this->_privateCount++;
|
$this->privateCount++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->_publicCount++;
|
$this->publicCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +236,7 @@ public function reorder($order = 'DESC')
|
||||||
*/
|
*/
|
||||||
public function countLinks()
|
public function countLinks()
|
||||||
{
|
{
|
||||||
return $this->_publicCount + $this->_privateCount;
|
return $this->publicCount + $this->privateCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,7 +244,7 @@ public function countLinks()
|
||||||
*/
|
*/
|
||||||
public function countPublicLinks()
|
public function countPublicLinks()
|
||||||
{
|
{
|
||||||
return $this->_publicCount;
|
return $this->publicCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -249,7 +252,7 @@ public function countPublicLinks()
|
||||||
*/
|
*/
|
||||||
public function countPrivateLinks()
|
public function countPrivateLinks()
|
||||||
{
|
{
|
||||||
return $this->_privateCount;
|
return $this->privateCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Tests\Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Testing the untestable - Session ID generation
|
* Testing the untestable - Session ID generation
|
||||||
*/
|
*/
|
||||||
|
@ -13,9 +16,9 @@ class ReferenceSessionIdHashes
|
||||||
public static function genAllHashes()
|
public static function genAllHashes()
|
||||||
{
|
{
|
||||||
foreach (hash_algos() as $algo) {
|
foreach (hash_algos() as $algo) {
|
||||||
self::$sidHashes[$algo] = array();
|
self::$sidHashes[$algo] = [];
|
||||||
|
|
||||||
foreach (array(4, 5, 6) as $bpc) {
|
foreach ([4, 5, 6] as $bpc) {
|
||||||
self::$sidHashes[$algo][$bpc] = self::genSidHash($algo, $bpc);
|
self::$sidHashes[$algo][$bpc] = self::genSidHash($algo, $bpc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$GLOBALS['login'] = 'root';
|
$GLOBALS['login'] = 'root';
|
||||||
$GLOBALS['hash'] = 'hash';
|
$GLOBALS['hash'] = 'hash';
|
||||||
$GLOBALS['salt'] = 'salt';
|
$GLOBALS['salt'] = 'salt';
|
||||||
|
|
Loading…
Reference in a new issue