aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /tests
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php27
-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.php9
-rw-r--r--tests/TimeZoneTest.php2
-rw-r--r--tests/UtilsTest.php2
-rw-r--r--tests/api/ApiMiddlewareTest.php3
-rw-r--r--tests/api/ApiUtilsTest.php4
-rw-r--r--tests/api/controllers/history/HistoryTest.php28
-rw-r--r--tests/api/controllers/info/InfoTest.php5
-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.php10
-rw-r--r--tests/api/controllers/links/PostLinkTest.php19
-rw-r--r--tests/api/controllers/links/PutLinkTest.php17
-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.php17
-rw-r--r--tests/bookmark/LinkDBTest.php (renamed from tests/LinkDBTest.php)33
-rw-r--r--tests/bookmark/LinkFilterTest.php (renamed from tests/LinkFilterTest.php)23
-rw-r--r--tests/bookmark/LinkUtilsTest.php (renamed from tests/LinkUtilsTest.php)142
-rw-r--r--tests/config/ConfigJsonTest.php6
-rw-r--r--tests/config/ConfigManagerTest.php2
-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)23
-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)11
-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)6
-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)24
-rw-r--r--tests/http/UrlUtils/CleanupUrlTest.php (renamed from tests/Url/CleanupUrlTest.php)6
-rw-r--r--tests/http/UrlUtils/GetUrlSchemeTest.php (renamed from tests/Url/GetUrlSchemeTest.php)10
-rw-r--r--tests/http/UrlUtils/UnparseUrlTest.php (renamed from tests/Url/UnparseUrlTest.php)8
-rw-r--r--tests/http/UrlUtils/WhitelistProtocolsTest.php (renamed from tests/Url/WhitelistProtocolsTest.php)8
-rw-r--r--tests/languages/fr/LanguagesFrTest.php2
-rw-r--r--tests/netscape/BookmarkExportTest.php (renamed from tests/NetscapeBookmarkUtils/BookmarkExportTest.php)11
-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.php7
-rw-r--r--tests/plugins/PluginMarkdownTest.php6
-rw-r--r--tests/plugins/PluginPlayvideosTest.php7
-rw-r--r--tests/plugins/PluginPubsubhubbubTest.php7
-rw-r--r--tests/plugins/PluginQrcodeTest.php8
-rw-r--r--tests/plugins/PluginWallabagTest.php9
-rw-r--r--tests/plugins/WallabagInstanceTest.php5
-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.php4
-rw-r--r--tests/updater/DummyUpdater.php (renamed from tests/Updater/DummyUpdater.php)9
-rw-r--r--tests/updater/UpdaterTest.php (renamed from tests/Updater/UpdaterTest.php)31
-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.php3
-rw-r--r--tests/utils/config/configPhp.php2
72 files changed, 464 insertions, 381 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index fe5f84ce..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';
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 abf1bd5f..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.
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 d0abd996..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';
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 df4e189a..ea0ae500 100644
--- a/tests/api/ApiUtilsTest.php
+++ b/tests/api/ApiUtilsTest.php
@@ -2,12 +2,12 @@
2 2
3namespace Shaarli\Api; 3namespace Shaarli\Api;
4 4
5use Shaarli\Base64Url; 5use Shaarli\Http\Base64Url;
6 6
7/** 7/**
8 * Class ApiUtilsTest 8 * Class ApiUtilsTest
9 */ 9 */
10class ApiUtilsTest extends \PHPUnit_Framework_TestCase 10class ApiUtilsTest extends \PHPUnit\Framework\TestCase
11{ 11{
12 /** 12 /**
13 * Force the timezone for ISO datetimes. 13 * Force the timezone for ISO datetimes.
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php
index ff34e16d..e287f239 100644
--- a/tests/api/controllers/history/HistoryTest.php
+++ b/tests/api/controllers/history/HistoryTest.php
@@ -1,9 +1,9 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6use Shaarli\Config\ConfigManager; 5use Shaarli\Config\ConfigManager;
6use Shaarli\History;
7use Slim\Container; 7use Slim\Container;
8use Slim\Http\Environment; 8use Slim\Http\Environment;
9use Slim\Http\Request; 9use Slim\Http\Request;
@@ -11,7 +11,7 @@ use Slim\Http\Response;
11 11
12require_once 'tests/utils/ReferenceHistory.php'; 12require_once 'tests/utils/ReferenceHistory.php';
13 13
14class HistoryTest extends \PHPUnit_Framework_TestCase 14class HistoryTest 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 HistoryTest extends \PHPUnit_Framework_TestCase
34 protected $container; 34 protected $container;
35 35
36 /** 36 /**
37 * @var History controller instance. 37 * @var HistoryController controller instance.
38 */ 38 */
39 protected $controller; 39 protected $controller;
40 40
@@ -49,9 +49,9 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
49 $this->container = new Container(); 49 $this->container = new Container();
50 $this->container['conf'] = $this->conf; 50 $this->container['conf'] = $this->conf;
51 $this->container['db'] = true; 51 $this->container['db'] = true;
52 $this->container['history'] = new \History(self::$testHistory); 52 $this->container['history'] = new History(self::$testHistory);
53 53
54 $this->controller = new History($this->container); 54 $this->controller = new HistoryController($this->container);
55 } 55 }
56 56
57 /** 57 /**
@@ -78,35 +78,35 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
78 78
79 $this->assertEquals($this->refHistory->count(), count($data)); 79 $this->assertEquals($this->refHistory->count(), count($data));
80 80
81 $this->assertEquals(\History::DELETED, $data[0]['event']); 81 $this->assertEquals(History::DELETED, $data[0]['event']);
82 $this->assertEquals( 82 $this->assertEquals(
83 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 83 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
84 $data[0]['datetime'] 84 $data[0]['datetime']
85 ); 85 );
86 $this->assertEquals(124, $data[0]['id']); 86 $this->assertEquals(124, $data[0]['id']);
87 87
88 $this->assertEquals(\History::SETTINGS, $data[1]['event']); 88 $this->assertEquals(History::SETTINGS, $data[1]['event']);
89 $this->assertEquals( 89 $this->assertEquals(
90 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 90 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
91 $data[1]['datetime'] 91 $data[1]['datetime']
92 ); 92 );
93 $this->assertNull($data[1]['id']); 93 $this->assertNull($data[1]['id']);
94 94
95 $this->assertEquals(\History::UPDATED, $data[2]['event']); 95 $this->assertEquals(History::UPDATED, $data[2]['event']);
96 $this->assertEquals( 96 $this->assertEquals(
97 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), 97 \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM),
98 $data[2]['datetime'] 98 $data[2]['datetime']
99 ); 99 );
100 $this->assertEquals(123, $data[2]['id']); 100 $this->assertEquals(123, $data[2]['id']);
101 101
102 $this->assertEquals(\History::CREATED, $data[3]['event']); 102 $this->assertEquals(History::CREATED, $data[3]['event']);
103 $this->assertEquals( 103 $this->assertEquals(
104 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), 104 \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM),
105 $data[3]['datetime'] 105 $data[3]['datetime']
106 ); 106 );
107 $this->assertEquals(124, $data[3]['id']); 107 $this->assertEquals(124, $data[3]['id']);
108 108
109 $this->assertEquals(\History::CREATED, $data[4]['event']); 109 $this->assertEquals(History::CREATED, $data[4]['event']);
110 $this->assertEquals( 110 $this->assertEquals(
111 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 111 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
112 $data[4]['datetime'] 112 $data[4]['datetime']
@@ -131,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
131 131
132 $this->assertEquals(1, count($data)); 132 $this->assertEquals(1, count($data));
133 133
134 $this->assertEquals(\History::DELETED, $data[0]['event']); 134 $this->assertEquals(History::DELETED, $data[0]['event']);
135 $this->assertEquals( 135 $this->assertEquals(
136 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 136 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
137 $data[0]['datetime'] 137 $data[0]['datetime']
@@ -156,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
156 156
157 $this->assertEquals(1, count($data)); 157 $this->assertEquals(1, count($data));
158 158
159 $this->assertEquals(\History::CREATED, $data[0]['event']); 159 $this->assertEquals(History::CREATED, $data[0]['event']);
160 $this->assertEquals( 160 $this->assertEquals(
161 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), 161 \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM),
162 $data[0]['datetime'] 162 $data[0]['datetime']
@@ -181,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
181 181
182 $this->assertEquals(1, count($data)); 182 $this->assertEquals(1, count($data));
183 183
184 $this->assertEquals(\History::DELETED, $data[0]['event']); 184 $this->assertEquals(History::DELETED, $data[0]['event']);
185 $this->assertEquals( 185 $this->assertEquals(
186 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), 186 \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM),
187 $data[0]['datetime'] 187 $data[0]['datetime']
@@ -206,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase
206 206
207 $this->assertEquals(1, count($data)); 207 $this->assertEquals(1, count($data));
208 208
209 $this->assertEquals(\History::SETTINGS, $data[0]['event']); 209 $this->assertEquals(History::SETTINGS, $data[0]['event']);
210 $this->assertEquals( 210 $this->assertEquals(
211 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), 211 \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM),
212 $data[0]['datetime'] 212 $data[0]['datetime']
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php
index e437082a..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;
@@ -15,7 +14,7 @@ use Slim\Http\Response;
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 64f02774..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);
@@ -114,7 +114,7 @@ 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']);
@@ -125,7 +125,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
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 }
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php
index 5c2b5623..d683a984 100644
--- a/tests/api/controllers/links/PostLinkTest.php
+++ b/tests/api/controllers/links/PostLinkTest.php
@@ -4,6 +4,7 @@ namespace Shaarli\Api\Controllers;
4 4
5use PHPUnit\Framework\TestCase; 5use PHPUnit\Framework\TestCase;
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
@@ -40,7 +41,7 @@ class PostLinkTest extends TestCase
40 protected $refDB = null; 41 protected $refDB = null;
41 42
42 /** 43 /**
43 * @var \History instance. 44 * @var HistoryController instance.
44 */ 45 */
45 protected $history; 46 protected $history;
46 47
@@ -70,12 +71,12 @@ class PostLinkTest extends TestCase
70 71
71 $refHistory = new \ReferenceHistory(); 72 $refHistory = new \ReferenceHistory();
72 $refHistory->write(self::$testHistory); 73 $refHistory->write(self::$testHistory);
73 $this->history = new \History(self::$testHistory); 74 $this->history = new History(self::$testHistory);
74 75
75 $this->container = new Container(); 76 $this->container = new Container();
76 $this->container['conf'] = $this->conf; 77 $this->container['conf'] = $this->conf;
77 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 78 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
78 $this->container['history'] = new \History(self::$testHistory); 79 $this->container['history'] = new History(self::$testHistory);
79 80
80 $this->controller = new Links($this->container); 81 $this->controller = new Links($this->container);
81 82
@@ -121,7 +122,7 @@ class PostLinkTest extends TestCase
121 $data = json_decode((string) $response->getBody(), true); 122 $data = json_decode((string) $response->getBody(), true);
122 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 123 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
123 $this->assertEquals(43, $data['id']); 124 $this->assertEquals(43, $data['id']);
124 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 125 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
125 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); 126 $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']);
126 $this->assertEquals('?' . $data['shorturl'], $data['title']); 127 $this->assertEquals('?' . $data['shorturl'], $data['title']);
127 $this->assertEquals('', $data['description']); 128 $this->assertEquals('', $data['description']);
@@ -133,7 +134,7 @@ class PostLinkTest extends TestCase
133 $this->assertEquals('', $data['updated']); 134 $this->assertEquals('', $data['updated']);
134 135
135 $historyEntry = $this->history->getHistory()[0]; 136 $historyEntry = $this->history->getHistory()[0];
136 $this->assertEquals(\History::CREATED, $historyEntry['event']); 137 $this->assertEquals(History::CREATED, $historyEntry['event']);
137 $this->assertTrue( 138 $this->assertTrue(
138 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 139 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
139 ); 140 );
@@ -166,7 +167,7 @@ class PostLinkTest extends TestCase
166 $data = json_decode((string) $response->getBody(), true); 167 $data = json_decode((string) $response->getBody(), true);
167 $this->assertEquals(self::NB_FIELDS_LINK, count($data)); 168 $this->assertEquals(self::NB_FIELDS_LINK, count($data));
168 $this->assertEquals(43, $data['id']); 169 $this->assertEquals(43, $data['id']);
169 $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); 170 $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']);
170 $this->assertEquals('http://' . $link['url'], $data['url']); 171 $this->assertEquals('http://' . $link['url'], $data['url']);
171 $this->assertEquals($link['title'], $data['title']); 172 $this->assertEquals($link['title'], $data['title']);
172 $this->assertEquals($link['description'], $data['description']); 173 $this->assertEquals($link['description'], $data['description']);
@@ -210,11 +211,11 @@ class PostLinkTest extends TestCase
210 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 211 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
211 $this->assertEquals(false, $data['private']); 212 $this->assertEquals(false, $data['private']);
212 $this->assertEquals( 213 $this->assertEquals(
213 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 214 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
214 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 215 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
215 ); 216 );
216 $this->assertEquals( 217 $this->assertEquals(
217 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 218 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
218 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 219 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
219 ); 220 );
220 } 221 }
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php
index f276b4c1..cd815b66 100644
--- a/tests/api/controllers/links/PutLinkTest.php
+++ b/tests/api/controllers/links/PutLinkTest.php
@@ -4,12 +4,13 @@
4namespace Shaarli\Api\Controllers; 4namespace Shaarli\Api\Controllers;
5 5
6use Shaarli\Config\ConfigManager; 6use Shaarli\Config\ConfigManager;
7use Shaarli\History;
7use Slim\Container; 8use Slim\Container;
8use Slim\Http\Environment; 9use Slim\Http\Environment;
9use Slim\Http\Request; 10use Slim\Http\Request;
10use Slim\Http\Response; 11use Slim\Http\Response;
11 12
12class PutLinkTest extends \PHPUnit_Framework_TestCase 13class PutLinkTest extends \PHPUnit\Framework\TestCase
13{ 14{
14 /** 15 /**
15 * @var string datastore to test write operations 16 * @var string datastore to test write operations
@@ -32,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
32 protected $refDB = null; 33 protected $refDB = null;
33 34
34 /** 35 /**
35 * @var \History instance. 36 * @var HistoryController instance.
36 */ 37 */
37 protected $history; 38 protected $history;
38 39
@@ -62,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
62 63
63 $refHistory = new \ReferenceHistory(); 64 $refHistory = new \ReferenceHistory();
64 $refHistory->write(self::$testHistory); 65 $refHistory->write(self::$testHistory);
65 $this->history = new \History(self::$testHistory); 66 $this->history = new History(self::$testHistory);
66 67
67 $this->container = new Container(); 68 $this->container = new Container();
68 $this->container['conf'] = $this->conf; 69 $this->container['conf'] = $this->conf;
69 $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); 70 $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false);
70 $this->container['history'] = new \History(self::$testHistory); 71 $this->container['history'] = new History(self::$testHistory);
71 72
72 $this->controller = new Links($this->container); 73 $this->controller = new Links($this->container);
73 74
@@ -119,7 +120,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
119 ); 120 );
120 121
121 $historyEntry = $this->history->getHistory()[0]; 122 $historyEntry = $this->history->getHistory()[0];
122 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 123 $this->assertEquals(History::UPDATED, $historyEntry['event']);
123 $this->assertTrue( 124 $this->assertTrue(
124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 125 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
125 ); 126 );
@@ -198,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase
198 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); 199 $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']);
199 $this->assertEquals(false, $data['private']); 200 $this->assertEquals(false, $data['private']);
200 $this->assertEquals( 201 $this->assertEquals(
201 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 202 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
202 \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) 203 \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])
203 ); 204 );
204 $this->assertEquals( 205 $this->assertEquals(
205 \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), 206 \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
206 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) 207 \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])
207 ); 208 );
208 } 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 38017243..86106fc7 100644
--- a/tests/api/controllers/tags/PutTagTest.php
+++ b/tests/api/controllers/tags/PutTagTest.php
@@ -1,16 +1,17 @@
1<?php 1<?php
2 2
3
4namespace Shaarli\Api\Controllers; 3namespace Shaarli\Api\Controllers;
5 4
6use Shaarli\Api\Exceptions\ApiBadParametersException; 5use Shaarli\Api\Exceptions\ApiBadParametersException;
6use Shaarli\Bookmark\LinkDB;
7use Shaarli\Config\ConfigManager; 7use Shaarli\Config\ConfigManager;
8use Shaarli\History;
8use Slim\Container; 9use Slim\Container;
9use Slim\Http\Environment; 10use Slim\Http\Environment;
10use Slim\Http\Request; 11use Slim\Http\Request;
11use Slim\Http\Response; 12use Slim\Http\Response;
12 13
13class PutTagTest extends \PHPUnit_Framework_TestCase 14class PutTagTest extends \PHPUnit\Framework\TestCase
14{ 15{
15 /** 16 /**
16 * @var string datastore to test write operations 17 * @var string datastore to test write operations
@@ -33,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
33 protected $refDB = null; 34 protected $refDB = null;
34 35
35 /** 36 /**
36 * @var \History instance. 37 * @var HistoryController instance.
37 */ 38 */
38 protected $history; 39 protected $history;
39 40
@@ -43,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
43 protected $container; 44 protected $container;
44 45
45 /** 46 /**
46 * @var \LinkDB instance. 47 * @var LinkDB instance.
47 */ 48 */
48 protected $linkDB; 49 protected $linkDB;
49 50
@@ -68,11 +69,11 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
68 69
69 $refHistory = new \ReferenceHistory(); 70 $refHistory = new \ReferenceHistory();
70 $refHistory->write(self::$testHistory); 71 $refHistory->write(self::$testHistory);
71 $this->history = new \History(self::$testHistory); 72 $this->history = new History(self::$testHistory);
72 73
73 $this->container = new Container(); 74 $this->container = new Container();
74 $this->container['conf'] = $this->conf; 75 $this->container['conf'] = $this->conf;
75 $this->linkDB = new \LinkDB(self::$testDatastore, true, false); 76 $this->linkDB = new LinkDB(self::$testDatastore, true, false);
76 $this->container['db'] = $this->linkDB; 77 $this->container['db'] = $this->linkDB;
77 $this->container['history'] = $this->history; 78 $this->container['history'] = $this->history;
78 79
@@ -113,12 +114,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase
113 $this->assertEquals(2, $tags[$newName]); 114 $this->assertEquals(2, $tags[$newName]);
114 115
115 $historyEntry = $this->history->getHistory()[0]; 116 $historyEntry = $this->history->getHistory()[0];
116 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 117 $this->assertEquals(History::UPDATED, $historyEntry['event']);
117 $this->assertTrue( 118 $this->assertTrue(
118 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 119 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
119 ); 120 );
120 $historyEntry = $this->history->getHistory()[1]; 121 $historyEntry = $this->history->getHistory()[1];
121 $this->assertEquals(\History::UPDATED, $historyEntry['event']); 122 $this->assertEquals(History::UPDATED, $historyEntry['event']);
122 $this->assertTrue( 123 $this->assertTrue(
123 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] 124 (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime']
124 ); 125 );
diff --git a/tests/LinkDBTest.php b/tests/bookmark/LinkDBTest.php
index c763c0cb..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');
@@ -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 {
diff --git a/tests/LinkFilterTest.php b/tests/bookmark/LinkFilterTest.php
index eb54c359..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 {
@@ -79,10 +82,14 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
79 count( 82 count(
80 self::$linkFilter->filter( 83 self::$linkFilter->filter(
81 LinkFilter::$FILTER_TAG, 84 LinkFilter::$FILTER_TAG,
82 /*$request=*/'', 85 /*$request=*/
83 /*$casesensitive=*/false, 86 '',
84 /*$visibility=*/'all', 87 /*$casesensitive=*/
85 /*$untaggedonly=*/true 88 false,
89 /*$visibility=*/
90 'all',
91 /*$untaggedonly=*/
92 true
86 ) 93 )
87 ) 94 )
88 ); 95 );
@@ -227,7 +234,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
227 /** 234 /**
228 * No link for this hash 235 * No link for this hash
229 * 236 *
230 * @expectedException LinkNotFoundException 237 * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException
231 */ 238 */
232 public function testFilterUnknownSmallHash() 239 public function testFilterUnknownSmallHash()
233 { 240 {
diff --git a/tests/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 5407159a..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
@@ -84,8 +88,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
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">' 90 'end' => 'th=device-width">'
87 .'<title>Refactoring · GitHub</title>' 91 . '<title>Refactoring · GitHub</title>'
88 .'<link rel="search" type="application/opensea', 92 . '<link rel="search" type="application/opensea',
89 '<title>ignored</title>', 93 '<title>ignored</title>',
90 ]; 94 ];
91 foreach ($data as $key => $line) { 95 foreach ($data as $key => $line) {
@@ -109,8 +113,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
109 $data = [ 113 $data = [
110 'HTTP/1.1 200 OK', 114 'HTTP/1.1 200 OK',
111 'end' => 'th=device-width">' 115 'end' => 'th=device-width">'
112 .'<title>Refactoring · GitHub</title>' 116 . '<title>Refactoring · GitHub</title>'
113 .'<link rel="search" type="application/opensea', 117 . '<link rel="search" type="application/opensea',
114 '<title>ignored</title>', 118 '<title>ignored</title>',
115 ]; 119 ];
116 foreach ($data as $key => $line) { 120 foreach ($data as $key => $line) {
@@ -131,8 +135,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
131 'HTTP/1.1 200 OK', 135 'HTTP/1.1 200 OK',
132 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', 136 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
133 'end' => 'th=device-width">' 137 'end' => 'th=device-width">'
134 .'<title>Refactoring · GitHub</title>' 138 . '<title>Refactoring · GitHub</title>'
135 .'<link rel="search" type="application/opensea', 139 . '<link rel="search" type="application/opensea',
136 '<title>ignored</title>', 140 '<title>ignored</title>',
137 ]; 141 ];
138 foreach ($data as $key => $line) { 142 foreach ($data as $key => $line) {
@@ -218,19 +222,19 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
218 { 222 {
219 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 223 $text = 'stuff http://hello.there/is=someone#here otherstuff';
220 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' 224 $expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
221 .'http://hello.there/is=someone#here</a> otherstuff'; 225 . 'http://hello.there/is=someone#here</a> otherstuff';
222 $processedText = text2clickable($text, ''); 226 $processedText = text2clickable($text, '');
223 $this->assertEquals($expectedText, $processedText); 227 $this->assertEquals($expectedText, $processedText);
224 228
225 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; 229 $text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
226 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' 230 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
227 .'http://hello.there/is=someone#here(please)</a> otherstuff'; 231 . 'http://hello.there/is=someone#here(please)</a> otherstuff';
228 $processedText = text2clickable($text, ''); 232 $processedText = text2clickable($text, '');
229 $this->assertEquals($expectedText, $processedText); 233 $this->assertEquals($expectedText, $processedText);
230 234
231 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; 235 $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
232 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' 236 $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
233 .'http://hello.there/is=someone#here(please)&no</a> otherstuff'; 237 . 'http://hello.there/is=someone#here(please)&no</a> otherstuff';
234 $processedText = text2clickable($text, ''); 238 $processedText = text2clickable($text, '');
235 $this->assertEquals($expectedText, $processedText); 239 $this->assertEquals($expectedText, $processedText);
236 } 240 }
@@ -242,7 +246,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
242 { 246 {
243 $text = 'stuff http://hello.there/is=someone#here otherstuff'; 247 $text = 'stuff http://hello.there/is=someone#here otherstuff';
244 $redirector = 'http://redirector.to'; 248 $redirector = 'http://redirector.to';
245 $expectedText = 'stuff <a href="'. 249 $expectedText = 'stuff <a href="' .
246 $redirector . 250 $redirector .
247 urlencode('http://hello.there/is=someone#here') . 251 urlencode('http://hello.there/is=someone#here') .
248 '">http://hello.there/is=someone#here</a> otherstuff'; 252 '">http://hello.there/is=someone#here</a> otherstuff';
@@ -257,7 +261,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
257 { 261 {
258 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; 262 $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff';
259 $redirector = 'http://redirector.to'; 263 $redirector = 'http://redirector.to';
260 $expectedText = 'stuff <a href="'. 264 $expectedText = 'stuff <a href="' .
261 $redirector . 265 $redirector .
262 'http://hello.there/?is=someone&or=something#here' . 266 'http://hello.there/?is=someone&or=something#here' .
263 '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; 267 '">http://hello.there/?is=someone&or=something#here</a> otherstuff';
@@ -270,8 +274,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
270 */ 274 */
271 public function testSpace2nbsp() 275 public function testSpace2nbsp()
272 { 276 {
273 $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; 277 $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?';
274 $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?';
275 $processedText = space2nbsp($text); 279 $processedText = space2nbsp($text);
276 $this->assertEquals($expectedText, $processedText); 280 $this->assertEquals($expectedText, $processedText);
277 } 281 }
@@ -317,105 +321,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase
317 * Util function to build an hashtag link. 321 * Util function to build an hashtag link.
318 * 322 *
319 * @param string $hashtag Hashtag name. 323 * @param string $hashtag Hashtag name.
320 * @param string $index Index URL. 324 * @param string $index Index URL.
321 * 325 *
322 * @return string HTML hashtag link. 326 * @return string HTML hashtag link.
323 */ 327 */
324 private function getHashtagLink($hashtag, $index = '') 328 private function getHashtagLink($hashtag, $index = '')
325 { 329 {
326 $hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>'; 330 $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>';
327 return str_replace('$1', $hashtag, $hashtagLink); 331 return str_replace('$1', $hashtag, $hashtagLink);
328 } 332 }
329} 333}
330
331// old style mock: PHPUnit doesn't allow function mock
332
333/**
334 * Returns code 200 or html content type.
335 *
336 * @param resource $ch cURL resource
337 * @param int $type cURL info type
338 *
339 * @return int|string 200 or 'text/html'
340 */
341function ut_curl_getinfo_ok($ch, $type)
342{
343 switch ($type) {
344 case CURLINFO_RESPONSE_CODE:
345 return 200;
346 case CURLINFO_CONTENT_TYPE:
347 return 'text/html; charset=utf-8';
348 }
349}
350
351/**
352 * Returns code 200 or html content type without charset.
353 *
354 * @param resource $ch cURL resource
355 * @param int $type cURL info type
356 *
357 * @return int|string 200 or 'text/html'
358 */
359function ut_curl_getinfo_no_charset($ch, $type)
360{
361 switch ($type) {
362 case CURLINFO_RESPONSE_CODE:
363 return 200;
364 case CURLINFO_CONTENT_TYPE:
365 return 'text/html';
366 }
367}
368
369/**
370 * Invalid response code.
371 *
372 * @param resource $ch cURL resource
373 * @param int $type cURL info type
374 *
375 * @return int|string 404 or 'text/html'
376 */
377function ut_curl_getinfo_rc_ko($ch, $type)
378{
379 switch ($type) {
380 case CURLINFO_RESPONSE_CODE:
381 return 404;
382 case CURLINFO_CONTENT_TYPE:
383 return 'text/html; charset=utf-8';
384 }
385}
386
387/**
388 * Invalid content type.
389 *
390 * @param resource $ch cURL resource
391 * @param int $type cURL info type
392 *
393 * @return int|string 200 or 'text/plain'
394 */
395function ut_curl_getinfo_ct_ko($ch, $type)
396{
397 switch ($type) {
398 case CURLINFO_RESPONSE_CODE:
399 return 200;
400 case CURLINFO_CONTENT_TYPE:
401 return 'text/plain';
402 }
403}
404
405/**
406 * Invalid response code and content type.
407 *
408 * @param resource $ch cURL resource
409 * @param int $type cURL info type
410 *
411 * @return int|string 404 or 'text/plain'
412 */
413function ut_curl_getinfo_rs_ct_ko($ch, $type)
414{
415 switch ($type) {
416 case CURLINFO_RESPONSE_CODE:
417 return 404;
418 case CURLINFO_CONTENT_TYPE:
419 return 'text/plain';
420 }
421}
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 4a4e94ac..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
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 f60fad91..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,7 +84,7 @@ 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);
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 4ca58e5a..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).
@@ -90,7 +93,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
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']);
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 7af5bd9d..fe3a639e 100644
--- a/tests/HttpUtils/GetIpAdressFromProxyTest.php
+++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php
@@ -1,11 +1,13 @@
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
9{ 11{
10 12
11 /** 13 /**
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 db229ce0..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';
@@ -18,7 +18,7 @@ class UrlTest extends PHPUnit_Framework_TestCase
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,26 +115,26 @@ 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 } 138 }
139 139
140 /** 140 /**
diff --git a/tests/Url/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php
index 24791948..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
diff --git a/tests/Url/GetUrlSchemeTest.php b/tests/http/UrlUtils/GetUrlSchemeTest.php
index 18b932d6..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 {
diff --git a/tests/Url/UnparseUrlTest.php b/tests/http/UrlUtils/UnparseUrlTest.php
index e314b484..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
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/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
index 38347de1..b8b7ca3a 100644
--- a/tests/languages/fr/LanguagesFrTest.php
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -12,7 +12,7 @@ use Shaarli\Config\ConfigManager;
12 * 12 *
13 * @package Shaarli 13 * @package Shaarli
14 */ 14 */
15class LanguagesFrTest extends \PHPUnit_Framework_TestCase 15class LanguagesFrTest extends \PHPUnit\Framework\TestCase
16{ 16{
17 /** 17 /**
18 * @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 77fbd5f3..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 }
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 2c9efbcd..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
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index 44364b05..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.
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 dd632eee..0c61e14a 100644
--- a/tests/plugins/PluginQrcodeTest.php
+++ b/tests/plugins/PluginQrcodeTest.php
@@ -1,16 +1,20 @@
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
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/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 f26cd1eb..de8055ed 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 7961e771..f264505e 100644
--- a/tests/security/SessionManagerTest.php
+++ b/tests/security/SessionManagerTest.php
@@ -5,8 +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 10
11/** 11/**
12 * Test coverage for SessionManager 12 * Test coverage for SessionManager
diff --git a/tests/Updater/DummyUpdater.php b/tests/updater/DummyUpdater.php
index a805ab5e..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{
diff --git a/tests/Updater/UpdaterTest.php b/tests/updater/UpdaterTest.php
index c4a6e7ef..d7df5963 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/updater/UpdaterTest.php
@@ -1,17 +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;
5use Shaarli\Thumbnailer; 10use Shaarli\Thumbnailer;
6 11
7require_once 'tests/Updater/DummyUpdater.php'; 12require_once 'application/updater/UpdaterUtils.php';
13require_once 'tests/updater/DummyUpdater.php';
14require_once 'tests/utils/ReferenceLinkDB.php';
8require_once 'inc/rain.tpl.class.php'; 15require_once 'inc/rain.tpl.class.php';
9 16
10/** 17/**
11 * Class UpdaterTest. 18 * Class UpdaterTest.
12 * Runs unit tests against the Updater class. 19 * Runs unit tests against the updater class.
13 */ 20 */
14class UpdaterTest extends PHPUnit_Framework_TestCase 21class UpdaterTest extends \PHPUnit\Framework\TestCase
15{ 22{
16 /** 23 /**
17 * @var string Path to test datastore. 24 * @var string Path to test datastore.
@@ -153,7 +160,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
153 /** 160 /**
154 * Test Update failed. 161 * Test Update failed.
155 * 162 *
156 * @expectedException UpdaterException 163 * @expectedException \Exception
157 */ 164 */
158 public function testUpdateFailed() 165 public function testUpdateFailed()
159 { 166 {
@@ -179,17 +186,17 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
179 $this->conf->setConfigFile('tests/utils/config/configPhp'); 186 $this->conf->setConfigFile('tests/utils/config/configPhp');
180 $this->conf->reset(); 187 $this->conf->reset();
181 188
182 $optionsFile = 'tests/Updater/options.php'; 189 $optionsFile = 'tests/updater/options.php';
183 $options = '<?php 190 $options = '<?php
184$GLOBALS[\'privateLinkByDefault\'] = true;'; 191$GLOBALS[\'privateLinkByDefault\'] = true;';
185 file_put_contents($optionsFile, $options); 192 file_put_contents($optionsFile, $options);
186 193
187 // tmp config file. 194 // tmp config file.
188 $this->conf->setConfigFile('tests/Updater/config'); 195 $this->conf->setConfigFile('tests/updater/config');
189 196
190 // merge configs 197 // merge configs
191 $updater = new Updater(array(), array(), $this->conf, true); 198 $updater = new Updater(array(), array(), $this->conf, true);
192 // This writes a new config file in tests/Updater/config.php 199 // This writes a new config file in tests/updater/config.php
193 $updater->updateMethodMergeDeprecatedConfigFile(); 200 $updater->updateMethodMergeDeprecatedConfigFile();
194 201
195 // make sure updated field is changed 202 // make sure updated field is changed
@@ -216,7 +223,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
216 */ 223 */
217 public function testRenameDashTags() 224 public function testRenameDashTags()
218 { 225 {
219 $refDB = new ReferenceLinkDB(); 226 $refDB = new \ReferenceLinkDB();
220 $refDB->write(self::$testDatastore); 227 $refDB->write(self::$testDatastore);
221 $linkDB = new LinkDB(self::$testDatastore, true, false); 228 $linkDB = new LinkDB(self::$testDatastore, true, false);
222 229
@@ -362,7 +369,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
362 'private' => true, 369 'private' => true,
363 ), 370 ),
364 ); 371 );
365 $refDB = new ReferenceLinkDB(); 372 $refDB = new \ReferenceLinkDB();
366 $refDB->setLinks($links); 373 $refDB->setLinks($links);
367 $refDB->write(self::$testDatastore); 374 $refDB->write(self::$testDatastore);
368 $linkDB = new LinkDB(self::$testDatastore, true, false); 375 $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -426,7 +433,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
426 */ 433 */
427 public function testDatastoreIdsNothingToDo() 434 public function testDatastoreIdsNothingToDo()
428 { 435 {
429 $refDB = new ReferenceLinkDB(); 436 $refDB = new \ReferenceLinkDB();
430 $refDB->write(self::$testDatastore); 437 $refDB->write(self::$testDatastore);
431 $linkDB = new LinkDB(self::$testDatastore, true, false); 438 $linkDB = new LinkDB(self::$testDatastore, true, false);
432 439
@@ -763,7 +770,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
763 1 => ['id' => 1] + $blank, 770 1 => ['id' => 1] + $blank,
764 2 => ['id' => 2] + $blank, 771 2 => ['id' => 2] + $blank,
765 ]; 772 ];
766 $refDB = new ReferenceLinkDB(); 773 $refDB = new \ReferenceLinkDB();
767 $refDB->setLinks($links); 774 $refDB->setLinks($links);
768 $refDB->write(self::$testDatastore); 775 $refDB->write(self::$testDatastore);
769 $linkDB = new LinkDB(self::$testDatastore, true, false); 776 $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -794,7 +801,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
794 1 => ['id' => 1, 'sticky' => true] + $blank, 801 1 => ['id' => 1, 'sticky' => true] + $blank,
795 2 => ['id' => 2] + $blank, 802 2 => ['id' => 2] + $blank,
796 ]; 803 ];
797 $refDB = new ReferenceLinkDB(); 804 $refDB = new \ReferenceLinkDB();
798 $refDB->setLinks($links); 805 $refDB->setLinks($links);
799 $refDB->write(self::$testDatastore); 806 $refDB->write(self::$testDatastore);
800 $linkDB = new LinkDB(self::$testDatastore, true, false); 807 $linkDB = new LinkDB(self::$testDatastore, true, false);
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 59679e38..c12bcb67 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -1,4 +1,7 @@
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 */
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php
index 34b11fcd..7dc81e22 100644
--- a/tests/utils/config/configPhp.php
+++ b/tests/utils/config/configPhp.php
@@ -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';