aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php31
-rw-r--r--tests/FileUtilsTest.php12
-rw-r--r--tests/HistoryTest.php6
-rw-r--r--tests/LanguagesTest.php2
-rw-r--r--tests/PluginManagerTest.php10
-rw-r--r--tests/RouterTest.php10
-rw-r--r--tests/ThumbnailerTest.php116
-rw-r--r--tests/TimeZoneTest.php2
-rw-r--r--tests/UtilsTest.php11
-rw-r--r--tests/api/ApiMiddlewareTest.php3
-rw-r--r--tests/api/ApiUtilsTest.php7
-rw-r--r--tests/api/controllers/history/HistoryTest.php29
-rw-r--r--tests/api/controllers/info/InfoTest.php9
-rw-r--r--tests/api/controllers/links/DeleteLinkTest.php18
-rw-r--r--tests/api/controllers/links/GetLinkIdTest.php7
-rw-r--r--tests/api/controllers/links/GetLinksTest.php31
-rw-r--r--tests/api/controllers/links/PostLinkTest.php28
-rw-r--r--tests/api/controllers/links/PutLinkTest.php26
-rw-r--r--tests/api/controllers/tags/DeleteTagTest.php22
-rw-r--r--tests/api/controllers/tags/GetTagNameTest.php6
-rw-r--r--tests/api/controllers/tags/GetTagsTest.php8
-rw-r--r--tests/api/controllers/tags/PutTagTest.php18
-rw-r--r--tests/bookmark/LinkDBTest.php (renamed from tests/LinkDBTest.php)49
-rw-r--r--tests/bookmark/LinkFilterTest.php (renamed from tests/LinkFilterTest.php)33
-rw-r--r--tests/bookmark/LinkUtilsTest.php (renamed from tests/LinkUtilsTest.php)148
-rw-r--r--tests/config/ConfigJsonTest.php6
-rw-r--r--tests/config/ConfigManagerTest.php25
-rw-r--r--tests/config/ConfigPhpTest.php2
-rw-r--r--tests/config/ConfigPluginTest.php2
-rw-r--r--tests/feed/CacheTest.php (renamed from tests/CacheTest.php)25
-rw-r--r--tests/feed/CachedPageTest.php (renamed from tests/CachedPageTest.php)9
-rw-r--r--tests/feed/FeedBuilderTest.php (renamed from tests/FeedBuilderTest.php)29
-rw-r--r--tests/http/HttpUtils/ClientIpIdTest.php (renamed from tests/HttpUtils/ClientIpIdTest.php)6
-rw-r--r--tests/http/HttpUtils/GetHttpUrlTest.php (renamed from tests/HttpUtils/GetHttpUrlTest.php)10
-rw-r--r--tests/http/HttpUtils/GetIpAdressFromProxyTest.php (renamed from tests/HttpUtils/GetIpAdressFromProxyTest.php)7
-rw-r--r--tests/http/HttpUtils/IndexUrlTest.php (renamed from tests/HttpUtils/IndexUrlTest.php)6
-rw-r--r--tests/http/HttpUtils/IsHttpsTest.php (renamed from tests/HttpUtils/IsHttpsTest.php)5
-rw-r--r--tests/http/HttpUtils/PageUrlTest.php (renamed from tests/HttpUtils/PageUrlTest.php)6
-rw-r--r--tests/http/HttpUtils/ServerUrlTest.php (renamed from tests/HttpUtils/ServerUrlTest.php)6
-rw-r--r--tests/http/UrlTest.php (renamed from tests/Url/UrlTest.php)30
-rw-r--r--tests/http/UrlUtils/CleanupUrlTest.php (renamed from tests/Url/CleanupUrlTest.php)7
-rw-r--r--tests/http/UrlUtils/GetUrlSchemeTest.php (renamed from tests/Url/GetUrlSchemeTest.php)11
-rw-r--r--tests/http/UrlUtils/UnparseUrlTest.php (renamed from tests/Url/UnparseUrlTest.php)9
-rw-r--r--tests/http/UrlUtils/WhitelistProtocolsTest.php (renamed from tests/Url/WhitelistProtocolsTest.php)8
-rw-r--r--tests/languages/de/UtilsDeTest.php2
-rw-r--r--tests/languages/fr/LanguagesFrTest.php3
-rw-r--r--tests/netscape/BookmarkExportTest.php (renamed from tests/NetscapeBookmarkUtils/BookmarkExportTest.php)15
-rw-r--r--tests/netscape/BookmarkImportTest.php (renamed from tests/NetscapeBookmarkUtils/BookmarkImportTest.php)8
-rw-r--r--tests/netscape/input/empty.htm (renamed from tests/NetscapeBookmarkUtils/input/empty.htm)0
-rw-r--r--tests/netscape/input/internet_explorer_encoding.htm (renamed from tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm)0
-rw-r--r--tests/netscape/input/lowercase_doctype.htm (renamed from tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm)0
-rw-r--r--tests/netscape/input/netscape_basic.htm (renamed from tests/NetscapeBookmarkUtils/input/netscape_basic.htm)0
-rw-r--r--tests/netscape/input/netscape_nested.htm (renamed from tests/NetscapeBookmarkUtils/input/netscape_nested.htm)0
-rw-r--r--tests/netscape/input/no_doctype.htm (renamed from tests/NetscapeBookmarkUtils/input/no_doctype.htm)0
-rw-r--r--tests/netscape/input/same_date.htm (renamed from tests/NetscapeBookmarkUtils/input/same_date.htm)0
-rw-r--r--tests/plugins/PluginAddlinkTest.php10
-rw-r--r--tests/plugins/PluginArchiveorgTest.php5
-rw-r--r--tests/plugins/PluginIssoTest.php23
-rw-r--r--tests/plugins/PluginMarkdownTest.php22
-rw-r--r--tests/plugins/PluginPlayvideosTest.php7
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php7
-rw-r--r--tests/plugins/PluginQrcodeTest.php11
-rw-r--r--tests/plugins/PluginWallabagTest.php9
-rw-r--r--tests/plugins/WallabagInstanceTest.php5
-rw-r--r--tests/plugins/resources/hashtags.md10
-rw-r--r--tests/plugins/resources/hashtags.raw10
-rw-r--r--tests/plugins/resources/markdown.html8
-rw-r--r--tests/plugins/resources/markdown.md2
-rw-r--r--tests/render/ThemeUtilsTest.php (renamed from tests/ThemeUtilsTest.php)4
-rw-r--r--tests/security/LoginManagerTest.php3
-rw-r--r--tests/security/SessionManagerTest.php5
-rw-r--r--tests/updater/DummyUpdater.php (renamed from tests/Updater/DummyUpdater.php)17
-rw-r--r--tests/updater/UpdaterTest.php (renamed from tests/Updater/UpdaterTest.php)158
-rw-r--r--tests/utils/CurlUtils.php94
-rw-r--r--tests/utils/FakeApplicationUtils.php19
-rw-r--r--tests/utils/ReferenceHistory.php3
-rw-r--r--tests/utils/ReferenceLinkDB.php52
-rw-r--r--tests/utils/config/configJson.json.php71
-rw-r--r--tests/utils/config/configPhp.php4
-rw-r--r--tests/utils/config/wt.json12
80 files changed, 978 insertions, 472 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index ff4c9e17..82f8804d 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -1,33 +1,14 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli;
3
4/**
5 * ApplicationUtils' tests
6 */
7 3
8require_once 'application/ApplicationUtils.php'; 4use Shaarli\Config\ConfigManager;
9
10/**
11 * Fake ApplicationUtils class to avoid HTTP requests
12 */
13class FakeApplicationUtils extends ApplicationUtils
14{
15 public static $VERSION_CODE = '';
16
17 /**
18 * Toggle HTTP requests, allow overriding the version code
19 */
20 public static function getVersion($url, $timeout=0)
21 {
22 return self::$VERSION_CODE;
23 }
24}
25 5
6require_once 'tests/utils/FakeApplicationUtils.php';
26 7
27/** 8/**
28 * Unitary tests for Shaarli utilities 9 * Unitary tests for Shaarli utilities
29 */ 10 */
30class ApplicationUtilsTest extends PHPUnit_Framework_TestCase 11class ApplicationUtilsTest extends \PHPUnit\Framework\TestCase
31{ 12{
32 protected static $testUpdateFile = 'sandbox/update.txt'; 13 protected static $testUpdateFile = 'sandbox/update.txt';
33 protected static $testVersion = '0.5.0'; 14 protected static $testVersion = '0.5.0';
@@ -67,7 +48,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
67 '0.5.4', 48 '0.5.4',
68 ApplicationUtils::getVersion( 49 ApplicationUtils::getVersion(
69 'https://raw.githubusercontent.com/shaarli/Shaarli/' 50 'https://raw.githubusercontent.com/shaarli/Shaarli/'
70 .'v0.5.4/shaarli_version.php', 51 .'v0.5.4/shaarli_version.php',
71 $testTimeout 52 $testTimeout
72 ) 53 )
73 ); 54 );
@@ -75,7 +56,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
75 self::$versionPattern, 56 self::$versionPattern,
76 ApplicationUtils::getVersion( 57 ApplicationUtils::getVersion(
77 'https://raw.githubusercontent.com/shaarli/Shaarli/' 58 'https://raw.githubusercontent.com/shaarli/Shaarli/'
78 .'latest/shaarli_version.php', 59 .'latest/shaarli_version.php',
79 $testTimeout 60 $testTimeout
80 ) 61 )
81 ); 62 );
diff --git a/tests/FileUtilsTest.php b/tests/FileUtilsTest.php
index d764e495..57719175 100644
--- a/tests/FileUtilsTest.php
+++ b/tests/FileUtilsTest.php
@@ -1,13 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/FileUtils.php'; 3namespace Shaarli;
4
5use Exception;
4 6
5/** 7/**
6 * Class FileUtilsTest 8 * Class FileUtilsTest
7 * 9 *
8 * Test file utility class. 10 * Test file utility class.
9 */ 11 */
10class FileUtilsTest extends PHPUnit_Framework_TestCase 12class FileUtilsTest extends \PHPUnit\Framework\TestCase
11{ 13{
12 /** 14 /**
13 * @var string Test file path. 15 * @var string Test file path.
@@ -48,7 +50,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
48 /** 50 /**
49 * File not writable: raise an exception. 51 * File not writable: raise an exception.
50 * 52 *
51 * @expectedException IOException 53 * @expectedException Shaarli\Exceptions\IOException
52 * @expectedExceptionMessage Error accessing "sandbox/flat.db" 54 * @expectedExceptionMessage Error accessing "sandbox/flat.db"
53 */ 55 */
54 public function testWriteWithoutPermission() 56 public function testWriteWithoutPermission()
@@ -61,7 +63,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
61 /** 63 /**
62 * Folder non existent: raise an exception. 64 * Folder non existent: raise an exception.
63 * 65 *
64 * @expectedException IOException 66 * @expectedException Shaarli\Exceptions\IOException
65 * @expectedExceptionMessage Error accessing "nopefolder" 67 * @expectedExceptionMessage Error accessing "nopefolder"
66 */ 68 */
67 public function testWriteFolderDoesNotExist() 69 public function testWriteFolderDoesNotExist()
@@ -72,7 +74,7 @@ class FileUtilsTest extends PHPUnit_Framework_TestCase
72 /** 74 /**
73 * Folder non writable: raise an exception. 75 * Folder non writable: raise an exception.
74 * 76 *
75 * @expectedException IOException 77 * @expectedException Shaarli\Exceptions\IOException
76 * @expectedExceptionMessage Error accessing "sandbox" 78 * @expectedExceptionMessage Error accessing "sandbox"
77 */ 79 */
78 public function testWriteFolderPermission() 80 public function testWriteFolderPermission()
diff --git a/tests/HistoryTest.php b/tests/HistoryTest.php
index d3bef5a3..8303e53a 100644
--- a/tests/HistoryTest.php
+++ b/tests/HistoryTest.php
@@ -1,9 +1,11 @@
1<?php 1<?php
2 2
3require_once 'application/History.php'; 3namespace Shaarli;
4 4
5use DateTime;
6use Exception;
5 7
6class HistoryTest extends PHPUnit_Framework_TestCase 8class HistoryTest extends \PHPUnit\Framework\TestCase
7{ 9{
8 /** 10 /**
9 * @var string History file path 11 * @var string History file path
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php
index 4951e09a..de83f291 100644
--- a/tests/LanguagesTest.php
+++ b/tests/LanguagesTest.php
@@ -7,7 +7,7 @@ use Shaarli\Config\ConfigManager;
7/** 7/**
8 * Class LanguagesTest. 8 * Class LanguagesTest.
9 */ 9 */
10class LanguagesTest extends \PHPUnit_Framework_TestCase 10class LanguagesTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * @var string Config file path (without extension). 13 * @var string Config file path (without extension).
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php
index 01de959c..71761ac1 100644
--- a/tests/PluginManagerTest.php
+++ b/tests/PluginManagerTest.php
@@ -1,16 +1,12 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli\Plugin;
3 3
4/** 4use Shaarli\Config\ConfigManager;
5 * Plugin Manager tests
6 */
7
8require_once 'application/PluginManager.php';
9 5
10/** 6/**
11 * Unit tests for Plugins 7 * Unit tests for Plugins
12 */ 8 */
13class PluginManagerTest extends PHPUnit_Framework_TestCase 9class PluginManagerTest extends \PHPUnit\Framework\TestCase
14{ 10{
15 /** 11 /**
16 * Path to tests plugin. 12 * Path to tests plugin.
diff --git a/tests/RouterTest.php b/tests/RouterTest.php
index 544bcf9c..0cd49bb8 100644
--- a/tests/RouterTest.php
+++ b/tests/RouterTest.php
@@ -1,15 +1,10 @@
1<?php 1<?php
2 2namespace Shaarli;
3/**
4 * Router tests
5 */
6
7require_once 'application/Router.php';
8 3
9/** 4/**
10 * Unit tests for Router 5 * Unit tests for Router
11 */ 6 */
12class RouterTest extends PHPUnit_Framework_TestCase 7class RouterTest extends \PHPUnit\Framework\TestCase
13{ 8{
14 /** 9 /**
15 * Test findPage: login page output. 10 * Test findPage: login page output.
@@ -218,7 +213,6 @@ class RouterTest extends PHPUnit_Framework_TestCase
218 Router::$PAGE_CHANGEPASSWORD, 213 Router::$PAGE_CHANGEPASSWORD,
219 Router::findPage('do=changepasswd&stuff', array(), true) 214 Router::findPage('do=changepasswd&stuff', array(), true)
220 ); 215 );
221
222 } 216 }
223 217
224 /** 218 /**
diff --git a/tests/ThumbnailerTest.php b/tests/ThumbnailerTest.php
new file mode 100644
index 00000000..c01849f7
--- /dev/null
+++ b/tests/ThumbnailerTest.php
@@ -0,0 +1,116 @@
1<?php
2
3namespace Shaarli;
4
5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager;
7use WebThumbnailer\Application\ConfigManager as WTConfigManager;
8
9/**
10 * Class ThumbnailerTest
11 *
12 * We only make 1 thumb test because:
13 *
14 * 1. the thumbnailer library is itself tested
15 * 2. we don't want to make too many external requests during the tests
16 */
17class ThumbnailerTest extends TestCase
18{
19 const WIDTH = 190;
20
21 const HEIGHT = 210;
22
23 /**
24 * @var Thumbnailer;
25 */
26 protected $thumbnailer;
27
28 /**
29 * @var ConfigManager
30 */
31 protected $conf;
32
33 public function setUp()
34 {
35 $this->conf = new ConfigManager('tests/utils/config/configJson');
36 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_ALL);
37 $this->conf->set('thumbnails.width', self::WIDTH);
38 $this->conf->set('thumbnails.height', self::HEIGHT);
39 $this->conf->set('dev.debug', true);
40
41 $this->thumbnailer = new Thumbnailer($this->conf);
42 // cache files in the sandbox
43 WTConfigManager::addFile('tests/utils/config/wt.json');
44 }
45
46 public function tearDown()
47 {
48 $this->rrmdirContent('sandbox/');
49 }
50
51 /**
52 * Test a thumbnail with a custom size in 'all' mode.
53 */
54 public function testThumbnailAllValid()
55 {
56 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/');
57 $this->assertNotFalse($thumb);
58 $image = imagecreatefromstring(file_get_contents($thumb));
59 $this->assertEquals(self::WIDTH, imagesx($image));
60 $this->assertEquals(self::HEIGHT, imagesy($image));
61 }
62
63 /**
64 * Test a thumbnail with a custom size in 'common' mode.
65 */
66 public function testThumbnailCommonValid()
67 {
68 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON);
69 $thumb = $this->thumbnailer->get('https://imgur.com/jlFgGpe');
70 $this->assertNotFalse($thumb);
71 $image = imagecreatefromstring(file_get_contents($thumb));
72 $this->assertEquals(self::WIDTH, imagesx($image));
73 $this->assertEquals(self::HEIGHT, imagesy($image));
74 }
75
76 /**
77 * Test a thumbnail in 'common' mode which isn't include in common websites.
78 */
79 public function testThumbnailCommonInvalid()
80 {
81 $this->conf->set('thumbnails.mode', Thumbnailer::MODE_COMMON);
82 $thumb = $this->thumbnailer->get('https://github.com/shaarli/Shaarli/');
83 $this->assertFalse($thumb);
84 }
85
86 /**
87 * Test a thumbnail that can't be retrieved.
88 */
89 public function testThumbnailNotValid()
90 {
91 $oldlog = ini_get('error_log');
92 ini_set('error_log', '/dev/null');
93
94 $thumbnailer = new Thumbnailer(new ConfigManager());
95 $thumb = $thumbnailer->get('nope');
96 $this->assertFalse($thumb);
97
98 ini_set('error_log', $oldlog);
99 }
100
101 protected function rrmdirContent($dir)
102 {
103 if (is_dir($dir)) {
104 $objects = scandir($dir);
105 foreach ($objects as $object) {
106 if ($object != "." && $object != "..") {
107 if (is_dir($dir."/".$object)) {
108 $this->rrmdirContent($dir."/".$object);
109 } else {
110 unlink($dir."/".$object);
111 }
112 }
113 }
114 }
115 }
116}
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php
index 127fdc19..02bf060f 100644
--- a/tests/TimeZoneTest.php
+++ b/tests/TimeZoneTest.php
@@ -8,7 +8,7 @@ require_once 'application/TimeZone.php';
8/** 8/**
9 * Unitary tests for timezone utilities 9 * Unitary tests for timezone utilities
10 */ 10 */
11class TimeZoneTest extends PHPUnit_Framework_TestCase 11class TimeZoneTest extends PHPUnit\Framework\TestCase
12{ 12{
13 /** 13 /**
14 * @var array of timezones 14 * @var array of timezones
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 6cd37a7a..8225d95a 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -10,7 +10,7 @@ require_once 'application/Languages.php';
10/** 10/**
11 * Unitary tests for Shaarli utilities 11 * Unitary tests for Shaarli utilities
12 */ 12 */
13class UtilsTest extends PHPUnit_Framework_TestCase 13class UtilsTest extends PHPUnit\Framework\TestCase
14{ 14{
15 // Log file 15 // Log file
16 protected static $testLogFile = 'tests.log'; 16 protected static $testLogFile = 'tests.log';
@@ -187,7 +187,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase
187 /** 187 /**
188 * Test generate location with valid data. 188 * Test generate location with valid data.
189 */ 189 */
190 public function testGenerateLocation() { 190 public function testGenerateLocation()
191 {
191 $ref = 'http://localhost/?test'; 192 $ref = 'http://localhost/?test';
192 $this->assertEquals($ref, generateLocation($ref, 'localhost')); 193 $this->assertEquals($ref, generateLocation($ref, 'localhost'));
193 $ref = 'http://localhost:8080/?test'; 194 $ref = 'http://localhost:8080/?test';
@@ -199,7 +200,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase
199 /** 200 /**
200 * Test generate location - anti loop. 201 * Test generate location - anti loop.
201 */ 202 */
202 public function testGenerateLocationLoop() { 203 public function testGenerateLocationLoop()
204 {
203 $ref = 'http://localhost/?test'; 205 $ref = 'http://localhost/?test';
204 $this->assertEquals('?', generateLocation($ref, 'localhost', array('test'))); 206 $this->assertEquals('?', generateLocation($ref, 'localhost', array('test')));
205 } 207 }
@@ -207,7 +209,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase
207 /** 209 /**
208 * Test generate location - from other domain. 210 * Test generate location - from other domain.
209 */ 211 */
210 public function testGenerateLocationOut() { 212 public function testGenerateLocationOut()
213 {
211 $ref = 'http://somewebsite.com/?test'; 214 $ref = 'http://somewebsite.com/?test';
212 $this->assertEquals('?', generateLocation($ref, 'localhost')); 215 $this->assertEquals('?', generateLocation($ref, 'localhost'));
213 } 216 }
diff --git a/tests/api/ApiMiddlewareTest.php b/tests/api/ApiMiddlewareTest.php
index 23a56b1c..0b9b03f2 100644
--- a/tests/api/ApiMiddlewareTest.php
+++ b/tests/api/ApiMiddlewareTest.php
@@ -2,7 +2,6 @@
2namespace Shaarli\Api; 2namespace Shaarli\Api;
3 3
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 5use Slim\Container;
7use Slim\Http\Environment; 6use Slim\Http\Environment;
8use Slim\Http\Request; 7use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
18 * 17 *
19 * @package Api 18 * @package Api
20 */ 19 */
21class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase 20class ApiMiddlewareTest extends \PHPUnit\Framework\TestCase
22{ 21{
23 /** 22 /**
24 * @var string datastore to test write operations 23 * @var string datastore to test write operations
diff --git a/tests/api/ApiUtilsTest.php b/tests/api/ApiUtilsTest.php
index 62baf4c5..ea0ae500 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -2,13 +2,12 @@
2 2
3namespace Shaarli\Api; 3namespace Shaarli\Api;
4 4
5use Shaarli\Base64Url; 5use Shaarli\Http\Base64Url;
6
7 6
8/** 7/**
9 * Class ApiUtilsTest 8 * Class ApiUtilsTest
10 */ 9 */
11class ApiUtilsTest extends \PHPUnit_Framework_TestCase 10class ApiUtilsTest extends \PHPUnit\Framework\TestCase
12{ 11{
13 /** 12 /**
14 * Force the timezone for ISO datetimes. 13 * Force the timezone for ISO datetimes.
@@ -34,7 +33,7 @@ class ApiUtilsTest extends \PHPUnit_Framework_TestCase
34 $payload = Base64Url::encode('{ 33 $payload = Base64Url::encode('{
35 "iat": '. time() .' 34 "iat": '. time() .'
36 }'); 35 }');
37 $signature = Base64Url::encode(hash_hmac('sha512', $header .'.'. $payload , $secret, true)); 36 $signature = Base64Url::encode(hash_hmac('sha512', $header .'.'. $payload, $secret, true));
38 return $header .'.'. $payload .'.'. $signature; 37 return $header .'.'. $payload .'.'. $signature;
39 } 38 }
40 39
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php
index 61046d97..e287f239 100644
--- a/tests/api/controllers/history/HistoryTest.php
+++ b/tests/api/controllers/history/HistoryTest.php
@@ -1,10 +1,9 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6
7use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use Shaarli\History;
8use Slim\Container; 7use Slim\Container;
9use Slim\Http\Environment; 8use Slim\Http\Environment;
10use Slim\Http\Request; 9use Slim\Http\Request;
@@ -12,7 +11,7 @@ use Slim\Http\Response;
12 11
13require_once 'tests/utils/ReferenceHistory.php'; 12require_once 'tests/utils/ReferenceHistory.php';
14 13
15class HistoryTest extends \PHPUnit_Framework_TestCase 14class HistoryTest extends \PHPUnit\Framework\TestCase
16{ 15{
17 /** 16 /**
18 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -35,7 +34,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
35 protected $container; 34 protected $container;
36 35
37 /** 36 /**
38 * @var History controller instance. 37 * @var HistoryController controller instance.
39 */ 38 */
40 protected $controller; 39 protected $controller;
41 40
@@ -50,9 +49,9 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
50 $this->container = new Container(); 49 $this->container = new Container();
51 $this->container['conf'] = $this->conf; 50 $this->container['conf'] = $this->conf;
52 $this->container['db'] = true; 51 $this->container['db'] = true;
53 $this->container['history'] = new \History(self::$testHistory); 52 $this->container['history'] = new History(self::$testHistory);
54 53
55 $this->controller = new History($this->container); 54 $this->controller = new HistoryController($this->container);
56 } 55 }
57 56
58 /** 57 /**
@@ -79,35 +78,35 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
79 78
80 $this->assertEquals($this->refHistory->count(), count($data)); 79 $this->assertEquals($this->refHistory->count(), count($data));
81 80
82 $this->assertEquals(\History::DELETED, $data[0]['event']); 81 $this->assertEquals(History::DELETED, $data[0]['event']);
83 $this->assertEquals( 82 $this->assertEquals(
84 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 83 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
85 $data[0]['datetime'] 84 $data[0]['datetime']
86 ); 85 );
87 $this->assertEquals(124, $data[0]['id']); 86 $this->assertEquals(124, $data[0]['id']);
88 87
89 $this->assertEquals(\History::SETTINGS, $data[1]['event']); 88 $this->assertEquals(History::SETTINGS, $data[1]['event']);
90 $this->assertEquals( 89 $this->assertEquals(
91 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 90 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
92 $data[1]['datetime'] 91 $data[1]['datetime']
93 ); 92 );
94 $this->assertNull($data[1]['id']); 93 $this->assertNull($data[1]['id']);
95 94
96 $this->assertEquals(\History::UPDATED, $data[2]['event']); 95 $this->assertEquals(History::UPDATED, $data[2]['event']);
97 $this->assertEquals( 96 $this->assertEquals(
98 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), 97 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM),
99 $data[2]['datetime'] 98 $data[2]['datetime']
100 ); 99 );
101 $this->assertEquals(123, $data[2]['id']); 100 $this->assertEquals(123, $data[2]['id']);
102 101
103 $this->assertEquals(\History::CREATED, $data[3]['event']); 102 $this->assertEquals(History::CREATED, $data[3]['event']);
104 $this->assertEquals( 103 $this->assertEquals(
105 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), 104 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM),
106 $data[3]['datetime'] 105 $data[3]['datetime']
107 ); 106 );
108 $this->assertEquals(124, $data[3]['id']); 107 $this->assertEquals(124, $data[3]['id']);
109 108
110 $this->assertEquals(\History::CREATED, $data[4]['event']); 109 $this->assertEquals(History::CREATED, $data[4]['event']);
111 $this->assertEquals( 110 $this->assertEquals(
112 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 111 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
113 $data[4]['datetime'] 112 $data[4]['datetime']
@@ -132,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
132 131
133 $this->assertEquals(1, count($data)); 132 $this->assertEquals(1, count($data));
134 133
135 $this->assertEquals(\History::DELETED, $data[0]['event']); 134 $this->assertEquals(History::DELETED, $data[0]['event']);
136 $this->assertEquals( 135 $this->assertEquals(
137 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 136 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
138 $data[0]['datetime'] 137 $data[0]['datetime']
@@ -157,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
157 156
158 $this->assertEquals(1, count($data)); 157 $this->assertEquals(1, count($data));
159 158
160 $this->assertEquals(\History::CREATED, $data[0]['event']); 159 $this->assertEquals(History::CREATED, $data[0]['event']);
161 $this->assertEquals( 160 $this->assertEquals(
162 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 161 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
163 $data[0]['datetime'] 162 $data[0]['datetime']
@@ -182,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
182 181
183 $this->assertEquals(1, count($data)); 182 $this->assertEquals(1, count($data));
184 183
185 $this->assertEquals(\History::DELETED, $data[0]['event']); 184 $this->assertEquals(History::DELETED, $data[0]['event']);
186 $this->assertEquals( 185 $this->assertEquals(
187 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 186 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
188 $data[0]['datetime'] 187 $data[0]['datetime']
@@ -207,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
207 206
208 $this->assertEquals(1, count($data)); 207 $this->assertEquals(1, count($data));
209 208
210 $this->assertEquals(\History::SETTINGS, $data[0]['event']); 209 $this->assertEquals(History::SETTINGS, $data[0]['event']);
211 $this->assertEquals( 210 $this->assertEquals(
212 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 211 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
213 $data[0]['datetime'] 212 $data[0]['datetime']
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index f7e63bfa..e70d371b 100644
--- a/tests/api/controllers/info/InfoTest.php
+++ b/tests/api/controllers/info/InfoTest.php
@@ -2,7 +2,6 @@
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 5use Slim\Container;
7use Slim\Http\Environment; 6use Slim\Http\Environment;
8use Slim\Http\Request; 7use Slim\Http\Request;
@@ -10,12 +9,12 @@ use Slim\Http\Response;
10 9
11/** 10/**
12 * Class InfoTest 11 * Class InfoTest
13 * 12 *
14 * Test REST API controller Info. 13 * Test REST API controller Info.
15 * 14 *
16 * @package Api\Controllers 15 * @package Api\Controllers
17 */ 16 */
18class InfoTest extends \PHPUnit_Framework_TestCase 17class InfoTest extends \PHPUnit\Framework\TestCase
19{ 18{
20 /** 19 /**
21 * @var string datastore to test write operations 20 * @var string datastore to test write operations
@@ -53,7 +52,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
53 52
54 $this->container = new Container(); 53 $this->container = new Container();
55 $this->container['conf'] = $this->conf; 54 $this->container['conf'] = $this->conf;
56 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 55 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
57 $this->container['history'] = null; 56 $this->container['history'] = null;
58 57
59 $this->controller = new Info($this->container); 58 $this->controller = new Info($this->container);
diff --git a/tests/api/controllers/links/DeleteLinkTest.php b/tests/api/controllers/links/DeleteLinkTest.php
index 7d797137..90193e28 100644
--- a/tests/api/controllers/links/DeleteLinkTest.php
+++ b/tests/api/controllers/links/DeleteLinkTest.php
@@ -3,13 +3,15 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
7use Slim\Container; 9use Slim\Container;
8use Slim\Http\Environment; 10use Slim\Http\Environment;
9use Slim\Http\Request; 11use Slim\Http\Request;
10use Slim\Http\Response; 12use Slim\Http\Response;
11 13
12class DeleteLinkTest extends \PHPUnit_Framework_TestCase 14class DeleteLinkTest extends \PHPUnit\Framework\TestCase
13{ 15{
14 /** 16 /**
15 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -32,12 +34,12 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 34 protected $refDB = null;
33 35
34 /** 36 /**
35 * @var \LinkDB instance. 37 * @var LinkDB instance.
36 */ 38 */
37 protected $linkDB; 39 protected $linkDB;
38 40
39 /** 41 /**
40 * @var \History instance. 42 * @var HistoryController instance.
41 */ 43 */
42 protected $history; 44 protected $history;
43 45
@@ -59,10 +61,10 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
59 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
60 $this->refDB = new \ReferenceLinkDB(); 62 $this->refDB = new \ReferenceLinkDB();
61 $this->refDB->write(self::$testDatastore); 63 $this->refDB->write(self::$testDatastore);
62 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 64 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory(); 65 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 66 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 67 $this->history = new History(self::$testHistory);
66 $this->container = new Container(); 68 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
68 $this->container['db'] = $this->linkDB; 70 $this->container['db'] = $this->linkDB;
@@ -96,11 +98,11 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
96 $this->assertEquals(204, $response->getStatusCode()); 98 $this->assertEquals(204, $response->getStatusCode());
97 $this->assertEmpty((string) $response->getBody()); 99 $this->assertEmpty((string) $response->getBody());
98 100
99 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 101 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
100 $this->assertFalse(isset($this->linkDB[$id])); 102 $this->assertFalse(isset($this->linkDB[$id]));
101 103
102 $historyEntry = $this->history->getHistory()[0]; 104 $historyEntry = $this->history->getHistory()[0];
103 $this->assertEquals(\History::DELETED, $historyEntry['event']); 105 $this->assertEquals(History::DELETED, $historyEntry['event']);
104 $this->assertTrue( 106 $this->assertTrue(
105 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 107 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
106 ); 108 );
@@ -110,7 +112,7 @@ class DeleteLinkTest extends \PHPUnit_Framework_TestCase
110 /** 112 /**
111 * Test DELETE link endpoint: reach not existing ID. 113 * Test DELETE link endpoint: reach not existing ID.
112 * 114 *
113 * @expectedException Shaarli\Api\Exceptions\ApiLinkNotFoundException 115 * @expectedException \Shaarli\Api\Exceptions\ApiLinkNotFoundException
114 */ 116 */
115 public function testDeleteLink404() 117 public function testDeleteLink404()
116 { 118 {
diff --git a/tests/api/controllers/links/GetLinkIdTest.php b/tests/api/controllers/links/GetLinkIdTest.php
index 57528d5a..cb9b7f6a 100644
--- a/tests/api/controllers/links/GetLinkIdTest.php
+++ b/tests/api/controllers/links/GetLinkIdTest.php
@@ -3,7 +3,6 @@
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6
7use Slim\Container; 6use Slim\Container;
8use Slim\Http\Environment; 7use Slim\Http\Environment;
9use Slim\Http\Request; 8use Slim\Http\Request;
@@ -18,7 +17,7 @@ use Slim\Http\Response;
18 * 17 *
19 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
20 */ 19 */
21class GetLinkIdTest extends \PHPUnit_Framework_TestCase 20class GetLinkIdTest extends \PHPUnit\Framework\TestCase
22{ 21{
23 /** 22 /**
24 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -61,7 +60,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
61 60
62 $this->container = new Container(); 61 $this->container = new Container();
63 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
64 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
65 $this->container['history'] = null; 64 $this->container['history'] = null;
66 65
67 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
@@ -108,7 +107,7 @@ class GetLinkIdTest extends \PHPUnit_Framework_TestCase
108 $this->assertEquals('sTuff', $data['tags'][0]); 107 $this->assertEquals('sTuff', $data['tags'][0]);
109 $this->assertEquals(false, $data['private']); 108 $this->assertEquals(false, $data['private']);
110 $this->assertEquals( 109 $this->assertEquals(
111 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 110 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
112 $data['created'] 111 $data['created']
113 ); 112 );
114 $this->assertEmpty($data['updated']); 113 $this->assertEmpty($data['updated']);
diff --git a/tests/api/controllers/links/GetLinksTest.php b/tests/api/controllers/links/GetLinksTest.php
index d22ed3bf..711a3152 100644
--- a/tests/api/controllers/links/GetLinksTest.php
+++ b/tests/api/controllers/links/GetLinksTest.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 6use Slim\Container;
7use Slim\Http\Environment; 7use Slim\Http\Environment;
8use Slim\Http\Request; 8use Slim\Http\Request;
@@ -17,7 +17,7 @@ use Slim\Http\Response;
17 * 17 *
18 * @package Shaarli\Api\Controllers 18 * @package Shaarli\Api\Controllers
19 */ 19 */
20class GetLinksTest extends \PHPUnit_Framework_TestCase 20class GetLinksTest extends \PHPUnit\Framework\TestCase
21{ 21{
22 /** 22 /**
23 * @var string datastore to test write operations 23 * @var string datastore to test write operations
@@ -60,7 +60,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
60 60
61 $this->container = new Container(); 61 $this->container = new Container();
62 $this->container['conf'] = $this->conf; 62 $this->container['conf'] = $this->conf;
63 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 63 $this->container['db'] = new LinkDB(self::$testDatastore, true, false);
64 $this->container['history'] = null; 64 $this->container['history'] = null;
65 65
66 $this->controller = new Links($this->container); 66 $this->controller = new Links($this->container);
@@ -95,7 +95,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
95 $this->assertEquals($this->refDB->countLinks(), count($data)); 95 $this->assertEquals($this->refDB->countLinks(), count($data));
96 96
97 // Check order 97 // Check order
98 $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; 98 $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42];
99 $cpt = 0; 99 $cpt = 0;
100 foreach ($data as $link) { 100 foreach ($data as $link) {
101 $this->assertEquals(self::NB_FIELDS_LINK, count($link)); 101 $this->assertEquals(self::NB_FIELDS_LINK, count($link));
@@ -103,7 +103,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
103 } 103 }
104 104
105 // Check first element fields 105 // Check first element fields
106 $first = $data[0]; 106 $first = $data[2];
107 $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); 107 $this->assertEquals('http://domain.tld/?WDWyig', $first['url']);
108 $this->assertEquals('WDWyig', $first['shorturl']); 108 $this->assertEquals('WDWyig', $first['shorturl']);
109 $this->assertEquals('Link title: @website', $first['title']); 109 $this->assertEquals('Link title: @website', $first['title']);
@@ -114,18 +114,18 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
114 $this->assertEquals('sTuff', $first['tags'][0]); 114 $this->assertEquals('sTuff', $first['tags'][0]);
115 $this->assertEquals(false, $first['private']); 115 $this->assertEquals(false, $first['private']);
116 $this->assertEquals( 116 $this->assertEquals(
117 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), 117 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM),
118 $first['created'] 118 $first['created']
119 ); 119 );
120 $this->assertEmpty($first['updated']); 120 $this->assertEmpty($first['updated']);
121 121
122 // Multi tags 122 // Multi tags
123 $link = $data[1]; 123 $link = $data[3];
124 $this->assertEquals(7, count($link['tags'])); 124 $this->assertEquals(7, count($link['tags']));
125 125
126 // Update date 126 // Update date
127 $this->assertEquals( 127 $this->assertEquals(
128 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), 128 \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM),
129 $link['updated'] 129 $link['updated']
130 ); 130 );
131 } 131 }
@@ -138,7 +138,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
138 { 138 {
139 $env = Environment::mock([ 139 $env = Environment::mock([
140 'REQUEST_METHOD' => 'GET', 140 'REQUEST_METHOD' => 'GET',
141 'QUERY_STRING' => 'offset=1&limit=1' 141 'QUERY_STRING' => 'offset=3&limit=1'
142 ]); 142 ]);
143 $request = Request::createFromEnvironment($env); 143 $request = Request::createFromEnvironment($env);
144 $response = $this->controller->getLinks($request, new Response()); 144 $response = $this->controller->getLinks($request, new Response());
@@ -164,7 +164,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
164 $data = json_decode((string) $response->getBody(), true); 164 $data = json_decode((string) $response->getBody(), true);
165 $this->assertEquals($this->refDB->countLinks(), count($data)); 165 $this->assertEquals($this->refDB->countLinks(), count($data));
166 // Check order 166 // Check order
167 $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; 167 $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42];
168 $cpt = 0; 168 $cpt = 0;
169 foreach ($data as $link) { 169 foreach ($data as $link) {
170 $this->assertEquals(self::NB_FIELDS_LINK, count($link)); 170 $this->assertEquals(self::NB_FIELDS_LINK, count($link));
@@ -205,7 +205,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
205 $this->assertEquals(200, $response->getStatusCode()); 205 $this->assertEquals(200, $response->getStatusCode());
206 $data = json_decode((string)$response->getBody(), true); 206 $data = json_decode((string)$response->getBody(), true);
207 $this->assertEquals($this->refDB->countLinks(), count($data)); 207 $this->assertEquals($this->refDB->countLinks(), count($data));
208 $this->assertEquals(41, $data[0]['id']); 208 $this->assertEquals(10, $data[0]['id']);
209 $this->assertEquals(41, $data[2]['id']);
209 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); 210 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
210 } 211 }
211 212
@@ -243,7 +244,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
243 $this->assertEquals(200, $response->getStatusCode()); 244 $this->assertEquals(200, $response->getStatusCode());
244 $data = json_decode((string)$response->getBody(), true); 245 $data = json_decode((string)$response->getBody(), true);
245 $this->assertEquals($this->refDB->countPublicLinks(), count($data)); 246 $this->assertEquals($this->refDB->countPublicLinks(), count($data));
246 $this->assertEquals(41, $data[0]['id']); 247 $this->assertEquals(10, $data[0]['id']);
248 $this->assertEquals(41, $data[2]['id']);
247 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); 249 $this->assertEquals(self::NB_FIELDS_LINK, count($data[0]));
248 } 250 }
249 251
@@ -413,8 +415,9 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
413 $response = $this->controller->getLinks($request, new Response()); 415 $response = $this->controller->getLinks($request, new Response());
414 $this->assertEquals(200, $response->getStatusCode()); 416 $this->assertEquals(200, $response->getStatusCode());
415 $data = json_decode((string) $response->getBody(), true); 417 $data = json_decode((string) $response->getBody(), true);
416 $this->assertEquals(9, count($data)); 418 $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, count($data));
417 $this->assertEquals(41, $data[0]['id']); 419 $this->assertEquals(10, $data[0]['id']);
420 $this->assertEquals(41, $data[2]['id']);
418 421
419 // wildcard: optional ('*' does not need to expand) 422 // wildcard: optional ('*' does not need to expand)
420 $env = Environment::mock([ 423 $env = Environment::mock([
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index 100a9170..d683a984 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -2,9 +2,9 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5
6use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
8use Slim\Container; 8use Slim\Container;
9use Slim\Http\Environment; 9use Slim\Http\Environment;
10use Slim\Http\Request; 10use Slim\Http\Request;
@@ -41,7 +41,7 @@ class PostLinkTest extends TestCase
41 protected $refDB = null; 41 protected $refDB = null;
42 42
43 /** 43 /**
44 * @var \History instance. 44 * @var HistoryController instance.
45 */ 45 */
46 protected $history; 46 protected $history;
47 47
@@ -71,12 +71,12 @@ class PostLinkTest extends TestCase
71 71
72 $refHistory = new \ReferenceHistory(); 72 $refHistory = new \ReferenceHistory();
73 $refHistory->write(self::$testHistory); 73 $refHistory->write(self::$testHistory);
74 $this->history = new \History(self::$testHistory); 74 $this->history = new History(self::$testHistory);
75 75
76 $this->container = new Container(); 76 $this->container = new Container();
77 $this->container['conf'] = $this->conf; 77 $this->container['conf'] = $this->conf;
78 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 78 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
79 $this->container['history'] = new \History(self::$testHistory); 79 $this->container['history'] = new History(self::$testHistory);
80 80
81 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
82 82
@@ -122,17 +122,19 @@ class PostLinkTest extends TestCase
122 $data = json_decode((string) $response->getBody(), true); 122 $data = json_decode((string) $response->getBody(), true);
123 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 123 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
124 $this->assertEquals(43, $data['id']); 124 $this->assertEquals(43, $data['id']);
125 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 125 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
126 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); 126 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']);
127 $this->assertEquals('?' . $data['shorturl'], $data['title']); 127 $this->assertEquals('?' . $data['shorturl'], $data['title']);
128 $this->assertEquals('', $data['description']); 128 $this->assertEquals('', $data['description']);
129 $this->assertEquals([], $data['tags']); 129 $this->assertEquals([], $data['tags']);
130 $this->assertEquals(false, $data['private']); 130 $this->assertEquals(false, $data['private']);
131 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); 131 $this->assertTrue(
132 new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
133 );
132 $this->assertEquals('', $data['updated']); 134 $this->assertEquals('', $data['updated']);
133 135
134 $historyEntry = $this->history->getHistory()[0]; 136 $historyEntry = $this->history->getHistory()[0];
135 $this->assertEquals(\History::CREATED, $historyEntry['event']); 137 $this->assertEquals(History::CREATED, $historyEntry['event']);
136 $this->assertTrue( 138 $this->assertTrue(
137 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 139 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
138 ); 140 );
@@ -165,13 +167,15 @@ class PostLinkTest extends TestCase
165 $data = json_decode((string) $response->getBody(), true); 167 $data = json_decode((string) $response->getBody(), true);
166 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 168 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
167 $this->assertEquals(43, $data['id']); 169 $this->assertEquals(43, $data['id']);
168 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 170 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
169 $this->assertEquals('http://' . $link['url'], $data['url']); 171 $this->assertEquals('http://' . $link['url'], $data['url']);
170 $this->assertEquals($link['title'], $data['title']); 172 $this->assertEquals($link['title'], $data['title']);
171 $this->assertEquals($link['description'], $data['description']); 173 $this->assertEquals($link['description'], $data['description']);
172 $this->assertEquals($link['tags'], $data['tags']); 174 $this->assertEquals($link['tags'], $data['tags']);
173 $this->assertEquals(true, $data['private']); 175 $this->assertEquals(true, $data['private']);
174 $this->assertTrue(new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); 176 $this->assertTrue(
177 new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
178 );
175 $this->assertEquals('', $data['updated']); 179 $this->assertEquals('', $data['updated']);
176 } 180 }
177 181
@@ -207,11 +211,11 @@ class PostLinkTest extends TestCase
207 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 211 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
208 $this->assertEquals(false, $data['private']); 212 $this->assertEquals(false, $data['private']);
209 $this->assertEquals( 213 $this->assertEquals(
210 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 214 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
211 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 215 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
212 ); 216 );
213 $this->assertEquals( 217 $this->assertEquals(
214 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 218 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
215 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 219 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
216 ); 220 );
217 } 221 }
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index 8a562571..cd815b66 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -3,14 +3,14 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
8use Slim\Container; 8use Slim\Container;
9use Slim\Http\Environment; 9use Slim\Http\Environment;
10use Slim\Http\Request; 10use Slim\Http\Request;
11use Slim\Http\Response; 11use Slim\Http\Response;
12 12
13class PutLinkTest extends \PHPUnit_Framework_TestCase 13class PutLinkTest extends \PHPUnit\Framework\TestCase
14{ 14{
15 /** 15 /**
16 * @var string datastore to test write operations 16 * @var string datastore to test write operations
@@ -33,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
33 protected $refDB = null; 33 protected $refDB = null;
34 34
35 /** 35 /**
36 * @var \History instance. 36 * @var HistoryController instance.
37 */ 37 */
38 protected $history; 38 protected $history;
39 39
@@ -63,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
63 63
64 $refHistory = new \ReferenceHistory(); 64 $refHistory = new \ReferenceHistory();
65 $refHistory->write(self::$testHistory); 65 $refHistory->write(self::$testHistory);
66 $this->history = new \History(self::$testHistory); 66 $this->history = new History(self::$testHistory);
67 67
68 $this->container = new Container(); 68 $this->container = new Container();
69 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
70 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 70 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
71 $this->container['history'] = new \History(self::$testHistory); 71 $this->container['history'] = new History(self::$testHistory);
72 72
73 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
74 74
@@ -115,10 +115,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
115 \DateTime::createFromFormat('Ymd_His', '20150310_114651'), 115 \DateTime::createFromFormat('Ymd_His', '20150310_114651'),
116 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 116 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
117 ); 117 );
118 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); 118 $this->assertTrue(
119 new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
120 );
119 121
120 $historyEntry = $this->history->getHistory()[0]; 122 $historyEntry = $this->history->getHistory()[0];
121 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 123 $this->assertEquals(History::UPDATED, $historyEntry['event']);
122 $this->assertTrue( 124 $this->assertTrue(
123 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 125 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
124 ); 126 );
@@ -160,7 +162,9 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
160 \DateTime::createFromFormat('Ymd_His', '20150310_114651'), 162 \DateTime::createFromFormat('Ymd_His', '20150310_114651'),
161 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 163 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
162 ); 164 );
163 $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); 165 $this->assertTrue(
166 new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
167 );
164 } 168 }
165 169
166 /** 170 /**
@@ -195,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
195 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 199 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
196 $this->assertEquals(false, $data['private']); 200 $this->assertEquals(false, $data['private']);
197 $this->assertEquals( 201 $this->assertEquals(
198 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 202 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
199 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 203 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
200 ); 204 );
201 $this->assertEquals( 205 $this->assertEquals(
202 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 206 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
203 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 207 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
204 ); 208 );
205 } 209 }
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php
index e0787ce2..84e1d56e 100644
--- a/tests/api/controllers/tags/DeleteTagTest.php
+++ b/tests/api/controllers/tags/DeleteTagTest.php
@@ -3,13 +3,15 @@
3 3
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Bookmark\LinkDB;
6use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
7use Slim\Container; 9use Slim\Container;
8use Slim\Http\Environment; 10use Slim\Http\Environment;
9use Slim\Http\Request; 11use Slim\Http\Request;
10use Slim\Http\Response; 12use Slim\Http\Response;
11 13
12class DeleteTagTest extends \PHPUnit_Framework_TestCase 14class DeleteTagTest extends \PHPUnit\Framework\TestCase
13{ 15{
14 /** 16 /**
15 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -32,12 +34,12 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 34 protected $refDB = null;
33 35
34 /** 36 /**
35 * @var \LinkDB instance. 37 * @var LinkDB instance.
36 */ 38 */
37 protected $linkDB; 39 protected $linkDB;
38 40
39 /** 41 /**
40 * @var \History instance. 42 * @var HistoryController instance.
41 */ 43 */
42 protected $history; 44 protected $history;
43 45
@@ -59,10 +61,10 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
59 $this->conf = new ConfigManager('tests/utils/config/configJson'); 61 $this->conf = new ConfigManager('tests/utils/config/configJson');
60 $this->refDB = new \ReferenceLinkDB(); 62 $this->refDB = new \ReferenceLinkDB();
61 $this->refDB->write(self::$testDatastore); 63 $this->refDB->write(self::$testDatastore);
62 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 64 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
63 $refHistory = new \ReferenceHistory(); 65 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 66 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 67 $this->history = new History(self::$testHistory);
66 $this->container = new Container(); 68 $this->container = new Container();
67 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
68 $this->container['db'] = $this->linkDB; 70 $this->container['db'] = $this->linkDB;
@@ -97,18 +99,18 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
97 $this->assertEquals(204, $response->getStatusCode()); 99 $this->assertEquals(204, $response->getStatusCode());
98 $this->assertEmpty((string) $response->getBody()); 100 $this->assertEmpty((string) $response->getBody());
99 101
100 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 102 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
101 $tags = $this->linkDB->linksCountPerTag(); 103 $tags = $this->linkDB->linksCountPerTag();
102 $this->assertFalse(isset($tags[$tagName])); 104 $this->assertFalse(isset($tags[$tagName]));
103 105
104 // 2 links affected 106 // 2 links affected
105 $historyEntry = $this->history->getHistory()[0]; 107 $historyEntry = $this->history->getHistory()[0];
106 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 108 $this->assertEquals(History::UPDATED, $historyEntry['event']);
107 $this->assertTrue( 109 $this->assertTrue(
108 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 110 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
109 ); 111 );
110 $historyEntry = $this->history->getHistory()[1]; 112 $historyEntry = $this->history->getHistory()[1];
111 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 113 $this->assertEquals(History::UPDATED, $historyEntry['event']);
112 $this->assertTrue( 114 $this->assertTrue(
113 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 115 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
114 ); 116 );
@@ -131,13 +133,13 @@ class DeleteTagTest extends \PHPUnit_Framework_TestCase
131 $this->assertEquals(204, $response->getStatusCode()); 133 $this->assertEquals(204, $response->getStatusCode());
132 $this->assertEmpty((string) $response->getBody()); 134 $this->assertEmpty((string) $response->getBody());
133 135
134 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 136 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
135 $tags = $this->linkDB->linksCountPerTag(); 137 $tags = $this->linkDB->linksCountPerTag();
136 $this->assertFalse(isset($tags[$tagName])); 138 $this->assertFalse(isset($tags[$tagName]));
137 $this->assertTrue($tags[strtolower($tagName)] > 0); 139 $this->assertTrue($tags[strtolower($tagName)] > 0);
138 140
139 $historyEntry = $this->history->getHistory()[0]; 141 $historyEntry = $this->history->getHistory()[0];
140 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 142 $this->assertEquals(History::UPDATED, $historyEntry['event']);
141 $this->assertTrue( 143 $this->assertTrue(
142 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 144 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
143 ); 145 );
diff --git a/tests/api/controllers/tags/GetTagNameTest.php b/tests/api/controllers/tags/GetTagNameTest.php
index afac228e..a2525c17 100644
--- a/tests/api/controllers/tags/GetTagNameTest.php
+++ b/tests/api/controllers/tags/GetTagNameTest.php
@@ -2,8 +2,8 @@
2 2
3namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
4 4
5use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
6
7use Slim\Container; 7use Slim\Container;
8use Slim\Http\Environment; 8use Slim\Http\Environment;
9use Slim\Http\Request; 9use Slim\Http\Request;
@@ -16,7 +16,7 @@ use Slim\Http\Response;
16 * 16 *
17 * @package Shaarli\Api\Controllers 17 * @package Shaarli\Api\Controllers
18 */ 18 */
19class GetTagNameTest extends \PHPUnit_Framework_TestCase 19class GetTagNameTest extends \PHPUnit\Framework\TestCase
20{ 20{
21 /** 21 /**
22 * @var string datastore to test write operations 22 * @var string datastore to test write operations
@@ -59,7 +59,7 @@ class GetTagNameTest extends \PHPUnit_Framework_TestCase
59 59
60 $this->container = new Container(); 60 $this->container = new Container();
61 $this->container['conf'] = $this->conf; 61 $this->container['conf'] = $this->conf;
62 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 62 $this->container['db'] = new LinkDB(self::$testDatastore, true, false);
63 $this->container['history'] = null; 63 $this->container['history'] = null;
64 64
65 $this->controller = new Tags($this->container); 65 $this->controller = new Tags($this->container);
diff --git a/tests/api/controllers/tags/GetTagsTest.php b/tests/api/controllers/tags/GetTagsTest.php
index 3fab31b0..98628c98 100644
--- a/tests/api/controllers/tags/GetTagsTest.php
+++ b/tests/api/controllers/tags/GetTagsTest.php
@@ -1,8 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Api\Controllers; 2namespace Shaarli\Api\Controllers;
3 3
4use Shaarli\Bookmark\LinkDB;
4use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
5
6use Slim\Container; 6use Slim\Container;
7use Slim\Http\Environment; 7use Slim\Http\Environment;
8use Slim\Http\Request; 8use Slim\Http\Request;
@@ -15,7 +15,7 @@ use Slim\Http\Response;
15 * 15 *
16 * @package Shaarli\Api\Controllers 16 * @package Shaarli\Api\Controllers
17 */ 17 */
18class GetTagsTest extends \PHPUnit_Framework_TestCase 18class GetTagsTest extends \PHPUnit\Framework\TestCase
19{ 19{
20 /** 20 /**
21 * @var string datastore to test write operations 21 * @var string datastore to test write operations
@@ -38,7 +38,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
38 protected $container; 38 protected $container;
39 39
40 /** 40 /**
41 * @var \LinkDB instance. 41 * @var LinkDB instance.
42 */ 42 */
43 protected $linkDB; 43 protected $linkDB;
44 44
@@ -63,7 +63,7 @@ class GetTagsTest extends \PHPUnit_Framework_TestCase
63 63
64 $this->container = new Container(); 64 $this->container = new Container();
65 $this->container['conf'] = $this->conf; 65 $this->container['conf'] = $this->conf;
66 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 66 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
67 $this->container['db'] = $this->linkDB; 67 $this->container['db'] = $this->linkDB;
68 $this->container['history'] = null; 68 $this->container['history'] = null;
69 69
diff --git a/tests/api/controllers/tags/PutTagTest.php b/tests/api/controllers/tags/PutTagTest.php
index 6f7dec22..86106fc7 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -1,17 +1,17 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6
7use Shaarli\Api\Exceptions\ApiBadParametersException; 5use Shaarli\Api\Exceptions\ApiBadParametersException;
6use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
9use Slim\Container; 9use Slim\Container;
10use Slim\Http\Environment; 10use Slim\Http\Environment;
11use Slim\Http\Request; 11use Slim\Http\Request;
12use Slim\Http\Response; 12use Slim\Http\Response;
13 13
14class PutTagTest extends \PHPUnit_Framework_TestCase 14class PutTagTest extends \PHPUnit\Framework\TestCase
15{ 15{
16 /** 16 /**
17 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -34,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
34 protected $refDB = null; 34 protected $refDB = null;
35 35
36 /** 36 /**
37 * @var \History instance. 37 * @var HistoryController instance.
38 */ 38 */
39 protected $history; 39 protected $history;
40 40
@@ -44,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
44 protected $container; 44 protected $container;
45 45
46 /** 46 /**
47 * @var \LinkDB instance. 47 * @var LinkDB instance.
48 */ 48 */
49 protected $linkDB; 49 protected $linkDB;
50 50
@@ -69,11 +69,11 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
69 69
70 $refHistory = new \ReferenceHistory(); 70 $refHistory = new \ReferenceHistory();
71 $refHistory->write(self::$testHistory); 71 $refHistory->write(self::$testHistory);
72 $this->history = new \History(self::$testHistory); 72 $this->history = new History(self::$testHistory);
73 73
74 $this->container = new Container(); 74 $this->container = new Container();
75 $this->container['conf'] = $this->conf; 75 $this->container['conf'] = $this->conf;
76 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 76 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
77 $this->container['db'] = $this->linkDB; 77 $this->container['db'] = $this->linkDB;
78 $this->container['history'] = $this->history; 78 $this->container['history'] = $this->history;
79 79
@@ -114,12 +114,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
114 $this->assertEquals(2, $tags[$newName]); 114 $this->assertEquals(2, $tags[$newName]);
115 115
116 $historyEntry = $this->history->getHistory()[0]; 116 $historyEntry = $this->history->getHistory()[0];
117 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 117 $this->assertEquals(History::UPDATED, $historyEntry['event']);
118 $this->assertTrue( 118 $this->assertTrue(
119 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 119 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
120 ); 120 );
121 $historyEntry = $this->history->getHistory()[1]; 121 $historyEntry = $this->history->getHistory()[1];
122 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 122 $this->assertEquals(History::UPDATED, $historyEntry['event']);
123 $this->assertTrue( 123 $this->assertTrue(
124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
125 ); 125 );
diff --git a/tests/LinkDBTest.php b/tests/bookmark/LinkDBTest.php
index 3b980878..ff5c0b97 100644
--- a/tests/LinkDBTest.php
+++ b/tests/bookmark/LinkDBTest.php
@@ -3,9 +3,14 @@
3 * Link datastore tests 3 * Link datastore tests
4 */ 4 */
5 5
6require_once 'application/Cache.php'; 6namespace Shaarli\Bookmark;
7require_once 'application/FileUtils.php'; 7
8require_once 'application/LinkDB.php'; 8use DateTime;
9use ReferenceLinkDB;
10use ReflectionClass;
11use Shaarli;
12
13require_once 'application/feed/Cache.php';
9require_once 'application/Utils.php'; 14require_once 'application/Utils.php';
10require_once 'tests/utils/ReferenceLinkDB.php'; 15require_once 'tests/utils/ReferenceLinkDB.php';
11 16
@@ -13,7 +18,7 @@ require_once 'tests/utils/ReferenceLinkDB.php';
13/** 18/**
14 * Unitary tests for LinkDB 19 * Unitary tests for LinkDB
15 */ 20 */
16class LinkDBTest extends PHPUnit_Framework_TestCase 21class LinkDBTest extends \PHPUnit\Framework\TestCase
17{ 22{
18 // datastore to test write operations 23 // datastore to test write operations
19 protected static $testDatastore = 'sandbox/datastore.php'; 24 protected static $testDatastore = 'sandbox/datastore.php';
@@ -73,7 +78,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
73 */ 78 */
74 protected static function getMethod($name) 79 protected static function getMethod($name)
75 { 80 {
76 $class = new ReflectionClass('LinkDB'); 81 $class = new ReflectionClass('Shaarli\Bookmark\LinkDB');
77 $method = $class->getMethod($name); 82 $method = $class->getMethod($name);
78 $method->setAccessible(true); 83 $method->setAccessible(true);
79 return $method; 84 return $method;
@@ -100,7 +105,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
100 /** 105 /**
101 * Attempt to instantiate a LinkDB whereas the datastore is not writable 106 * Attempt to instantiate a LinkDB whereas the datastore is not writable
102 * 107 *
103 * @expectedException IOException 108 * @expectedException Shaarli\Exceptions\IOException
104 * @expectedExceptionMessageRegExp /Error accessing "null"/ 109 * @expectedExceptionMessageRegExp /Error accessing "null"/
105 */ 110 */
106 public function testConstructDatastoreNotWriteable() 111 public function testConstructDatastoreNotWriteable()
@@ -187,12 +192,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
187 192
188 $link = array( 193 $link = array(
189 'id' => 42, 194 'id' => 42,
190 'title'=>'an additional link', 195 'title' => 'an additional link',
191 'url'=>'http://dum.my', 196 'url' => 'http://dum.my',
192 'description'=>'One more', 197 'description' => 'One more',
193 'private'=>0, 198 'private' => 0,
194 'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), 199 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'),
195 'tags'=>'unit test' 200 'tags' => 'unit test'
196 ); 201 );
197 $testDB[$link['id']] = $link; 202 $testDB[$link['id']] = $link;
198 $testDB->save('tests'); 203 $testDB->save('tests');
@@ -239,12 +244,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
239 public function testDays() 244 public function testDays()
240 { 245 {
241 $this->assertEquals( 246 $this->assertEquals(
242 array('20100310', '20121206', '20130614', '20150310'), 247 array('20100309', '20100310', '20121206', '20121207', '20130614', '20150310'),
243 self::$publicLinkDB->days() 248 self::$publicLinkDB->days()
244 ); 249 );
245 250
246 $this->assertEquals( 251 $this->assertEquals(
247 array('20100310', '20121206', '20130614', '20141125', '20150310'), 252 array('20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'),
248 self::$privateLinkDB->days() 253 self::$privateLinkDB->days()
249 ); 254 );
250 } 255 }
@@ -362,7 +367,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
362 public function testLinkRealUrlWithoutRedirector() 367 public function testLinkRealUrlWithoutRedirector()
363 { 368 {
364 $db = new LinkDB(self::$testDatastore, false, false); 369 $db = new LinkDB(self::$testDatastore, false, false);
365 foreach($db as $link) { 370 foreach ($db as $link) {
366 $this->assertEquals($link['url'], $link['real_url']); 371 $this->assertEquals($link['url'], $link['real_url']);
367 } 372 }
368 } 373 }
@@ -374,13 +379,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
374 { 379 {
375 $redirector = 'http://redirector.to?'; 380 $redirector = 'http://redirector.to?';
376 $db = new LinkDB(self::$testDatastore, false, false, $redirector); 381 $db = new LinkDB(self::$testDatastore, false, false, $redirector);
377 foreach($db as $link) { 382 foreach ($db as $link) {
378 $this->assertStringStartsWith($redirector, $link['real_url']); 383 $this->assertStringStartsWith($redirector, $link['real_url']);
379 $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); 384 $this->assertNotFalse(strpos($link['real_url'], urlencode('://')));
380 } 385 }
381 386
382 $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); 387 $db = new LinkDB(self::$testDatastore, false, false, $redirector, false);
383 foreach($db as $link) { 388 foreach ($db as $link) {
384 $this->assertStringStartsWith($redirector, $link['real_url']); 389 $this->assertStringStartsWith($redirector, $link['real_url']);
385 $this->assertFalse(strpos($link['real_url'], urlencode('://'))); 390 $this->assertFalse(strpos($link['real_url'], urlencode('://')));
386 } 391 }
@@ -451,7 +456,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
451 /** 456 /**
452 * Test filterHash() with an invalid smallhash. 457 * Test filterHash() with an invalid smallhash.
453 * 458 *
454 * @expectedException LinkNotFoundException 459 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
455 */ 460 */
456 public function testFilterHashInValid1() 461 public function testFilterHashInValid1()
457 { 462 {
@@ -462,7 +467,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
462 /** 467 /**
463 * Test filterHash() with an empty smallhash. 468 * Test filterHash() with an empty smallhash.
464 * 469 *
465 * @expectedException LinkNotFoundException 470 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
466 */ 471 */
467 public function testFilterHashInValid() 472 public function testFilterHashInValid()
468 { 473 {
@@ -475,13 +480,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
475 public function testReorderLinksDesc() 480 public function testReorderLinksDesc()
476 { 481 {
477 self::$privateLinkDB->reorder('ASC'); 482 self::$privateLinkDB->reorder('ASC');
478 $linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41); 483 $stickyIds = [11, 10];
484 $standardIds = [42, 4, 9, 1, 0, 7, 6, 8, 41];
485 $linkIds = array_merge($stickyIds, $standardIds);
479 $cpt = 0; 486 $cpt = 0;
480 foreach (self::$privateLinkDB as $key => $value) { 487 foreach (self::$privateLinkDB as $key => $value) {
481 $this->assertEquals($linkIds[$cpt++], $key); 488 $this->assertEquals($linkIds[$cpt++], $key);
482 } 489 }
483 self::$privateLinkDB->reorder('DESC'); 490 self::$privateLinkDB->reorder('DESC');
484 $linkIds = array_reverse($linkIds); 491 $linkIds = array_merge(array_reverse($stickyIds), array_reverse($standardIds));
485 $cpt = 0; 492 $cpt = 0;
486 foreach (self::$privateLinkDB as $key => $value) { 493 foreach (self::$privateLinkDB as $key => $value) {
487 $this->assertEquals($linkIds[$cpt++], $key); 494 $this->assertEquals($linkIds[$cpt++], $key);
diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php
index 9cd6dbd4..808f8122 100644
--- a/tests/LinkFilterTest.php
+++ b/tests/bookmark/LinkFilterTest.php
@@ -1,11 +1,14 @@
1<?php 1<?php
2 2
3require_once 'application/LinkFilter.php'; 3namespace Shaarli\Bookmark;
4
5use Exception;
6use ReferenceLinkDB;
4 7
5/** 8/**
6 * Class LinkFilterTest. 9 * Class LinkFilterTest.
7 */ 10 */
8class LinkFilterTest extends PHPUnit_Framework_TestCase 11class LinkFilterTest extends \PHPUnit\Framework\TestCase
9{ 12{
10 /** 13 /**
11 * @var string Test datastore path. 14 * @var string Test datastore path.
@@ -27,7 +30,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
27 protected static $linkDB; 30 protected static $linkDB;
28 31
29 /** 32 /**
30 * Instanciate linkFilter with ReferenceLinkDB data. 33 * Instantiate linkFilter with ReferenceLinkDB data.
31 */ 34 */
32 public static function setUpBeforeClass() 35 public static function setUpBeforeClass()
33 { 36 {
@@ -76,7 +79,19 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
76 79
77 $this->assertEquals( 80 $this->assertEquals(
78 self::$refDB->countUntaggedLinks(), 81 self::$refDB->countUntaggedLinks(),
79 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, /*$request=*/'', /*$casesensitive=*/false, /*$visibility=*/'all', /*$untaggedonly=*/true)) 82 count(
83 self::$linkFilter->filter(
84 LinkFilter::$FILTER_TAG,
85 /*$request=*/
86 '',
87 /*$casesensitive=*/
88 false,
89 /*$visibility=*/
90 'all',
91 /*$untaggedonly=*/
92 true
93 )
94 )
80 ); 95 );
81 96
82 $this->assertEquals( 97 $this->assertEquals(
@@ -219,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
219 /** 234 /**
220 * No link for this hash 235 * No link for this hash
221 * 236 *
222 * @expectedException LinkNotFoundException 237 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
223 */ 238 */
224 public function testFilterUnknownSmallHash() 239 public function testFilterUnknownSmallHash()
225 { 240 {
@@ -246,7 +261,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
246 2, 261 2,
247 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'ars.userfriendly.org')) 262 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'ars.userfriendly.org'))
248 ); 263 );
249 264
250 $this->assertEquals( 265 $this->assertEquals(
251 2, 266 2,
252 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'ars org')) 267 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'ars org'))
@@ -288,16 +303,16 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
288 1, 303 1,
289 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'publishing media')) 304 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'publishing media'))
290 ); 305 );
291 306
292 $this->assertEquals( 307 $this->assertEquals(
293 1, 308 1,
294 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'mercurial w3c')) 309 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'mercurial w3c'))
295 ); 310 );
296 311
297 $this->assertEquals( 312 $this->assertEquals(
298 3, 313 3,
299 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software"')) 314 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '"free software"'))
300 ); 315 );
301 } 316 }
302 317
303 /** 318 /**
diff --git a/tests/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 7fbd59b0..1b8688e6 100644
--- a/tests/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -1,11 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/LinkUtils.php'; 3namespace Shaarli\Bookmark;
4
5use ReferenceLinkDB;
6
7require_once 'tests/utils/CurlUtils.php';
4 8
5/** 9/**
6* Class LinkUtilsTest. 10 * Class LinkUtilsTest.
7*/ 11 */
8class LinkUtilsTest extends PHPUnit_Framework_TestCase 12class LinkUtilsTest extends \PHPUnit\Framework\TestCase
9{ 13{
10 /** 14 /**
11 * Test html_extract_title() when the title is found. 15 * Test html_extract_title() when the title is found.
@@ -13,9 +17,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
13 public function testHtmlExtractExistentTitle() 17 public function testHtmlExtractExistentTitle()
14 { 18 {
15 $title = 'Read me please.'; 19 $title = 'Read me please.';
16 $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>'; 20 $html = '<html><meta>stuff</meta><title>' . $title . '</title></html>';
17 $this->assertEquals($title, html_extract_title($html)); 21 $this->assertEquals($title, html_extract_title($html));
18 $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>'; 22 $html = '<html><title>' . $title . '</title>blabla<title>another</title></html>';
19 $this->assertEquals($title, html_extract_title($html)); 23 $this->assertEquals($title, html_extract_title($html));
20 } 24 }
21 25
@@ -34,7 +38,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
34 public function testHeadersExtractExistentCharset() 38 public function testHeadersExtractExistentCharset()
35 { 39 {
36 $charset = 'x-MacCroatian'; 40 $charset = 'x-MacCroatian';
37 $headers = 'text/html; charset='. $charset; 41 $headers = 'text/html; charset=' . $charset;
38 $this->assertEquals(strtolower($charset), header_extract_charset($headers)); 42 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
39 } 43 }
40 44
@@ -56,7 +60,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
56 public function testHtmlExtractExistentCharset() 60 public function testHtmlExtractExistentCharset()
57 { 61 {
58 $charset = 'x-MacCroatian'; 62 $charset = 'x-MacCroatian';
59 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>'; 63 $html = '<html><meta>stuff2</meta><meta charset="' . $charset . '"/></html>';
60 $this->assertEquals(strtolower($charset), html_extract_charset($html)); 64 $this->assertEquals(strtolower($charset), html_extract_charset($html));
61 } 65 }
62 66
@@ -83,7 +87,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
83 'Date: Sat, 28 Oct 2017 12:01:33 GMT', 87 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
84 'Content-Type: text/html; charset=utf-8', 88 'Content-Type: text/html; charset=utf-8',
85 'Status: 200 OK', 89 'Status: 200 OK',
86 'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea', 90 'end' => 'th=device-width">'
91 . '<title>Refactoring · GitHub</title>'
92 . '<link rel="search" type="application/opensea',
87 '<title>ignored</title>', 93 '<title>ignored</title>',
88 ]; 94 ];
89 foreach ($data as $key => $line) { 95 foreach ($data as $key => $line) {
@@ -106,7 +112,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
106 $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_no_charset'); 112 $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_no_charset');
107 $data = [ 113 $data = [
108 'HTTP/1.1 200 OK', 114 'HTTP/1.1 200 OK',
109 'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea', 115 'end' => 'th=device-width">'
116 . '<title>Refactoring · GitHub</title>'
117 . '<link rel="search" type="application/opensea',
110 '<title>ignored</title>', 118 '<title>ignored</title>',
111 ]; 119 ];
112 foreach ($data as $key => $line) { 120 foreach ($data as $key => $line) {
@@ -126,7 +134,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
126 $data = [ 134 $data = [
127 'HTTP/1.1 200 OK', 135 'HTTP/1.1 200 OK',
128 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', 136 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
129 'end' => 'th=device-width"><title>Refactoring · GitHub</title><link rel="search" type="application/opensea', 137 'end' => 'th=device-width">'
138 . '<title>Refactoring · GitHub</title>'
139 . '<link rel="search" type="application/opensea',
130 '<title>ignored</title>', 140 '<title>ignored</title>',
131 ]; 141 ];
132 foreach ($data as $key => $line) { 142 foreach ($data as $key => $line) {
@@ -211,29 +221,32 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
211 public function testText2clickableWithoutRedirector() 221 public function testText2clickableWithoutRedirector()
212 { 222 {
213 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 223 $text = 'stuff http://hello.there/is=someone#here otherstuff';
214 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; 224 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
225 . 'http://hello.there/is=someone#here</a> otherstuff';
215 $processedText = text2clickable($text, ''); 226 $processedText = text2clickable($text, '');
216 $this->assertEquals($expectedText, $processedText); 227 $this->assertEquals($expectedText, $processedText);
217 228
218 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; 229 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
219 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">http://hello.there/is=someone#here(please)</a> otherstuff'; 230 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
231 . 'http://hello.there/is=someone#here(please)</a> otherstuff';
220 $processedText = text2clickable($text, ''); 232 $processedText = text2clickable($text, '');
221 $this->assertEquals($expectedText, $processedText); 233 $this->assertEquals($expectedText, $processedText);
222 234
223 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; 235 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
224 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">http://hello.there/is=someone#here(please)&no</a> otherstuff'; 236 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
237 . 'http://hello.there/is=someone#here(please)&no</a> otherstuff';
225 $processedText = text2clickable($text, ''); 238 $processedText = text2clickable($text, '');
226 $this->assertEquals($expectedText, $processedText); 239 $this->assertEquals($expectedText, $processedText);
227 } 240 }
228 241
229 /** 242 /**
230 * Test text2clickable a redirector set. 243 * Test text2clickable with a redirector set.
231 */ 244 */
232 public function testText2clickableWithRedirector() 245 public function testText2clickableWithRedirector()
233 { 246 {
234 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 247 $text = 'stuff http://hello.there/is=someone#here otherstuff';
235 $redirector = 'http://redirector.to'; 248 $redirector = 'http://redirector.to';
236 $expectedText = 'stuff <a href="'. 249 $expectedText = 'stuff <a href="' .
237 $redirector . 250 $redirector .
238 urlencode('http://hello.there/is=someone#here') . 251 urlencode('http://hello.there/is=someone#here') .
239 '">http://hello.there/is=someone#here</a> otherstuff'; 252 '">http://hello.there/is=someone#here</a> otherstuff';
@@ -248,7 +261,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
248 { 261 {
249 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; 262 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff';
250 $redirector = 'http://redirector.to'; 263 $redirector = 'http://redirector.to';
251 $expectedText = 'stuff <a href="'. 264 $expectedText = 'stuff <a href="' .
252 $redirector . 265 $redirector .
253 'http://hello.there/?is=someone&or=something#here' . 266 'http://hello.there/?is=someone&or=something#here' .
254 '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; 267 '">http://hello.there/?is=someone&or=something#here</a> otherstuff';
@@ -261,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
261 */ 274 */
262 public function testSpace2nbsp() 275 public function testSpace2nbsp()
263 { 276 {
264 $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; 277 $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?';
265 $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?'. PHP_EOL .'&nbsp;Really?'; 278 $expectedText = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?' . PHP_EOL . '&nbsp;Really?';
266 $processedText = space2nbsp($text); 279 $processedText = space2nbsp($text);
267 $this->assertEquals($expectedText, $processedText); 280 $this->assertEquals($expectedText, $processedText);
268 } 281 }
@@ -308,106 +321,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
308 * Util function to build an hashtag link. 321 * Util function to build an hashtag link.
309 * 322 *
310 * @param string $hashtag Hashtag name. 323 * @param string $hashtag Hashtag name.
311 * @param string $index Index URL. 324 * @param string $index Index URL.
312 * 325 *
313 * @return string HTML hashtag link. 326 * @return string HTML hashtag link.
314 */ 327 */
315 private function getHashtagLink($hashtag, $index = '') 328 private function getHashtagLink($hashtag, $index = '')
316 { 329 {
317 $hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>'; 330 $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>';
318 return str_replace('$1', $hashtag, $hashtagLink); 331 return str_replace('$1', $hashtag, $hashtagLink);
319 } 332 }
320} 333}
321
322// old style mock: PHPUnit doesn't allow function mock
323
324/**
325 * Returns code 200 or html content type.
326 *
327 * @param resource $ch cURL resource
328 * @param int $type cURL info type
329 *
330 * @return int|string 200 or 'text/html'
331 */
332function ut_curl_getinfo_ok($ch, $type)
333{
334 switch ($type) {
335 case CURLINFO_RESPONSE_CODE:
336 return 200;
337 case CURLINFO_CONTENT_TYPE:
338 return 'text/html; charset=utf-8';
339 }
340}
341
342/**
343 * Returns code 200 or html content type without charset.
344 *
345 * @param resource $ch cURL resource
346 * @param int $type cURL info type
347 *
348 * @return int|string 200 or 'text/html'
349 */
350function ut_curl_getinfo_no_charset($ch, $type)
351{
352 switch ($type) {
353 case CURLINFO_RESPONSE_CODE:
354 return 200;
355 case CURLINFO_CONTENT_TYPE:
356 return 'text/html';
357 }
358}
359
360/**
361 * Invalid response code.
362 *
363 * @param resource $ch cURL resource
364 * @param int $type cURL info type
365 *
366 * @return int|string 404 or 'text/html'
367 */
368function ut_curl_getinfo_rc_ko($ch, $type)
369{
370 switch ($type) {
371 case CURLINFO_RESPONSE_CODE:
372 return 404;
373 case CURLINFO_CONTENT_TYPE:
374 return 'text/html; charset=utf-8';
375 }
376}
377
378/**
379 * Invalid content type.
380 *
381 * @param resource $ch cURL resource
382 * @param int $type cURL info type
383 *
384 * @return int|string 200 or 'text/plain'
385 */
386function ut_curl_getinfo_ct_ko($ch, $type)
387{
388 switch ($type) {
389 case CURLINFO_RESPONSE_CODE:
390 return 200;
391 case CURLINFO_CONTENT_TYPE:
392 return 'text/plain';
393 }
394}
395
396/**
397 * Invalid response code and content type.
398 *
399 * @param resource $ch cURL resource
400 * @param int $type cURL info type
401 *
402 * @return int|string 404 or 'text/plain'
403 */
404function ut_curl_getinfo_rs_ct_ko($ch, $type)
405{
406 switch ($type) {
407 case CURLINFO_RESPONSE_CODE:
408 return 404;
409 case CURLINFO_CONTENT_TYPE:
410 return 'text/plain';
411 }
412}
413
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php
index d237bc80..95ad060b 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -4,7 +4,7 @@ namespace Shaarli\Config;
4/** 4/**
5 * Class ConfigJsonTest 5 * Class ConfigJsonTest
6 */ 6 */
7class ConfigJsonTest extends \PHPUnit_Framework_TestCase 7class ConfigJsonTest extends \PHPUnit\Framework\TestCase
8{ 8{
9 /** 9 /**
10 * @var ConfigJson 10 * @var ConfigJson
@@ -111,7 +111,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
111 /** 111 /**
112 * Write to invalid path. 112 * Write to invalid path.
113 * 113 *
114 * @expectedException \IOException 114 * @expectedException \Shaarli\Exceptions\IOException
115 */ 115 */
116 public function testWriteInvalidArray() 116 public function testWriteInvalidArray()
117 { 117 {
@@ -122,7 +122,7 @@ class ConfigJsonTest extends \PHPUnit_Framework_TestCase
122 /** 122 /**
123 * Write to invalid path. 123 * Write to invalid path.
124 * 124 *
125 * @expectedException \IOException 125 * @expectedException \Shaarli\Exceptions\IOException
126 */ 126 */
127 public function testWriteInvalidBlank() 127 public function testWriteInvalidBlank()
128 { 128 {
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 1ec447b2..33830bc9 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -7,7 +7,7 @@ namespace Shaarli\Config;
7 * Note: it only test the manager with ConfigJson, 7 * Note: it only test the manager with ConfigJson,
8 * ConfigPhp is only a workaround to handle the transition to JSON type. 8 * ConfigPhp is only a workaround to handle the transition to JSON type.
9 */ 9 */
10class ConfigManagerTest extends \PHPUnit_Framework_TestCase 10class ConfigManagerTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * @var ConfigManager 13 * @var ConfigManager
@@ -81,6 +81,18 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase
81 $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff')); 81 $this->assertEquals('testSetWriteGetNested', $this->conf->get('foo.bar.key.stuff'));
82 } 82 }
83 83
84 public function testSetDeleteNested()
85 {
86 $this->conf->set('foo.bar.key.stuff', 'testSetDeleteNested');
87 $this->assertTrue($this->conf->exists('foo.bar'));
88 $this->assertTrue($this->conf->exists('foo.bar.key.stuff'));
89 $this->assertEquals('testSetDeleteNested', $this->conf->get('foo.bar.key.stuff'));
90
91 $this->conf->remove('foo.bar');
92 $this->assertFalse($this->conf->exists('foo.bar.key.stuff'));
93 $this->assertFalse($this->conf->exists('foo.bar'));
94 }
95
84 /** 96 /**
85 * Set with an empty key. 97 * Set with an empty key.
86 * 98 *
@@ -104,6 +116,17 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase
104 } 116 }
105 117
106 /** 118 /**
119 * Remove with an empty key.
120 *
121 * @expectedException \Exception
122 * @expectedExceptionMessageRegExp #^Invalid setting key parameter. String expected, got.*#
123 */
124 public function testRmoveEmptyKey()
125 {
126 $this->conf->remove('');
127 }
128
129 /**
107 * Try to write the config without mandatory parameter (e.g. 'login'). 130 * Try to write the config without mandatory parameter (e.g. 'login').
108 * 131 *
109 * @expectedException Shaarli\Config\Exception\MissingFieldConfigException 132 * @expectedException Shaarli\Config\Exception\MissingFieldConfigException
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php
index be23eea1..67d878ce 100644
--- a/tests/config/ConfigPhpTest.php
+++ b/tests/config/ConfigPhpTest.php
@@ -4,7 +4,7 @@ namespace Shaarli\Config;
4/** 4/**
5 * Class ConfigPhpTest 5 * Class ConfigPhpTest
6 */ 6 */
7class ConfigPhpTest extends \PHPUnit_Framework_TestCase 7class ConfigPhpTest extends \PHPUnit\Framework\TestCase
8{ 8{
9 /** 9 /**
10 * @var ConfigPhp 10 * @var ConfigPhp
diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php
index deb02c9e..d7a70e68 100644
--- a/tests/config/ConfigPluginTest.php
+++ b/tests/config/ConfigPluginTest.php
@@ -8,7 +8,7 @@ require_once 'application/config/ConfigPlugin.php';
8/** 8/**
9 * Unitary tests for Shaarli config related functions 9 * Unitary tests for Shaarli config related functions
10 */ 10 */
11class ConfigPluginTest extends \PHPUnit_Framework_TestCase 11class ConfigPluginTest extends \PHPUnit\Framework\TestCase
12{ 12{
13 /** 13 /**
14 * Test save_plugin_config with valid data. 14 * Test save_plugin_config with valid data.
diff --git a/tests/CacheTest.php b/tests/feed/CacheTest.php
index 992e26a5..c0a9f26f 100644
--- a/tests/CacheTest.php
+++ b/tests/feed/CacheTest.php
@@ -2,16 +2,17 @@
2/** 2/**
3 * Cache tests 3 * Cache tests
4 */ 4 */
5namespace Shaarli\Feed;
5 6
6// required to access $_SESSION array 7// required to access $_SESSION array
7session_start(); 8session_start();
8 9
9require_once 'application/Cache.php'; 10require_once 'application/feed/Cache.php';
10 11
11/** 12/**
12 * Unitary tests for cached pages 13 * Unitary tests for cached pages
13 */ 14 */
14class CacheTest extends PHPUnit_Framework_TestCase 15class CacheTest extends \PHPUnit\Framework\TestCase
15{ 16{
16 // test cache directory 17 // test cache directory
17 protected static $testCacheDir = 'sandbox/dummycache'; 18 protected static $testCacheDir = 'sandbox/dummycache';
@@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase
25 */ 26 */
26 public function setUp() 27 public function setUp()
27 { 28 {
28 if (! is_dir(self::$testCacheDir)) { 29 if (!is_dir(self::$testCacheDir)) {
29 mkdir(self::$testCacheDir); 30 mkdir(self::$testCacheDir);
30 } else { 31 } else {
31 array_map('unlink', glob(self::$testCacheDir.'/*')); 32 array_map('unlink', glob(self::$testCacheDir . '/*'));
32 } 33 }
33 34
34 foreach (self::$pages as $page) { 35 foreach (self::$pages as $page) {
35 file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); 36 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
36 } 37 }
37 file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); 38 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
38 } 39 }
39 40
40 /** 41 /**
@@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
42 */ 43 */
43 public function tearDown() 44 public function tearDown()
44 { 45 {
45 array_map('unlink', glob(self::$testCacheDir.'/*')); 46 array_map('unlink', glob(self::$testCacheDir . '/*'));
46 rmdir(self::$testCacheDir); 47 rmdir(self::$testCacheDir);
47 } 48 }
48 49
@@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase
53 { 54 {
54 purgeCachedPages(self::$testCacheDir); 55 purgeCachedPages(self::$testCacheDir);
55 foreach (self::$pages as $page) { 56 foreach (self::$pages as $page) {
56 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
57 } 58 }
58 59
59 $this->assertFileExists(self::$testCacheDir.'/intru.der'); 60 $this->assertFileExists(self::$testCacheDir . '/intru.der');
60 } 61 }
61 62
62 /** 63 /**
@@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
68 ini_set('error_log', '/dev/null'); 69 ini_set('error_log', '/dev/null');
69 $this->assertEquals( 70 $this->assertEquals(
70 'Cannot purge sandbox/dummycache_missing: no directory', 71 'Cannot purge sandbox/dummycache_missing: no directory',
71 purgeCachedPages(self::$testCacheDir.'_missing') 72 purgeCachedPages(self::$testCacheDir . '_missing')
72 ); 73 );
73 ini_set('error_log', $oldlog); 74 ini_set('error_log', $oldlog);
74 } 75 }
@@ -83,8 +84,8 @@ class CacheTest extends PHPUnit_Framework_TestCase
83 84
84 invalidateCaches(self::$testCacheDir); 85 invalidateCaches(self::$testCacheDir);
85 foreach (self::$pages as $page) { 86 foreach (self::$pages as $page) {
86 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 87 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
87 } 88 }
88 89
89 $this->assertArrayNotHasKey('tags', $_SESSION); 90 $this->assertArrayNotHasKey('tags', $_SESSION);
90 } 91 }
diff --git a/tests/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 51565cd6..0bcc1442 100644
--- a/tests/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -2,13 +2,12 @@
2/** 2/**
3 * PageCache tests 3 * PageCache tests
4 */ 4 */
5 5namespace Shaarli\Feed;
6require_once 'application/CachedPage.php';
7 6
8/** 7/**
9 * Unitary tests for cached pages 8 * Unitary tests for cached pages
10 */ 9 */
11class CachedPageTest extends PHPUnit_Framework_TestCase 10class CachedPageTest extends \PHPUnit\Framework\TestCase
12{ 11{
13 // test cache directory 12 // test cache directory
14 protected static $testCacheDir = 'sandbox/pagecache'; 13 protected static $testCacheDir = 'sandbox/pagecache';
@@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase
20 */ 19 */
21 public static function setUpBeforeClass() 20 public static function setUpBeforeClass()
22 { 21 {
23 if (! is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
24 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
25 } 24 }
26 self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache'; 25 self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache';
27 } 26 }
28 27
29 /** 28 /**
diff --git a/tests/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index a590306d..b496cb4c 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -1,14 +1,17 @@
1<?php 1<?php
2 2
3require_once 'application/FeedBuilder.php'; 3namespace Shaarli\Feed;
4require_once 'application/LinkDB.php'; 4
5use DateTime;
6use ReferenceLinkDB;
7use Shaarli\Bookmark\LinkDB;
5 8
6/** 9/**
7 * FeedBuilderTest class. 10 * FeedBuilderTest class.
8 * 11 *
9 * Unit tests for FeedBuilder. 12 * Unit tests for FeedBuilder.
10 */ 13 */
11class FeedBuilderTest extends PHPUnit_Framework_TestCase 14class FeedBuilderTest extends \PHPUnit\Framework\TestCase
12{ 15{
13 /** 16 /**
14 * @var string locale Basque (Spain). 17 * @var string locale Basque (Spain).
@@ -82,15 +85,15 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
82 $this->assertFalse($data['usepermalinks']); 85 $this->assertFalse($data['usepermalinks']);
83 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 86 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
84 87
85 // Test first link (note link) 88 // Test first not pinned link (note link)
86 $link = reset($data['links']); 89 $link = $data['links'][array_keys($data['links'])[2]];
87 $this->assertEquals(41, $link['id']); 90 $this->assertEquals(41, $link['id']);
88 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 91 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
89 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 92 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 93 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 94 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
92 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); 95 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
93 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); 96 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
94 $this->assertEquals($pub, $up); 97 $this->assertEquals($pub, $up);
95 $this->assertContains('Stallman has a beard', $link['description']); 98 $this->assertContains('Stallman has a beard', $link['description']);
96 $this->assertContains('Permalink', $link['description']); 99 $this->assertContains('Permalink', $link['description']);
@@ -119,7 +122,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
119 $data = $feedBuilder->buildData(); 122 $data = $feedBuilder->buildData();
120 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 123 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
121 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); 124 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
122 $link = reset($data['links']); 125 $link = $data['links'][array_keys($data['links'])[2]];
123 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); 126 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
124 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']); 127 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
125 } 128 }
@@ -148,13 +151,13 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
148 public function testBuildDataCount() 151 public function testBuildDataCount()
149 { 152 {
150 $criteria = array( 153 $criteria = array(
151 'nb' => '1', 154 'nb' => '3',
152 ); 155 );
153 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); 156 $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false);
154 $feedBuilder->setLocale(self::$LOCALE); 157 $feedBuilder->setLocale(self::$LOCALE);
155 $data = $feedBuilder->buildData(); 158 $data = $feedBuilder->buildData();
156 $this->assertEquals(1, count($data['links'])); 159 $this->assertEquals(3, count($data['links']));
157 $link = array_shift($data['links']); 160 $link = $data['links'][array_keys($data['links'])[2]];
158 $this->assertEquals(41, $link['id']); 161 $this->assertEquals(41, $link['id']);
159 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 162 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
160 } 163 }
@@ -171,7 +174,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
171 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 174 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
172 $this->assertTrue($data['usepermalinks']); 175 $this->assertTrue($data['usepermalinks']);
173 // First link is a permalink 176 // First link is a permalink
174 $link = array_shift($data['links']); 177 $link = $data['links'][array_keys($data['links'])[2]];
175 $this->assertEquals(41, $link['id']); 178 $this->assertEquals(41, $link['id']);
176 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']); 179 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
177 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 180 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
@@ -179,7 +182,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
179 $this->assertContains('Direct link', $link['description']); 182 $this->assertContains('Direct link', $link['description']);
180 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 183 $this->assertContains('http://host.tld/?WDWyig', $link['description']);
181 // Second link is a direct link 184 // Second link is a direct link
182 $link = array_shift($data['links']); 185 $link = $data['links'][array_keys($data['links'])[3]];
183 $this->assertEquals(8, $link['id']); 186 $this->assertEquals(8, $link['id']);
184 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']); 187 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
185 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']); 188 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
@@ -237,7 +240,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
237 ); 240 );
238 241
239 // Test first link (note link) 242 // Test first link (note link)
240 $link = array_shift($data['links']); 243 $link = $data['links'][array_keys($data['links'])[2]];
241 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']); 244 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']);
242 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']); 245 $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']);
243 $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']); 246 $this->assertContains('http://host.tld:8080/~user/shaarli/?addtag=hashtag', $link['description']);
diff --git a/tests/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php
index c15ac5cc..982e57e0 100644
--- a/tests/HttpUtils/ClientIpIdTest.php
+++ b/tests/http/HttpUtils/ClientIpIdTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for client_ip_id() 11 * Unitary tests for client_ip_id()
10 */ 12 */
11class ClientIpIdTest extends PHPUnit_Framework_TestCase 13class ClientIpIdTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Get a remote client ID based on its IP 16 * Get a remote client ID based on its IP
diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php
index ea53de5f..3dc5bc9b 100644
--- a/tests/HttpUtils/GetHttpUrlTest.php
+++ b/tests/http/HttpUtils/GetHttpUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for get_http_response() 11 * Unitary tests for get_http_response()
10 */ 12 */
11class GetHttpUrlTest extends PHPUnit_Framework_TestCase 13class GetHttpUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Get an invalid local URL 16 * Get an invalid local URL
@@ -17,12 +19,12 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase
17 { 19 {
18 // Local 20 // Local
19 list($headers, $content) = get_http_response('/non/existent', 1); 21 list($headers, $content) = get_http_response('/non/existent', 1);
20 $this->assertEquals('Invalid HTTP Url', $headers[0]); 22 $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
21 $this->assertFalse($content); 23 $this->assertFalse($content);
22 24
23 // Non HTTP 25 // Non HTTP
24 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1); 26 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
25 $this->assertEquals('Invalid HTTP Url', $headers[0]); 27 $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]);
26 $this->assertFalse($content); 28 $this->assertFalse($content);
27 } 29 }
28 30
diff --git a/tests/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
index 6a74a45a..fe3a639e 100644
--- a/tests/HttpUtils/GetIpAdressFromProxyTest.php
+++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
@@ -1,11 +1,14 @@
1<?php 1<?php
2 2
3require_once 'application/HttpUtils.php'; 3namespace Shaarli\Http;
4
5require_once 'application/http/HttpUtils.php';
4 6
5/** 7/**
6 * Unitary tests for getIpAddressFromProxy() 8 * Unitary tests for getIpAddressFromProxy()
7 */ 9 */
8class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase { 10class GetIpAdressFromProxyTest extends \PHPUnit\Framework\TestCase
11{
9 12
10 /** 13 /**
11 * Test without proxy 14 * Test without proxy
diff --git a/tests/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php
index 337dcab0..bcbe59cb 100644
--- a/tests/HttpUtils/IndexUrlTest.php
+++ b/tests/http/HttpUtils/IndexUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for index_url() 11 * Unitary tests for index_url()
10 */ 12 */
11class IndexUrlTest extends PHPUnit_Framework_TestCase 13class IndexUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * If on the main page, remove "index.php" from the URL resource 16 * If on the main page, remove "index.php" from the URL resource
diff --git a/tests/HttpUtils/IsHttpsTest.php b/tests/http/HttpUtils/IsHttpsTest.php
index 097f2bcf..348956c6 100644
--- a/tests/HttpUtils/IsHttpsTest.php
+++ b/tests/http/HttpUtils/IsHttpsTest.php
@@ -1,12 +1,15 @@
1<?php 1<?php
2 2
3namespace Shaarli\Http;
4
5require_once 'application/http/HttpUtils.php';
3 6
4/** 7/**
5 * Class IsHttpsTest 8 * Class IsHttpsTest
6 * 9 *
7 * Test class for is_https() function. 10 * Test class for is_https() function.
8 */ 11 */
9class IsHttpsTest extends PHPUnit_Framework_TestCase 12class IsHttpsTest extends \PHPUnit\Framework\TestCase
10{ 13{
11 14
12 /** 15 /**
diff --git a/tests/HttpUtils/PageUrlTest.php b/tests/http/HttpUtils/PageUrlTest.php
index 4dbbe9cf..f1991716 100644
--- a/tests/HttpUtils/PageUrlTest.php
+++ b/tests/http/HttpUtils/PageUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for page_url() 11 * Unitary tests for page_url()
10 */ 12 */
11class PageUrlTest extends PHPUnit_Framework_TestCase 13class PageUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * If on the main page, remove "index.php" from the URL resource 16 * If on the main page, remove "index.php" from the URL resource
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/http/HttpUtils/ServerUrlTest.php
index 324b827a..9caf1049 100644
--- a/tests/HttpUtils/ServerUrlTest.php
+++ b/tests/http/HttpUtils/ServerUrlTest.php
@@ -3,12 +3,14 @@
3 * HttpUtils' tests 3 * HttpUtils' tests
4 */ 4 */
5 5
6require_once 'application/HttpUtils.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/HttpUtils.php';
7 9
8/** 10/**
9 * Unitary tests for server_url() 11 * Unitary tests for server_url()
10 */ 12 */
11class ServerUrlTest extends PHPUnit_Framework_TestCase 13class ServerUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Detect if the server uses SSL 16 * Detect if the server uses SSL
diff --git a/tests/Url/UrlTest.php b/tests/http/UrlTest.php
index aa2f2234..ae92f73a 100644
--- a/tests/Url/UrlTest.php
+++ b/tests/http/UrlTest.php
@@ -1,14 +1,14 @@
1<?php 1<?php
2/** 2/**
3 * Url's tests 3 * UrlUtils's tests
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8/** 8/**
9 * Unitary tests for URL utilities 9 * Unitary tests for URL utilities
10 */ 10 */
11class UrlTest extends PHPUnit_Framework_TestCase 11class UrlTest extends \PHPUnit\Framework\TestCase
12{ 12{
13 // base URL for tests 13 // base URL for tests
14 protected static $baseUrl = 'http://domain.tld:3000'; 14 protected static $baseUrl = 'http://domain.tld:3000';
@@ -16,9 +16,9 @@ class UrlTest extends PHPUnit_Framework_TestCase
16 /** 16 /**
17 * Helper method 17 * Helper method
18 */ 18 */
19 private function assertUrlIsCleaned($query='', $fragment='') 19 private function assertUrlIsCleaned($query = '', $fragment = '')
20 { 20 {
21 $url = new Url(self::$baseUrl.$query.$fragment); 21 $url = new Url(self::$baseUrl . $query . $fragment);
22 $url->cleanup(); 22 $url->cleanup();
23 $this->assertEquals(self::$baseUrl, $url->toString()); 23 $this->assertEquals(self::$baseUrl, $url->toString());
24 } 24 }
@@ -38,7 +38,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
38 public function testConstruct() 38 public function testConstruct()
39 { 39 {
40 $ref = 'http://username:password@hostname:9090/path' 40 $ref = 'http://username:password@hostname:9090/path'
41 .'?arg1=value1&arg2=value2#anchor'; 41 . '?arg1=value1&arg2=value2#anchor';
42 $url = new Url($ref); 42 $url = new Url($ref);
43 $this->assertEquals($ref, $url->toString()); 43 $this->assertEquals($ref, $url->toString());
44 } 44 }
@@ -52,7 +52,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
52 $this->assertUrlIsCleaned(); 52 $this->assertUrlIsCleaned();
53 53
54 // URL with no annoying elements 54 // URL with no annoying elements
55 $ref = self::$baseUrl.'?p1=val1&p2=1234#edit'; 55 $ref = self::$baseUrl . '?p1=val1&p2=1234#edit';
56 $url = new Url($ref); 56 $url = new Url($ref);
57 $this->assertEquals($ref, $url->cleanup()); 57 $this->assertEquals($ref, $url->cleanup());
58 } 58 }
@@ -115,33 +115,33 @@ class UrlTest extends PHPUnit_Framework_TestCase
115 // ditch annoying query params and fragment, keep useful params 115 // ditch annoying query params and fragment, keep useful params
116 $url = new Url( 116 $url = new Url(
117 self::$baseUrl 117 self::$baseUrl
118 .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' 118 . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
119 ); 119 );
120 $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); 120 $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup());
121 121
122 122
123 // ditch annoying query params, keep useful params and fragment 123 // ditch annoying query params, keep useful params and fragment
124 $url = new Url( 124 $url = new Url(
125 self::$baseUrl 125 self::$baseUrl
126 .'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' 126 . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
127 ); 127 );
128 $this->assertEquals( 128 $this->assertEquals(
129 self::$baseUrl.'?my=stuff&is=kept#again', 129 self::$baseUrl . '?my=stuff&is=kept#again',
130 $url->cleanup() 130 $url->cleanup()
131 ); 131 );
132 132
133 // test firefox reader url 133 // test firefox reader url
134 $url = new Url( 134 $url = new Url(
135 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') 135 'about://reader?url=' . urlencode(self::$baseUrl . '?my=stuff&is=kept')
136 ); 136 );
137 $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); 137 $this->assertEquals(self::$baseUrl . '?my=stuff&is=kept', $url->cleanup());
138
139 } 138 }
140 139
141 /** 140 /**
142 * Test default http scheme. 141 * Test default http scheme.
143 */ 142 */
144 public function testDefaultScheme() { 143 public function testDefaultScheme()
144 {
145 $url = new Url(self::$baseUrl); 145 $url = new Url(self::$baseUrl);
146 $this->assertEquals('http', $url->getScheme()); 146 $this->assertEquals('http', $url->getScheme());
147 $url = new Url('domain.tld'); 147 $url = new Url('domain.tld');
diff --git a/tests/Url/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php
index 1407d7d2..6c4d124b 100644
--- a/tests/Url/CleanupUrlTest.php
+++ b/tests/http/UrlUtils/CleanupUrlTest.php
@@ -3,9 +3,11 @@
3 * Unitary tests for cleanup_url() 3 * Unitary tests for cleanup_url()
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8class CleanupUrlTest extends PHPUnit_Framework_TestCase 8require_once 'application/http/UrlUtils.php';
9
10class CleanupUrlTest extends \PHPUnit\Framework\TestCase
9{ 11{
10 /** 12 /**
11 * @var string reference URL 13 * @var string reference URL
@@ -107,4 +109,3 @@ class CleanupUrlTest extends PHPUnit_Framework_TestCase
107 ); 109 );
108 } 110 }
109} 111}
110
diff --git a/tests/Url/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php
index 72d80b30..2b97f7be 100644
--- a/tests/Url/GetUrlSchemeTest.php
+++ b/tests/http/UrlUtils/GetUrlSchemeTest.php
@@ -3,12 +3,14 @@
3 * Unitary tests for get_url_scheme() 3 * Unitary tests for get_url_scheme()
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7 7
8class GetUrlSchemeTest extends PHPUnit_Framework_TestCase 8require_once 'application/http/UrlUtils.php';
9
10class GetUrlSchemeTest extends \PHPUnit\Framework\TestCase
9{ 11{
10 /** 12 /**
11 * Get empty scheme string for empty Url 13 * Get empty scheme string for empty UrlUtils
12 */ 14 */
13 public function testGetUrlSchemeEmpty() 15 public function testGetUrlSchemeEmpty()
14 { 16 {
@@ -16,7 +18,7 @@ class GetUrlSchemeTest extends PHPUnit_Framework_TestCase
16 } 18 }
17 19
18 /** 20 /**
19 * Get normal scheme of Url 21 * Get normal scheme of UrlUtils
20 */ 22 */
21 public function testGetUrlScheme() 23 public function testGetUrlScheme()
22 { 24 {
@@ -28,4 +30,3 @@ class GetUrlSchemeTest extends PHPUnit_Framework_TestCase
28 $this->assertEquals('git', get_url_scheme('git://domain.tld/push?pull=clone#checkout')); 30 $this->assertEquals('git', get_url_scheme('git://domain.tld/push?pull=clone#checkout'));
29 } 31 }
30} 32}
31
diff --git a/tests/Url/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php
index edde73e4..040d8c54 100644
--- a/tests/Url/UnparseUrlTest.php
+++ b/tests/http/UrlUtils/UnparseUrlTest.php
@@ -1,14 +1,16 @@
1<?php 1<?php
2/** 2/**
3 * Unpares Url's tests 3 * Unpares UrlUtils's tests
4 */ 4 */
5 5
6require_once 'application/Url.php'; 6namespace Shaarli\Http;
7
8require_once 'application/http/UrlUtils.php';
7 9
8/** 10/**
9 * Unitary tests for unparse_url() 11 * Unitary tests for unparse_url()
10 */ 12 */
11class UnparseUrlTest extends PHPUnit_Framework_TestCase 13class UnparseUrlTest extends \PHPUnit\Framework\TestCase
12{ 14{
13 /** 15 /**
14 * Thanks for building nothing 16 * Thanks for building nothing
@@ -28,4 +30,3 @@ class UnparseUrlTest extends PHPUnit_Framework_TestCase
28 $this->assertEquals($ref, unparse_url(parse_url($ref))); 30 $this->assertEquals($ref, unparse_url(parse_url($ref)));
29 } 31 }
30} 32}
31
diff --git a/tests/Url/WhitelistProtocolsTest.php b/tests/http/UrlUtils/WhitelistProtocolsTest.php
index a3156804..69512dbd 100644
--- a/tests/Url/WhitelistProtocolsTest.php
+++ b/tests/http/UrlUtils/WhitelistProtocolsTest.php
@@ -1,15 +1,15 @@
1<?php 1<?php
2 2
3require_once 'application/Url.php'; 3namespace Shaarli\Http;
4 4
5use Shaarli\Config\ConfigManager; 5require_once 'application/http/UrlUtils.php';
6 6
7/** 7/**
8 * Class WhitelistProtocolsTest 8 * Class WhitelistProtocolsTest
9 * 9 *
10 * Test whitelist_protocols() function of Url. 10 * Test whitelist_protocols() function of UrlUtils.
11 */ 11 */
12class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase 12class WhitelistProtocolsTest extends \PHPUnit\Framework\TestCase
13{ 13{
14 /** 14 /**
15 * Test whitelist_protocols() on a note (relative URL). 15 * Test whitelist_protocols() on a note (relative URL).
diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php
index 4569c923..588c9fd6 100644
--- a/tests/languages/de/UtilsDeTest.php
+++ b/tests/languages/de/UtilsDeTest.php
@@ -20,7 +20,7 @@ class UtilsDeTest extends UtilsTest
20 public function testDateFormatNoTime() 20 public function testDateFormatNoTime()
21 { 21 {
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); 22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertRegExp('/1\. Januar 2017/', format_date($date, false,true)); 23 $this->assertRegExp('/1\. Januar 2017/', format_date($date, false, true));
24 } 24 }
25 25
26 /** 26 /**
diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
index 0cf74891..b8b7ca3a 100644
--- a/tests/languages/fr/LanguagesFrTest.php
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -3,7 +3,6 @@
3 3
4namespace Shaarli; 4namespace Shaarli;
5 5
6
7use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
8 7
9/** 8/**
@@ -13,7 +12,7 @@ use Shaarli\Config\ConfigManager;
13 * 12 *
14 * @package Shaarli 13 * @package Shaarli
15 */ 14 */
16class LanguagesFrTest extends \PHPUnit_Framework_TestCase 15class LanguagesFrTest extends \PHPUnit\Framework\TestCase
17{ 16{
18 /** 17 /**
19 * @var string Config file path (without extension). 18 * @var string Config file path (without extension).
diff --git a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 6a47bbb9..6de9876d 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -1,11 +1,14 @@
1<?php 1<?php
2namespace Shaarli\Netscape;
2 3
3require_once 'application/NetscapeBookmarkUtils.php'; 4use Shaarli\Bookmark\LinkDB;
5
6require_once 'tests/utils/ReferenceLinkDB.php';
4 7
5/** 8/**
6 * Netscape bookmark export 9 * Netscape bookmark export
7 */ 10 */
8class BookmarkExportTest extends PHPUnit_Framework_TestCase 11class BookmarkExportTest extends \PHPUnit\Framework\TestCase
9{ 12{
10 /** 13 /**
11 * @var string datastore to test write operations 14 * @var string datastore to test write operations
@@ -13,7 +16,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
13 protected static $testDatastore = 'sandbox/datastore.php'; 16 protected static $testDatastore = 'sandbox/datastore.php';
14 17
15 /** 18 /**
16 * @var ReferenceLinkDB instance. 19 * @var \ReferenceLinkDB instance.
17 */ 20 */
18 protected static $refDb = null; 21 protected static $refDb = null;
19 22
@@ -27,7 +30,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
27 */ 30 */
28 public static function setUpBeforeClass() 31 public static function setUpBeforeClass()
29 { 32 {
30 self::$refDb = new ReferenceLinkDB(); 33 self::$refDb = new \ReferenceLinkDB();
31 self::$refDb->write(self::$testDatastore); 34 self::$refDb->write(self::$testDatastore);
32 self::$linkDb = new LinkDB(self::$testDatastore, true, false); 35 self::$linkDb = new LinkDB(self::$testDatastore, true, false);
33 } 36 }
@@ -110,7 +113,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
110 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 113 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
111 $this->assertEquals( 114 $this->assertEquals(
112 '?WDWyig', 115 '?WDWyig',
113 $links[0]['url'] 116 $links[2]['url']
114 ); 117 );
115 } 118 }
116 119
@@ -128,7 +131,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
128 ); 131 );
129 $this->assertEquals( 132 $this->assertEquals(
130 $indexUrl . '?WDWyig', 133 $indexUrl . '?WDWyig',
131 $links[0]['url'] 134 $links[2]['url']
132 ); 135 );
133 } 136 }
134} 137}
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/netscape/BookmarkImportTest.php
index f0a958cb..ccafc161 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/netscape/BookmarkImportTest.php
@@ -1,8 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Netscape;
2 3
3require_once 'application/NetscapeBookmarkUtils.php'; 4use DateTime;
4 5use Shaarli\Bookmark\LinkDB;
5use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
6 8
7/** 9/**
8 * Utility function to load a file's metadata in a $_FILES-like array 10 * Utility function to load a file's metadata in a $_FILES-like array
@@ -26,7 +28,7 @@ function file2array($filename)
26/** 28/**
27 * Netscape bookmark import 29 * Netscape bookmark import
28 */ 30 */
29class BookmarkImportTest extends PHPUnit_Framework_TestCase 31class BookmarkImportTest extends \PHPUnit\Framework\TestCase
30{ 32{
31 /** 33 /**
32 * @var string datastore to test write operations 34 * @var string datastore to test write operations
diff --git a/tests/NetscapeBookmarkUtils/input/empty.htm b/tests/netscape/input/empty.htm
index e69de29b..e69de29b 100644
--- a/tests/NetscapeBookmarkUtils/input/empty.htm
+++ b/tests/netscape/input/empty.htm
diff --git a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm b/tests/netscape/input/internet_explorer_encoding.htm
index 18703cf6..18703cf6 100644
--- a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm
+++ b/tests/netscape/input/internet_explorer_encoding.htm
diff --git a/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm b/tests/netscape/input/lowercase_doctype.htm
index 8911ad19..8911ad19 100644
--- a/tests/NetscapeBookmarkUtils/input/lowercase_doctype.htm
+++ b/tests/netscape/input/lowercase_doctype.htm
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_basic.htm b/tests/netscape/input/netscape_basic.htm
index affe0cf8..affe0cf8 100644
--- a/tests/NetscapeBookmarkUtils/input/netscape_basic.htm
+++ b/tests/netscape/input/netscape_basic.htm
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_nested.htm b/tests/netscape/input/netscape_nested.htm
index b486fe18..b486fe18 100644
--- a/tests/NetscapeBookmarkUtils/input/netscape_nested.htm
+++ b/tests/netscape/input/netscape_nested.htm
diff --git a/tests/NetscapeBookmarkUtils/input/no_doctype.htm b/tests/netscape/input/no_doctype.htm
index 766d398b..766d398b 100644
--- a/tests/NetscapeBookmarkUtils/input/no_doctype.htm
+++ b/tests/netscape/input/no_doctype.htm
diff --git a/tests/NetscapeBookmarkUtils/input/same_date.htm b/tests/netscape/input/same_date.htm
index 9d58a582..9d58a582 100644
--- a/tests/NetscapeBookmarkUtils/input/same_date.htm
+++ b/tests/netscape/input/same_date.htm
diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php
index b6239e7f..d052f8b9 100644
--- a/tests/plugins/PluginAddlinkTest.php
+++ b/tests/plugins/PluginAddlinkTest.php
@@ -1,17 +1,15 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Addlink;
2 3
3/** 4use Shaarli\Plugin\PluginManager;
4 * PluginPlayvideosTest.php 5use Shaarli\Router;
5 */
6 6
7require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; 7require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
8require_once 'application/Router.php';
9 8
10/** 9/**
11 * Class PluginAddlinkTest
12 * Unit test for the Addlink toolbar plugin 10 * Unit test for the Addlink toolbar plugin
13 */ 11 */
14class PluginAddlinkTest extends PHPUnit_Framework_TestCase 12class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
15{ 13{
16 /** 14 /**
17 * Reset plugin path. 15 * Reset plugin path.
diff --git a/tests/plugins/PluginArchiveorgTest.php b/tests/plugins/PluginArchiveorgTest.php
index fecd5f2c..510288bb 100644
--- a/tests/plugins/PluginArchiveorgTest.php
+++ b/tests/plugins/PluginArchiveorgTest.php
@@ -1,16 +1,19 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Archiveorg;
2 3
3/** 4/**
4 * PluginArchiveorgTest.php 5 * PluginArchiveorgTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9
7require_once 'plugins/archiveorg/archiveorg.php'; 10require_once 'plugins/archiveorg/archiveorg.php';
8 11
9/** 12/**
10 * Class PluginArchiveorgTest 13 * Class PluginArchiveorgTest
11 * Unit test for the archiveorg plugin 14 * Unit test for the archiveorg plugin
12 */ 15 */
13class PluginArchiveorgTest extends PHPUnit_Framework_TestCase 16class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase
14{ 17{
15 /** 18 /**
16 * Reset plugin path 19 * Reset plugin path
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 0ae73183..bdfab439 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -1,5 +1,10 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Isso;
3
4use DateTime;
5use Shaarli\Bookmark\LinkDB;
2use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\Plugin\PluginManager;
3 8
4require_once 'plugins/isso/isso.php'; 9require_once 'plugins/isso/isso.php';
5 10
@@ -8,7 +13,7 @@ require_once 'plugins/isso/isso.php';
8 * 13 *
9 * Test the Isso plugin (comment system). 14 * Test the Isso plugin (comment system).
10 */ 15 */
11class PluginIssoTest extends PHPUnit_Framework_TestCase 16class PluginIssoTest extends \PHPUnit\Framework\TestCase
12{ 17{
13 /** 18 /**
14 * Reset plugin path 19 * Reset plugin path
@@ -21,7 +26,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
21 /** 26 /**
22 * Test Isso init without errors. 27 * Test Isso init without errors.
23 */ 28 */
24 public function testWallabagInitNoError() 29 public function testIssoInitNoError()
25 { 30 {
26 $conf = new ConfigManager(''); 31 $conf = new ConfigManager('');
27 $conf->set('plugins.ISSO_SERVER', 'value'); 32 $conf->set('plugins.ISSO_SERVER', 'value');
@@ -32,7 +37,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
32 /** 37 /**
33 * Test Isso init with errors. 38 * Test Isso init with errors.
34 */ 39 */
35 public function testWallabagInitError() 40 public function testIssoInitError()
36 { 41 {
37 $conf = new ConfigManager(''); 42 $conf = new ConfigManager('');
38 $errors = isso_init($conf); 43 $errors = isso_init($conf);
@@ -96,19 +101,22 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
96 array( 101 array(
97 'id' => 12, 102 'id' => 12,
98 'url' => $str, 103 'url' => $str,
104 'shorturl' => $short1 = 'abcd',
99 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1), 105 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
100 ), 106 ),
101 array( 107 array(
102 'id' => 13, 108 'id' => 13,
103 'url' => $str . '2', 109 'url' => $str . '2',
110 'shorturl' => $short2 = 'efgh',
104 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2), 111 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
105 ), 112 ),
106 ) 113 )
107 ); 114 );
108 115
109 $processed = hook_isso_render_linklist($data, $conf); 116 $processed = hook_isso_render_linklist($data, $conf);
110 // data shouldn't be altered 117 // link_plugin should be added for the icon
111 $this->assertEquals($data, $processed); 118 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
119 $this->assertContains('<a href="?'. $short2 .'#isso-thread">', $processed['links'][1]['link_plugin'][0]);
112 } 120 }
113 121
114 /** 122 /**
@@ -127,6 +135,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
127 array( 135 array(
128 'id' => 12, 136 'id' => 12,
129 'url' => $str, 137 'url' => $str,
138 'shorturl' => $short1 = 'abcd',
130 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date), 139 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
131 ) 140 )
132 ), 141 ),
@@ -135,8 +144,8 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
135 144
136 $processed = hook_isso_render_linklist($data, $conf); 145 $processed = hook_isso_render_linklist($data, $conf);
137 146
138 // data shouldn't be altered 147 // link_plugin should be added for the icon
139 $this->assertEquals($data, $processed); 148 $this->assertContains('<a href="?'. $short1 .'#isso-thread">', $processed['links'][0]['link_plugin'][0]);
140 } 149 }
141 150
142 /** 151 /**
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index b31e817f..5e7c02b0 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -1,10 +1,14 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Markdown;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
3 6
4/** 7/**
5 * PluginMarkdownTest.php 8 * PluginMarkdownTest.php
6 */ 9 */
7 10
11require_once 'application/bookmark/LinkUtils.php';
8require_once 'application/Utils.php'; 12require_once 'application/Utils.php';
9require_once 'plugins/markdown/markdown.php'; 13require_once 'plugins/markdown/markdown.php';
10 14
@@ -12,7 +16,7 @@ require_once 'plugins/markdown/markdown.php';
12 * Class PluginMarkdownTest 16 * Class PluginMarkdownTest
13 * Unit test for the Markdown plugin 17 * Unit test for the Markdown plugin
14 */ 18 */
15class PluginMarkdownTest extends PHPUnit_Framework_TestCase 19class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
16{ 20{
17 /** 21 /**
18 * @var ConfigManager instance. 22 * @var ConfigManager instance.
@@ -47,6 +51,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
47 $data = hook_markdown_render_linklist($data, $this->conf); 51 $data = hook_markdown_render_linklist($data, $this->conf);
48 $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>')); 52 $this->assertNotFalse(strpos($data['links'][0]['description'], '<h1>'));
49 $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>')); 53 $this->assertNotFalse(strpos($data['links'][0]['description'], '<p>'));
54
55 $this->assertEquals($markdown, $data['links'][0]['description_src']);
50 } 56 }
51 57
52 /** 58 /**
@@ -107,6 +113,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
107 } 113 }
108 114
109 /** 115 /**
116 * Test reverse_text2clickable().
117 */
118 public function testReverseText2clickableHashtags()
119 {
120 $text = file_get_contents('tests/plugins/resources/hashtags.raw');
121 $md = file_get_contents('tests/plugins/resources/hashtags.md');
122 $clickableText = hashtag_autolink($text);
123 $reversedText = reverse_text2clickable($clickableText);
124 $this->assertEquals($md, $reversedText);
125 }
126
127 /**
110 * Test reverse_nl2br(). 128 * Test reverse_nl2br().
111 */ 129 */
112 public function testReverseNl2br() 130 public function testReverseNl2br()
@@ -246,7 +264,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
246 $this->conf->get('security.markdown_escape', true), 264 $this->conf->get('security.markdown_escape', true),
247 $this->conf->get('security.allowed_protocols') 265 $this->conf->get('security.allowed_protocols')
248 ); 266 );
249 $this->assertEquals($html, $data); 267 $this->assertEquals($html, $data . PHP_EOL);
250 } 268 }
251 269
252 /** 270 /**
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php
index 29ad047f..51472617 100644
--- a/tests/plugins/PluginPlayvideosTest.php
+++ b/tests/plugins/PluginPlayvideosTest.php
@@ -1,17 +1,20 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Playvideos;
2 3
3/** 4/**
4 * PluginPlayvideosTest.php 5 * PluginPlayvideosTest.php
5 */ 6 */
6 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
7require_once 'plugins/playvideos/playvideos.php'; 11require_once 'plugins/playvideos/playvideos.php';
8require_once 'application/Router.php';
9 12
10/** 13/**
11 * Class PluginPlayvideosTest 14 * Class PluginPlayvideosTest
12 * Unit test for the PlayVideos plugin 15 * Unit test for the PlayVideos plugin
13 */ 16 */
14class PluginPlayvideosTest extends PHPUnit_Framework_TestCase 17class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase
15{ 18{
16 /** 19 /**
17 * Reset plugin path 20 * Reset plugin path
diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php
index 69d00936..a7bd8fc9 100644
--- a/tests/plugins/PluginPubsubhubbubTest.php
+++ b/tests/plugins/PluginPubsubhubbubTest.php
@@ -1,14 +1,17 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Pubsubhubbub;
3
2use Shaarli\Config\ConfigManager; 4use Shaarli\Config\ConfigManager;
5use Shaarli\Plugin\PluginManager;
6use Shaarli\Router;
3 7
4require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; 8require_once 'plugins/pubsubhubbub/pubsubhubbub.php';
5require_once 'application/Router.php';
6 9
7/** 10/**
8 * Class PluginPubsubhubbubTest 11 * Class PluginPubsubhubbubTest
9 * Unit test for the pubsubhubbub plugin 12 * Unit test for the pubsubhubbub plugin
10 */ 13 */
11class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase 14class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase
12{ 15{
13 /** 16 /**
14 * @var string Config file path (without extension). 17 * @var string Config file path (without extension).
diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php
index ebfadddf..0c61e14a 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -1,21 +1,26 @@
1<?php 1<?php
2namespace Shaarli\Plugin\Qrcode;
3
2/** 4/**
3 * PluginQrcodeTest.php 5 * PluginQrcodeTest.php
4 */ 6 */
5 7
8use Shaarli\Plugin\PluginManager;
9use Shaarli\Router;
10
6require_once 'plugins/qrcode/qrcode.php'; 11require_once 'plugins/qrcode/qrcode.php';
7require_once 'application/Router.php';
8 12
9/** 13/**
10 * Class PluginQrcodeTest 14 * Class PluginQrcodeTest
11 * Unit test for the QR-Code plugin 15 * Unit test for the QR-Code plugin
12 */ 16 */
13class PluginQrcodeTest extends PHPUnit_Framework_TestCase 17class PluginQrcodeTest extends \PHPUnit\Framework\TestCase
14{ 18{
15 /** 19 /**
16 * Reset plugin path 20 * Reset plugin path
17 */ 21 */
18 public function setUp() { 22 public function setUp()
23 {
19 PluginManager::$PLUGINS_PATH = 'plugins'; 24 PluginManager::$PLUGINS_PATH = 'plugins';
20 } 25 }
21 26
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 76b7887e..79751921 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -1,9 +1,8 @@
1<?php 1<?php
2use Shaarli\Config\ConfigManager; 2namespace Shaarli\Plugin\Wallabag;
3 3
4/** 4use Shaarli\Config\ConfigManager;
5 * PluginWallabagTest.php.php 5use Shaarli\Plugin\PluginManager;
6 */
7 6
8require_once 'plugins/wallabag/wallabag.php'; 7require_once 'plugins/wallabag/wallabag.php';
9 8
@@ -11,7 +10,7 @@ require_once 'plugins/wallabag/wallabag.php';
11 * Class PluginWallabagTest 10 * Class PluginWallabagTest
12 * Unit test for the Wallabag plugin 11 * Unit test for the Wallabag plugin
13 */ 12 */
14class PluginWallabagTest extends PHPUnit_Framework_TestCase 13class PluginWallabagTest extends \PHPUnit\Framework\TestCase
15{ 14{
16 /** 15 /**
17 * Reset plugin path 16 * Reset plugin path
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
index 2c466871..a3cd9076 100644
--- a/tests/plugins/WallabagInstanceTest.php
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -1,11 +1,10 @@
1<?php 1<?php
2 2namespace Shaarli\Plugin\Wallabag;
3require_once 'plugins/wallabag/WallabagInstance.php';
4 3
5/** 4/**
6 * Class WallabagInstanceTest 5 * Class WallabagInstanceTest
7 */ 6 */
8class WallabagInstanceTest extends PHPUnit_Framework_TestCase 7class WallabagInstanceTest extends \PHPUnit\Framework\TestCase
9{ 8{
10 /** 9 /**
11 * @var string wallabag url. 10 * @var string wallabag url.
diff --git a/tests/plugins/resources/hashtags.md b/tests/plugins/resources/hashtags.md
new file mode 100644
index 00000000..46326de3
--- /dev/null
+++ b/tests/plugins/resources/hashtags.md
@@ -0,0 +1,10 @@
1[#lol](?addtag=lol)
2
3 #test
4
5`#test2`
6
7```
8bla #bli blo
9#bla
10```
diff --git a/tests/plugins/resources/hashtags.raw b/tests/plugins/resources/hashtags.raw
new file mode 100644
index 00000000..9d2dc98a
--- /dev/null
+++ b/tests/plugins/resources/hashtags.raw
@@ -0,0 +1,10 @@
1#lol
2
3 #test
4
5`#test2`
6
7```
8bla #bli blo
9#bla
10```
diff --git a/tests/plugins/resources/markdown.html b/tests/plugins/resources/markdown.html
index f1df4e7e..c3460bf7 100644
--- a/tests/plugins/resources/markdown.html
+++ b/tests/plugins/resources/markdown.html
@@ -12,11 +12,11 @@
12<li><a href="http://link.tld">two</a></li> 12<li><a href="http://link.tld">two</a></li>
13<li><a href="http://link.tld">three</a></li> 13<li><a href="http://link.tld">three</a></li>
14<li><a href="http://link.tld">four</a></li> 14<li><a href="http://link.tld">four</a></li>
15<li>foo &lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt;</li> 15<li>foo <a href="?addtag=foobar">#foobar</a></li>
16</ol></li> 16</ol></li>
17</ol> 17</ol>
18<p>&lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt; foo <code>lol #foo</code> &lt;a href=&quot;?addtag=bar&quot; title=&quot;Hashtag bar&quot;&gt;#bar&lt;/a&gt;</p> 18<p><a href="?addtag=foobar">#foobar</a> foo <code>lol #foo</code> <a href="?addtag=bar">#bar</a></p>
19<p>fsdfs <a href="http://link.tld">http://link.tld</a> &lt;a href=&quot;?addtag=foobar&quot; title=&quot;Hashtag foobar&quot;&gt;#foobar&lt;/a&gt; <code>http://link.tld</code></p> 19<p>fsdfs <a href="http://link.tld">http://link.tld</a> <a href="?addtag=foobar">#foobar</a> <code>http://link.tld</code></p>
20<pre><code>http://link.tld #foobar 20<pre><code>http://link.tld #foobar
21next #foo</code></pre> 21next #foo</code></pre>
22<p>Block:</p> 22<p>Block:</p>
@@ -30,4 +30,4 @@ next #foo</code></pre>
30<a href="ftp://test.tld/path/?query=value#hash">link</a><br /> 30<a href="ftp://test.tld/path/?query=value#hash">link</a><br />
31<a href="magnet:test.tld/path/?query=value#hash">link</a><br /> 31<a href="magnet:test.tld/path/?query=value#hash">link</a><br />
32<a href="http://alert(&#039;xss&#039;)">link</a><br /> 32<a href="http://alert(&#039;xss&#039;)">link</a><br />
33<a href="http://test.tld/path/?query=value#hash">link</a></p></div> \ No newline at end of file 33<a href="http://test.tld/path/?query=value#hash">link</a></p></div>
diff --git a/tests/plugins/resources/markdown.md b/tests/plugins/resources/markdown.md
index b8ebd934..9350a8c7 100644
--- a/tests/plugins/resources/markdown.md
+++ b/tests/plugins/resources/markdown.md
@@ -31,4 +31,4 @@ lorem ipsum #foobar http://link.tld
31[link](ftp://test.tld/path/?query=value#hash) 31[link](ftp://test.tld/path/?query=value#hash)
32[link](magnet:test.tld/path/?query=value#hash) 32[link](magnet:test.tld/path/?query=value#hash)
33[link](javascript:alert('xss')) 33[link](javascript:alert('xss'))
34[link](other://test.tld/path/?query=value#hash) \ No newline at end of file 34[link](other://test.tld/path/?query=value#hash)
diff --git a/tests/ThemeUtilsTest.php b/tests/render/ThemeUtilsTest.php
index e44564be..58e3426b 100644
--- a/tests/ThemeUtilsTest.php
+++ b/tests/render/ThemeUtilsTest.php
@@ -1,13 +1,13 @@
1<?php 1<?php
2 2
3namespace Shaarli; 3namespace Shaarli\Render;
4 4
5/** 5/**
6 * Class ThemeUtilsTest 6 * Class ThemeUtilsTest
7 * 7 *
8 * @package Shaarli 8 * @package Shaarli
9 */ 9 */
10class ThemeUtilsTest extends \PHPUnit_Framework_TestCase 10class ThemeUtilsTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * Test getThemes() with existing theme directories. 13 * Test getThemes() with existing theme directories.
diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php
index b9ab5ec4..7b0262b3 100644
--- a/tests/security/LoginManagerTest.php
+++ b/tests/security/LoginManagerTest.php
@@ -2,7 +2,8 @@
2namespace Shaarli\Security; 2namespace Shaarli\Security;
3 3
4require_once 'tests/utils/FakeConfigManager.php'; 4require_once 'tests/utils/FakeConfigManager.php';
5use \PHPUnit\Framework\TestCase; 5
6use PHPUnit\Framework\TestCase;
6 7
7/** 8/**
8 * Test coverage for LoginManager 9 * Test coverage for LoginManager
diff --git a/tests/security/SessionManagerTest.php b/tests/security/SessionManagerTest.php
index 9bd868f8..f264505e 100644
--- a/tests/security/SessionManagerTest.php
+++ b/tests/security/SessionManagerTest.php
@@ -5,9 +5,8 @@ require_once 'tests/utils/FakeConfigManager.php';
5require_once 'tests/utils/ReferenceSessionIdHashes.php'; 5require_once 'tests/utils/ReferenceSessionIdHashes.php';
6ReferenceSessionIdHashes::genAllHashes(); 6ReferenceSessionIdHashes::genAllHashes();
7 7
8use \Shaarli\Security\SessionManager; 8use PHPUnit\Framework\TestCase;
9use \PHPUnit\Framework\TestCase; 9use Shaarli\Security\SessionManager;
10
11 10
12/** 11/**
13 * Test coverage for SessionManager 12 * Test coverage for SessionManager
diff --git a/tests/Updater/DummyUpdater.php b/tests/updater/DummyUpdater.php
index a0be4413..9e866f1f 100644
--- a/tests/Updater/DummyUpdater.php
+++ b/tests/updater/DummyUpdater.php
@@ -1,10 +1,15 @@
1<?php 1<?php
2namespace Shaarli\Updater;
2 3
3require_once 'application/Updater.php'; 4use Exception;
5use ReflectionClass;
6use ReflectionMethod;
7use Shaarli\Bookmark\LinkDB;
8use Shaarli\Config\ConfigManager;
4 9
5/** 10/**
6 * Class DummyUpdater. 11 * Class DummyUpdater.
7 * Extends Updater to add update method designed for unit tests. 12 * Extends updater to add update method designed for unit tests.
8 */ 13 */
9class DummyUpdater extends Updater 14class DummyUpdater extends Updater
10{ 15{
@@ -31,7 +36,7 @@ class DummyUpdater extends Updater
31 * 36 *
32 * @return bool true. 37 * @return bool true.
33 */ 38 */
34 private final function updateMethodDummy1() 39 final private function updateMethodDummy1()
35 { 40 {
36 return true; 41 return true;
37 } 42 }
@@ -41,7 +46,7 @@ class DummyUpdater extends Updater
41 * 46 *
42 * @return bool true. 47 * @return bool true.
43 */ 48 */
44 private final function updateMethodDummy2() 49 final private function updateMethodDummy2()
45 { 50 {
46 return true; 51 return true;
47 } 52 }
@@ -51,7 +56,7 @@ class DummyUpdater extends Updater
51 * 56 *
52 * @return bool true. 57 * @return bool true.
53 */ 58 */
54 private final function updateMethodDummy3() 59 final private function updateMethodDummy3()
55 { 60 {
56 return true; 61 return true;
57 } 62 }
@@ -61,7 +66,7 @@ class DummyUpdater extends Updater
61 * 66 *
62 * @throws Exception error. 67 * @throws Exception error.
63 */ 68 */
64 private final function updateMethodException() 69 final private function updateMethodException()
65 { 70 {
66 throw new Exception('whatever'); 71 throw new Exception('whatever');
67 } 72 }
diff --git a/tests/Updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index 94e3c7d3..d7df5963 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -1,16 +1,24 @@
1<?php 1<?php
2namespace Shaarli\Updater;
3
4use DateTime;
5use Exception;
6use Shaarli\Bookmark\LinkDB;
2use Shaarli\Config\ConfigJson; 7use Shaarli\Config\ConfigJson;
3use Shaarli\Config\ConfigManager; 8use Shaarli\Config\ConfigManager;
4use Shaarli\Config\ConfigPhp; 9use Shaarli\Config\ConfigPhp;
10use Shaarli\Thumbnailer;
5 11
6require_once 'tests/Updater/DummyUpdater.php'; 12require_once 'application/updater/UpdaterUtils.php';
13require_once 'tests/updater/DummyUpdater.php';
14require_once 'tests/utils/ReferenceLinkDB.php';
7require_once 'inc/rain.tpl.class.php'; 15require_once 'inc/rain.tpl.class.php';
8 16
9/** 17/**
10 * Class UpdaterTest. 18 * Class UpdaterTest.
11 * Runs unit tests against the Updater class. 19 * Runs unit tests against the updater class.
12 */ 20 */
13class UpdaterTest extends PHPUnit_Framework_TestCase 21class UpdaterTest extends \PHPUnit\Framework\TestCase
14{ 22{
15 /** 23 /**
16 * @var string Path to test datastore. 24 * @var string Path to test datastore.
@@ -20,7 +28,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
20 /** 28 /**
21 * @var string Config file path (without extension). 29 * @var string Config file path (without extension).
22 */ 30 */
23 protected static $configFile = 'tests/utils/config/configJson'; 31 protected static $configFile = 'sandbox/config';
24 32
25 /** 33 /**
26 * @var ConfigManager 34 * @var ConfigManager
@@ -32,6 +40,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
32 */ 40 */
33 public function setUp() 41 public function setUp()
34 { 42 {
43 copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php');
35 $this->conf = new ConfigManager(self::$configFile); 44 $this->conf = new ConfigManager(self::$configFile);
36 } 45 }
37 46
@@ -151,7 +160,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
151 /** 160 /**
152 * Test Update failed. 161 * Test Update failed.
153 * 162 *
154 * @expectedException UpdaterException 163 * @expectedException \Exception
155 */ 164 */
156 public function testUpdateFailed() 165 public function testUpdateFailed()
157 { 166 {
@@ -177,17 +186,17 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
177 $this->conf->setConfigFile('tests/utils/config/configPhp'); 186 $this->conf->setConfigFile('tests/utils/config/configPhp');
178 $this->conf->reset(); 187 $this->conf->reset();
179 188
180 $optionsFile = 'tests/Updater/options.php'; 189 $optionsFile = 'tests/updater/options.php';
181 $options = '<?php 190 $options = '<?php
182$GLOBALS[\'privateLinkByDefault\'] = true;'; 191$GLOBALS[\'privateLinkByDefault\'] = true;';
183 file_put_contents($optionsFile, $options); 192 file_put_contents($optionsFile, $options);
184 193
185 // tmp config file. 194 // tmp config file.
186 $this->conf->setConfigFile('tests/Updater/config'); 195 $this->conf->setConfigFile('tests/updater/config');
187 196
188 // merge configs 197 // merge configs
189 $updater = new Updater(array(), array(), $this->conf, true); 198 $updater = new Updater(array(), array(), $this->conf, true);
190 // This writes a new config file in tests/Updater/config.php 199 // This writes a new config file in tests/updater/config.php
191 $updater->updateMethodMergeDeprecatedConfigFile(); 200 $updater->updateMethodMergeDeprecatedConfigFile();
192 201
193 // make sure updated field is changed 202 // make sure updated field is changed
@@ -214,7 +223,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
214 */ 223 */
215 public function testRenameDashTags() 224 public function testRenameDashTags()
216 { 225 {
217 $refDB = new ReferenceLinkDB(); 226 $refDB = new \ReferenceLinkDB();
218 $refDB->write(self::$testDatastore); 227 $refDB->write(self::$testDatastore);
219 $linkDB = new LinkDB(self::$testDatastore, true, false); 228 $linkDB = new LinkDB(self::$testDatastore, true, false);
220 229
@@ -360,7 +369,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
360 'private' => true, 369 'private' => true,
361 ), 370 ),
362 ); 371 );
363 $refDB = new ReferenceLinkDB(); 372 $refDB = new \ReferenceLinkDB();
364 $refDB->setLinks($links); 373 $refDB->setLinks($links);
365 $refDB->write(self::$testDatastore); 374 $refDB->write(self::$testDatastore);
366 $linkDB = new LinkDB(self::$testDatastore, true, false); 375 $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -391,20 +400,32 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
391 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']); 400 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
392 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']); 401 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
393 $this->assertTrue($linkDB[0]['private']); 402 $this->assertTrue($linkDB[0]['private']);
394 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), $linkDB[0]['created']); 403 $this->assertEquals(
404 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'),
405 $linkDB[0]['created']
406 );
395 407
396 $this->assertTrue(isset($linkDB[1])); 408 $this->assertTrue(isset($linkDB[1]));
397 $this->assertFalse(isset($linkDB[1]['linkdate'])); 409 $this->assertFalse(isset($linkDB[1]['linkdate']));
398 $this->assertEquals(1, $linkDB[1]['id']); 410 $this->assertEquals(1, $linkDB[1]['id']);
399 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']); 411 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
400 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), $linkDB[1]['created']); 412 $this->assertEquals(
413 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'),
414 $linkDB[1]['created']
415 );
401 416
402 $this->assertTrue(isset($linkDB[2])); 417 $this->assertTrue(isset($linkDB[2]));
403 $this->assertFalse(isset($linkDB[2]['linkdate'])); 418 $this->assertFalse(isset($linkDB[2]['linkdate']));
404 $this->assertEquals(2, $linkDB[2]['id']); 419 $this->assertEquals(2, $linkDB[2]['id']);
405 $this->assertEquals('Geek and Poke', $linkDB[2]['title']); 420 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
406 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), $linkDB[2]['created']); 421 $this->assertEquals(
407 $this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), $linkDB[2]['updated']); 422 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'),
423 $linkDB[2]['created']
424 );
425 $this->assertEquals(
426 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'),
427 $linkDB[2]['updated']
428 );
408 } 429 }
409 430
410 /** 431 /**
@@ -412,7 +433,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
412 */ 433 */
413 public function testDatastoreIdsNothingToDo() 434 public function testDatastoreIdsNothingToDo()
414 { 435 {
415 $refDB = new ReferenceLinkDB(); 436 $refDB = new \ReferenceLinkDB();
416 $refDB->write(self::$testDatastore); 437 $refDB->write(self::$testDatastore);
417 $linkDB = new LinkDB(self::$testDatastore, true, false); 438 $linkDB = new LinkDB(self::$testDatastore, true, false);
418 439
@@ -684,4 +705,111 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
684 $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); 705 $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
685 $this->assertEquals(3, $this->conf->get('general.download_timeout')); 706 $this->assertEquals(3, $this->conf->get('general.download_timeout'));
686 } 707 }
708
709 /**
710<<<<<<< HEAD
711 * Test updateMethodWebThumbnailer with thumbnails enabled.
712 */
713 public function testUpdateMethodWebThumbnailerEnabled()
714 {
715 $this->conf->remove('thumbnails');
716 $this->conf->set('thumbnail.enable_thumbnails', true);
717 $updater = new Updater([], [], $this->conf, true, $_SESSION);
718 $this->assertTrue($updater->updateMethodWebThumbnailer());
719 $this->assertFalse($this->conf->exists('thumbnail'));
720 $this->assertEquals(\Shaarli\Thumbnailer::MODE_ALL, $this->conf->get('thumbnails.mode'));
721 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
722 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
723 $this->assertContains('You have enabled or changed thumbnails', $_SESSION['warnings'][0]);
724 }
725
726 /**
727 * Test updateMethodWebThumbnailer with thumbnails disabled.
728 */
729 public function testUpdateMethodWebThumbnailerDisabled()
730 {
731 $this->conf->remove('thumbnails');
732 $this->conf->set('thumbnail.enable_thumbnails', false);
733 $updater = new Updater([], [], $this->conf, true, $_SESSION);
734 $this->assertTrue($updater->updateMethodWebThumbnailer());
735 $this->assertFalse($this->conf->exists('thumbnail'));
736 $this->assertEquals(Thumbnailer::MODE_NONE, $this->conf->get('thumbnails.mode'));
737 $this->assertEquals(125, $this->conf->get('thumbnails.width'));
738 $this->assertEquals(90, $this->conf->get('thumbnails.height'));
739 $this->assertTrue(empty($_SESSION['warnings']));
740 }
741
742 /**
743 * Test updateMethodWebThumbnailer with thumbnails disabled.
744 */
745 public function testUpdateMethodWebThumbnailerNothingToDo()
746 {
747 $updater = new Updater([], [], $this->conf, true, $_SESSION);
748 $this->assertTrue($updater->updateMethodWebThumbnailer());
749 $this->assertFalse($this->conf->exists('thumbnail'));
750 $this->assertEquals(Thumbnailer::MODE_COMMON, $this->conf->get('thumbnails.mode'));
751 $this->assertEquals(90, $this->conf->get('thumbnails.width'));
752 $this->assertEquals(53, $this->conf->get('thumbnails.height'));
753 $this->assertTrue(empty($_SESSION['warnings']));
754 }
755
756 /**
757 * Test updateMethodSetSticky().
758 */
759 public function testUpdateStickyValid()
760 {
761 $blank = [
762 'id' => 1,
763 'url' => 'z',
764 'title' => '',
765 'description' => '',
766 'tags' => '',
767 'created' => new DateTime(),
768 ];
769 $links = [
770 1 => ['id' => 1] + $blank,
771 2 => ['id' => 2] + $blank,
772 ];
773 $refDB = new \ReferenceLinkDB();
774 $refDB->setLinks($links);
775 $refDB->write(self::$testDatastore);
776 $linkDB = new LinkDB(self::$testDatastore, true, false);
777
778 $updater = new Updater(array(), $linkDB, $this->conf, true);
779 $this->assertTrue($updater->updateMethodSetSticky());
780
781 $linkDB = new LinkDB(self::$testDatastore, true, false);
782 foreach ($linkDB as $link) {
783 $this->assertFalse($link['sticky']);
784 }
785 }
786
787 /**
788 * Test updateMethodSetSticky().
789 */
790 public function testUpdateStickyNothingToDo()
791 {
792 $blank = [
793 'id' => 1,
794 'url' => 'z',
795 'title' => '',
796 'description' => '',
797 'tags' => '',
798 'created' => new DateTime(),
799 ];
800 $links = [
801 1 => ['id' => 1, 'sticky' => true] + $blank,
802 2 => ['id' => 2] + $blank,
803 ];
804 $refDB = new \ReferenceLinkDB();
805 $refDB->setLinks($links);
806 $refDB->write(self::$testDatastore);
807 $linkDB = new LinkDB(self::$testDatastore, true, false);
808
809 $updater = new Updater(array(), $linkDB, $this->conf, true);
810 $this->assertTrue($updater->updateMethodSetSticky());
811
812 $linkDB = new LinkDB(self::$testDatastore, true, false);
813 $this->assertTrue($linkDB[1]['sticky']);
814 }
687} 815}
diff --git a/tests/utils/CurlUtils.php b/tests/utils/CurlUtils.php
new file mode 100644
index 00000000..1cc4907e
--- /dev/null
+++ b/tests/utils/CurlUtils.php
@@ -0,0 +1,94 @@
1<?php
2/**
3 * Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions
4 */
5
6/**
7 * Returns code 200 or html content type.
8 *
9 * @param resource $ch cURL resource
10 * @param int $type cURL info type
11 *
12 * @return int|string 200 or 'text/html'
13 */
14function ut_curl_getinfo_ok($ch, $type)
15{
16 switch ($type) {
17 case CURLINFO_RESPONSE_CODE:
18 return 200;
19 case CURLINFO_CONTENT_TYPE:
20 return 'text/html; charset=utf-8';
21 }
22}
23
24/**
25 * Returns code 200 or html content type without charset.
26 *
27 * @param resource $ch cURL resource
28 * @param int $type cURL info type
29 *
30 * @return int|string 200 or 'text/html'
31 */
32function ut_curl_getinfo_no_charset($ch, $type)
33{
34 switch ($type) {
35 case CURLINFO_RESPONSE_CODE:
36 return 200;
37 case CURLINFO_CONTENT_TYPE:
38 return 'text/html';
39 }
40}
41
42/**
43 * Invalid response code.
44 *
45 * @param resource $ch cURL resource
46 * @param int $type cURL info type
47 *
48 * @return int|string 404 or 'text/html'
49 */
50function ut_curl_getinfo_rc_ko($ch, $type)
51{
52 switch ($type) {
53 case CURLINFO_RESPONSE_CODE:
54 return 404;
55 case CURLINFO_CONTENT_TYPE:
56 return 'text/html; charset=utf-8';
57 }
58}
59
60/**
61 * Invalid content type.
62 *
63 * @param resource $ch cURL resource
64 * @param int $type cURL info type
65 *
66 * @return int|string 200 or 'text/plain'
67 */
68function ut_curl_getinfo_ct_ko($ch, $type)
69{
70 switch ($type) {
71 case CURLINFO_RESPONSE_CODE:
72 return 200;
73 case CURLINFO_CONTENT_TYPE:
74 return 'text/plain';
75 }
76}
77
78/**
79 * Invalid response code and content type.
80 *
81 * @param resource $ch cURL resource
82 * @param int $type cURL info type
83 *
84 * @return int|string 404 or 'text/plain'
85 */
86function ut_curl_getinfo_rs_ct_ko($ch, $type)
87{
88 switch ($type) {
89 case CURLINFO_RESPONSE_CODE:
90 return 404;
91 case CURLINFO_CONTENT_TYPE:
92 return 'text/plain';
93 }
94}
diff --git a/tests/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php
new file mode 100644
index 00000000..de83d598
--- /dev/null
+++ b/tests/utils/FakeApplicationUtils.php
@@ -0,0 +1,19 @@
1<?php
2
3namespace Shaarli;
4
5/**
6 * Fake ApplicationUtils class to avoid HTTP requests
7 */
8class FakeApplicationUtils extends ApplicationUtils
9{
10 public static $VERSION_CODE = '';
11
12 /**
13 * Toggle HTTP requests, allow overriding the version code
14 */
15 public static function getVersion($url, $timeout = 0)
16 {
17 return self::$VERSION_CODE;
18 }
19}
diff --git a/tests/utils/ReferenceHistory.php b/tests/utils/ReferenceHistory.php
index 75cbb326..e411c417 100644
--- a/tests/utils/ReferenceHistory.php
+++ b/tests/utils/ReferenceHistory.php
@@ -1,5 +1,8 @@
1<?php 1<?php
2 2
3use Shaarli\FileUtils;
4use Shaarli\History;
5
3/** 6/**
4 * Populates a reference history 7 * Populates a reference history
5 */ 8 */
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index e887aa78..c12bcb67 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -1,10 +1,13 @@
1<?php 1<?php
2
3use Shaarli\Bookmark\LinkDB;
4
2/** 5/**
3 * Populates a reference datastore to test LinkDB 6 * Populates a reference datastore to test LinkDB
4 */ 7 */
5class ReferenceLinkDB 8class ReferenceLinkDB
6{ 9{
7 public static $NB_LINKS_TOTAL = 9; 10 public static $NB_LINKS_TOTAL = 11;
8 11
9 private $_links = array(); 12 private $_links = array();
10 private $_publicCount = 0; 13 private $_publicCount = 0;
@@ -16,6 +19,32 @@ class ReferenceLinkDB
16 public function __construct() 19 public function __construct()
17 { 20 {
18 $this->addLink( 21 $this->addLink(
22 11,
23 'Pined older',
24 '?PCRizQ',
25 'This is an older pinned link',
26 0,
27 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100309_101010'),
28 '',
29 null,
30 'PCRizQ',
31 true
32 );
33
34 $this->addLink(
35 10,
36 'Pined',
37 '?0gCTjQ',
38 'This is a pinned link',
39 0,
40 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121207_152312'),
41 '',
42 null,
43 '0gCTjQ',
44 true
45 );
46
47 $this->addLink(
19 41, 48 41,
20 'Link title: @website', 49 'Link title: @website',
21 '?WDWyig', 50 '?WDWyig',
@@ -114,8 +143,18 @@ class ReferenceLinkDB
114 /** 143 /**
115 * Adds a new link 144 * Adds a new link
116 */ 145 */
117 protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '') 146 protected function addLink(
118 { 147 $id,
148 $title,
149 $url,
150 $description,
151 $private,
152 $date,
153 $tags,
154 $updated = '',
155 $shorturl = '',
156 $pinned = false
157 ) {
119 $link = array( 158 $link = array(
120 'id' => $id, 159 'id' => $id,
121 'title' => $title, 160 'title' => $title,
@@ -126,6 +165,7 @@ class ReferenceLinkDB
126 'created' => $date, 165 'created' => $date,
127 'updated' => $updated, 166 'updated' => $updated,
128 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), 167 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id),
168 'sticky' => $pinned
129 ); 169 );
130 $this->_links[$id] = $link; 170 $this->_links[$id] = $link;
131 171
@@ -164,7 +204,11 @@ class ReferenceLinkDB
164 204
165 $order = $order === 'ASC' ? -1 : 1; 205 $order = $order === 'ASC' ? -1 : 1;
166 // Reorder array by dates. 206 // Reorder array by dates.
167 usort($this->_links, function($a, $b) use ($order) { 207 usort($this->_links, function ($a, $b) use ($order) {
208 if (isset($a['sticky']) && isset($b['sticky']) && $a['sticky'] !== $b['sticky']) {
209 return $a['sticky'] ? -1 : 1;
210 }
211
168 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; 212 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
169 }); 213 });
170 } 214 }
diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php
index 9c9288f3..1549ddfc 100644
--- a/tests/utils/config/configJson.json.php
+++ b/tests/utils/config/configJson.json.php
@@ -1,35 +1,84 @@
1<?php /* 1<?php /*
2{ 2{
3 "credentials": { 3 "credentials": {
4 "login":"root", 4 "login": "root",
5 "hash":"hash", 5 "hash": "hash",
6 "salt":"salt" 6 "salt": "salt"
7 }, 7 },
8 "security": { 8 "security": {
9 "session_protection_disabled":false 9 "session_protection_disabled": false,
10 "ban_after": 4,
11 "ban_duration": 1800,
12 "open_shaarli": false,
13 "allowed_protocols": [
14 "ftp",
15 "ftps",
16 "magnet"
17 ]
10 }, 18 },
11 "general": { 19 "general": {
12 "timezone":"Europe\/Paris", 20 "timezone": "Europe\/Paris",
13 "title": "Shaarli", 21 "title": "Shaarli",
14 "header_link": "?" 22 "header_link": "?",
23 "links_per_page": 20,
24 "enabled_plugins": [
25 "qrcode"
26 ],
27 "default_note_title": "Note: "
15 }, 28 },
16 "privacy": { 29 "privacy": {
17 "default_private_links":true 30 "default_private_links": true,
31 "hide_public_links": false,
32 "force_login": false,
33 "hide_timestamps": false,
34 "remember_user_default": true
18 }, 35 },
19 "redirector": { 36 "redirector": {
20 "url":"lala" 37 "url": "lala",
38 "encode_url": true
21 }, 39 },
22 "config": { 40 "config": {
23 "foo": "bar" 41 "foo": "bar"
24 }, 42 },
25 "resource": { 43 "resource": {
26 "datastore": "tests\/utils\/config\/datastore.php", 44 "datastore": "tests\/utils\/config\/datastore.php",
27 "data_dir": "sandbox/", 45 "data_dir": "sandbox\/",
28 "raintpl_tpl": "tpl/" 46 "raintpl_tpl": "tpl\/",
47 "config": "data\/config.php",
48 "ban_file": "data\/ipbans.php",
49 "updates": "data\/updates.txt",
50 "log": "data\/log.txt",
51 "update_check": "data\/lastupdatecheck.txt",
52 "history": "data\/history.php",
53 "theme": "default",
54 "raintpl_tmp": "tmp\/",
55 "thumbnails_cache": "cache",
56 "page_cache": "pagecache"
29 }, 57 },
30 "plugins": { 58 "plugins": {
31 "WALLABAG_VERSION": 1 59 "WALLABAG_VERSION": 1
60 },
61 "dev": {
62 "debug": true
63 },
64 "updates": {
65 "check_updates": false,
66 "check_updates_branch": "stable",
67 "check_updates_interval": 86400
68 },
69 "feed": {
70 "rss_permalinks": true,
71 "show_atom": true
72 },
73 "translation": {
74 "language": "auto",
75 "mode": "php",
76 "extensions": []
77 },
78 "thumbnails": {
79 "mode": "common",
80 "width": 90,
81 "height": 53
32 } 82 }
33} 83}
34*/ ?> 84*/ ?>
35
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php
index 0e034175..7dc81e22 100644
--- a/tests/utils/config/configPhp.php
+++ b/tests/utils/config/configPhp.php
@@ -1,4 +1,4 @@
1<?php 1<?php
2$GLOBALS['login'] = 'root'; 2$GLOBALS['login'] = 'root';
3$GLOBALS['hash'] = 'hash'; 3$GLOBALS['hash'] = 'hash';
4$GLOBALS['salt'] = 'salt'; 4$GLOBALS['salt'] = 'salt';
@@ -8,7 +8,7 @@ $GLOBALS['titleLink'] = 'titleLink';
8$GLOBALS['redirector'] = 'lala'; 8$GLOBALS['redirector'] = 'lala';
9$GLOBALS['disablesessionprotection'] = false; 9$GLOBALS['disablesessionprotection'] = false;
10$GLOBALS['privateLinkByDefault'] = false; 10$GLOBALS['privateLinkByDefault'] = false;
11$GLOBALS['config']['DATADIR'] = 'tests/Updater'; 11$GLOBALS['config']['DATADIR'] = 'tests/updater';
12$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache'; 12$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
13$GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; 13$GLOBALS['config']['DATASTORE'] = 'data/datastore.php';
14$GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; 14$GLOBALS['plugins']['WALLABAG_VERSION'] = '1';
diff --git a/tests/utils/config/wt.json b/tests/utils/config/wt.json
new file mode 100644
index 00000000..69ce49a6
--- /dev/null
+++ b/tests/utils/config/wt.json
@@ -0,0 +1,12 @@
1{
2 "settings": {
3 "default": {
4 "_comment": "infinite cache",
5 "cache_duration": -1,
6 "timeout": 10
7 },
8 "path": {
9 "cache": "sandbox/"
10 }
11 }
12} \ No newline at end of file