diff options
Diffstat (limited to 'tests')
74 files changed, 1303 insertions, 554 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 |
2 | use Shaarli\Config\ConfigManager; | 2 | namespace Shaarli; |
3 | |||
4 | /** | ||
5 | * ApplicationUtils' tests | ||
6 | */ | ||
7 | 3 | ||
8 | require_once 'application/ApplicationUtils.php'; | 4 | use Shaarli\Config\ConfigManager; |
9 | |||
10 | /** | ||
11 | * Fake ApplicationUtils class to avoid HTTP requests | ||
12 | */ | ||
13 | class 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 | ||
6 | require_once 'tests/utils/FakeApplicationUtils.php'; | ||
26 | 7 | ||
27 | /** | 8 | /** |
28 | * Unitary tests for Shaarli utilities | 9 | * Unitary tests for Shaarli utilities |
29 | */ | 10 | */ |
30 | class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | 11 | class 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 | ||
3 | require_once 'application/FileUtils.php'; | 3 | namespace Shaarli; |
4 | |||
5 | use 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 | */ |
10 | class FileUtilsTest extends PHPUnit_Framework_TestCase | 12 | class 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 | ||
3 | require_once 'application/History.php'; | 3 | namespace Shaarli; |
4 | 4 | ||
5 | use DateTime; | ||
6 | use Exception; | ||
5 | 7 | ||
6 | class HistoryTest extends PHPUnit_Framework_TestCase | 8 | class 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 | */ |
10 | class LanguagesTest extends \PHPUnit_Framework_TestCase | 10 | class 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 |
2 | use Shaarli\Config\ConfigManager; | 2 | namespace Shaarli\Plugin; |
3 | 3 | ||
4 | /** | 4 | use Shaarli\Config\ConfigManager; |
5 | * Plugin Manager tests | ||
6 | */ | ||
7 | |||
8 | require_once 'application/PluginManager.php'; | ||
9 | 5 | ||
10 | /** | 6 | /** |
11 | * Unit tests for Plugins | 7 | * Unit tests for Plugins |
12 | */ | 8 | */ |
13 | class PluginManagerTest extends PHPUnit_Framework_TestCase | 9 | class 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 | 2 | namespace Shaarli; | |
3 | /** | ||
4 | * Router tests | ||
5 | */ | ||
6 | |||
7 | require_once 'application/Router.php'; | ||
8 | 3 | ||
9 | /** | 4 | /** |
10 | * Unit tests for Router | 5 | * Unit tests for Router |
11 | */ | 6 | */ |
12 | class RouterTest extends PHPUnit_Framework_TestCase | 7 | class 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 | */ |
11 | class TimeZoneTest extends PHPUnit_Framework_TestCase | 11 | class 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 | */ |
13 | class UtilsTest extends PHPUnit_Framework_TestCase | 13 | class 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 @@ | |||
2 | namespace Shaarli\Api; | 2 | namespace Shaarli\Api; |
3 | 3 | ||
4 | use Shaarli\Config\ConfigManager; | 4 | use Shaarli\Config\ConfigManager; |
5 | |||
6 | use Slim\Container; | 5 | use Slim\Container; |
7 | use Slim\Http\Environment; | 6 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 7 | use Slim\Http\Request; |
@@ -18,7 +17,7 @@ use Slim\Http\Response; | |||
18 | * | 17 | * |
19 | * @package Api | 18 | * @package Api |
20 | */ | 19 | */ |
21 | class ApiMiddlewareTest extends \PHPUnit_Framework_TestCase | 20 | class 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 | ||
3 | namespace Shaarli\Api; | 3 | namespace Shaarli\Api; |
4 | 4 | ||
5 | use Shaarli\Base64Url; | 5 | use Shaarli\Http\Base64Url; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Class ApiUtilsTest | 8 | * Class ApiUtilsTest |
9 | */ | 9 | */ |
10 | class ApiUtilsTest extends \PHPUnit_Framework_TestCase | 10 | class 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 | |||
4 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
5 | 4 | ||
6 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
6 | use Shaarli\History; | ||
7 | use Slim\Container; | 7 | use Slim\Container; |
8 | use Slim\Http\Environment; | 8 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 9 | use Slim\Http\Request; |
@@ -11,7 +11,7 @@ use Slim\Http\Response; | |||
11 | 11 | ||
12 | require_once 'tests/utils/ReferenceHistory.php'; | 12 | require_once 'tests/utils/ReferenceHistory.php'; |
13 | 13 | ||
14 | class HistoryTest extends \PHPUnit_Framework_TestCase | 14 | class 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 @@ | |||
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use Shaarli\Config\ConfigManager; | 4 | use Shaarli\Config\ConfigManager; |
5 | |||
6 | use Slim\Container; | 5 | use Slim\Container; |
7 | use Slim\Http\Environment; | 6 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 7 | use Slim\Http\Request; |
@@ -15,7 +14,7 @@ use Slim\Http\Response; | |||
15 | * | 14 | * |
16 | * @package Api\Controllers | 15 | * @package Api\Controllers |
17 | */ | 16 | */ |
18 | class InfoTest extends \PHPUnit_Framework_TestCase | 17 | class 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 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Bookmark\LinkDB; | ||
6 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
7 | use Slim\Container; | 9 | use Slim\Container; |
8 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
10 | use Slim\Http\Response; | 12 | use Slim\Http\Response; |
11 | 13 | ||
12 | class DeleteLinkTest extends \PHPUnit_Framework_TestCase | 14 | class 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 @@ | |||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
6 | |||
7 | use Slim\Container; | 6 | use Slim\Container; |
8 | use Slim\Http\Environment; | 7 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 8 | use 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 | */ |
21 | class GetLinkIdTest extends \PHPUnit_Framework_TestCase | 20 | class 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 |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use Shaarli\Bookmark\LinkDB; | ||
4 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
5 | |||
6 | use Slim\Container; | 6 | use Slim\Container; |
7 | use Slim\Http\Environment; | 7 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 8 | use 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 | */ |
20 | class GetLinksTest extends \PHPUnit_Framework_TestCase | 20 | class 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 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
7 | use Slim\Container; | 8 | use Slim\Container; |
8 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 10 | use 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 @@ | |||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
7 | use Slim\Container; | 8 | use Slim\Container; |
8 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
10 | use Slim\Http\Response; | 11 | use Slim\Http\Response; |
11 | 12 | ||
12 | class PutLinkTest extends \PHPUnit_Framework_TestCase | 13 | class 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 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | use Shaarli\Bookmark\LinkDB; | ||
6 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
7 | use Slim\Container; | 9 | use Slim\Container; |
8 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
10 | use Slim\Http\Response; | 12 | use Slim\Http\Response; |
11 | 13 | ||
12 | class DeleteTagTest extends \PHPUnit_Framework_TestCase | 14 | class 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 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | use Shaarli\Bookmark\LinkDB; | ||
5 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
6 | |||
7 | use Slim\Container; | 7 | use Slim\Container; |
8 | use Slim\Http\Environment; | 8 | use Slim\Http\Environment; |
9 | use Slim\Http\Request; | 9 | use 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 | */ |
19 | class GetTagNameTest extends \PHPUnit_Framework_TestCase | 19 | class 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 |
2 | namespace Shaarli\Api\Controllers; | 2 | namespace Shaarli\Api\Controllers; |
3 | 3 | ||
4 | use Shaarli\Bookmark\LinkDB; | ||
4 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
5 | |||
6 | use Slim\Container; | 6 | use Slim\Container; |
7 | use Slim\Http\Environment; | 7 | use Slim\Http\Environment; |
8 | use Slim\Http\Request; | 8 | use 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 | */ |
18 | class GetTagsTest extends \PHPUnit_Framework_TestCase | 18 | class 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 | |||
4 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
5 | 4 | ||
6 | use Shaarli\Api\Exceptions\ApiBadParametersException; | 5 | use Shaarli\Api\Exceptions\ApiBadParametersException; |
6 | use Shaarli\Bookmark\LinkDB; | ||
7 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
8 | use Slim\Container; | 9 | use Slim\Container; |
9 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
11 | use Slim\Http\Response; | 12 | use Slim\Http\Response; |
12 | 13 | ||
13 | class PutTagTest extends \PHPUnit_Framework_TestCase | 14 | class 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..2990a6b5 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 | ||
6 | require_once 'application/Cache.php'; | 6 | namespace Shaarli\Bookmark; |
7 | require_once 'application/FileUtils.php'; | 7 | |
8 | require_once 'application/LinkDB.php'; | 8 | use DateTime; |
9 | use ReferenceLinkDB; | ||
10 | use ReflectionClass; | ||
11 | use Shaarli; | ||
12 | |||
13 | require_once 'application/feed/Cache.php'; | ||
9 | require_once 'application/Utils.php'; | 14 | require_once 'application/Utils.php'; |
10 | require_once 'tests/utils/ReferenceLinkDB.php'; | 15 | require_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 | */ |
16 | class LinkDBTest extends PHPUnit_Framework_TestCase | 21 | class 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'); |
@@ -357,36 +362,6 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
357 | } | 362 | } |
358 | 363 | ||
359 | /** | 364 | /** |
360 | * Test real_url without redirector. | ||
361 | */ | ||
362 | public function testLinkRealUrlWithoutRedirector() | ||
363 | { | ||
364 | $db = new LinkDB(self::$testDatastore, false, false); | ||
365 | foreach ($db as $link) { | ||
366 | $this->assertEquals($link['url'], $link['real_url']); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | /** | ||
371 | * Test real_url with redirector. | ||
372 | */ | ||
373 | public function testLinkRealUrlWithRedirector() | ||
374 | { | ||
375 | $redirector = 'http://redirector.to?'; | ||
376 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); | ||
377 | foreach ($db as $link) { | ||
378 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
379 | $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); | ||
380 | } | ||
381 | |||
382 | $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); | ||
383 | foreach ($db as $link) { | ||
384 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
385 | $this->assertFalse(strpos($link['real_url'], urlencode('://'))); | ||
386 | } | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * Test filter with string. | 365 | * Test filter with string. |
391 | */ | 366 | */ |
392 | public function testFilterString() | 367 | public function testFilterString() |
@@ -451,7 +426,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
451 | /** | 426 | /** |
452 | * Test filterHash() with an invalid smallhash. | 427 | * Test filterHash() with an invalid smallhash. |
453 | * | 428 | * |
454 | * @expectedException LinkNotFoundException | 429 | * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException |
455 | */ | 430 | */ |
456 | public function testFilterHashInValid1() | 431 | public function testFilterHashInValid1() |
457 | { | 432 | { |
@@ -462,7 +437,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
462 | /** | 437 | /** |
463 | * Test filterHash() with an empty smallhash. | 438 | * Test filterHash() with an empty smallhash. |
464 | * | 439 | * |
465 | * @expectedException LinkNotFoundException | 440 | * @expectedException \Shaarli\Bookmark\Exception\LinkNotFoundException |
466 | */ | 441 | */ |
467 | public function testFilterHashInValid() | 442 | public function testFilterHashInValid() |
468 | { | 443 | { |
@@ -511,7 +486,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
511 | public function testRenameTagCaseSensitive() | 486 | public function testRenameTagCaseSensitive() |
512 | { | 487 | { |
513 | self::$refDB->write(self::$testDatastore); | 488 | self::$refDB->write(self::$testDatastore); |
514 | $linkDB = new LinkDB(self::$testDatastore, true, false, ''); | 489 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
515 | 490 | ||
516 | $res = $linkDB->renameTag('sTuff', 'Taz'); | 491 | $res = $linkDB->renameTag('sTuff', 'Taz'); |
517 | $this->assertEquals(1, count($res)); | 492 | $this->assertEquals(1, count($res)); |
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 | ||
3 | require_once 'application/LinkFilter.php'; | 3 | namespace Shaarli\Bookmark; |
4 | |||
5 | use Exception; | ||
6 | use ReferenceLinkDB; | ||
4 | 7 | ||
5 | /** | 8 | /** |
6 | * Class LinkFilterTest. | 9 | * Class LinkFilterTest. |
7 | */ | 10 | */ |
8 | class LinkFilterTest extends PHPUnit_Framework_TestCase | 11 | class 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..78cb8f2a 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -1,11 +1,17 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | require_once 'application/LinkUtils.php'; | 3 | namespace Shaarli\Bookmark; |
4 | |||
5 | use PHPUnit\Framework\TestCase; | ||
6 | use ReferenceLinkDB; | ||
7 | use Shaarli\Config\ConfigManager; | ||
8 | |||
9 | require_once 'tests/utils/CurlUtils.php'; | ||
4 | 10 | ||
5 | /** | 11 | /** |
6 | * Class LinkUtilsTest. | 12 | * Class LinkUtilsTest. |
7 | */ | 13 | */ |
8 | class LinkUtilsTest extends PHPUnit_Framework_TestCase | 14 | class LinkUtilsTest extends TestCase |
9 | { | 15 | { |
10 | /** | 16 | /** |
11 | * Test html_extract_title() when the title is found. | 17 | * Test html_extract_title() when the title is found. |
@@ -13,9 +19,9 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
13 | public function testHtmlExtractExistentTitle() | 19 | public function testHtmlExtractExistentTitle() |
14 | { | 20 | { |
15 | $title = 'Read me please.'; | 21 | $title = 'Read me please.'; |
16 | $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>'; | 22 | $html = '<html><meta>stuff</meta><title>' . $title . '</title></html>'; |
17 | $this->assertEquals($title, html_extract_title($html)); | 23 | $this->assertEquals($title, html_extract_title($html)); |
18 | $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>'; | 24 | $html = '<html><title>' . $title . '</title>blabla<title>another</title></html>'; |
19 | $this->assertEquals($title, html_extract_title($html)); | 25 | $this->assertEquals($title, html_extract_title($html)); |
20 | } | 26 | } |
21 | 27 | ||
@@ -34,7 +40,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
34 | public function testHeadersExtractExistentCharset() | 40 | public function testHeadersExtractExistentCharset() |
35 | { | 41 | { |
36 | $charset = 'x-MacCroatian'; | 42 | $charset = 'x-MacCroatian'; |
37 | $headers = 'text/html; charset='. $charset; | 43 | $headers = 'text/html; charset=' . $charset; |
38 | $this->assertEquals(strtolower($charset), header_extract_charset($headers)); | 44 | $this->assertEquals(strtolower($charset), header_extract_charset($headers)); |
39 | } | 45 | } |
40 | 46 | ||
@@ -56,7 +62,7 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
56 | public function testHtmlExtractExistentCharset() | 62 | public function testHtmlExtractExistentCharset() |
57 | { | 63 | { |
58 | $charset = 'x-MacCroatian'; | 64 | $charset = 'x-MacCroatian'; |
59 | $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>'; | 65 | $html = '<html><meta>stuff2</meta><meta charset="' . $charset . '"/></html>'; |
60 | $this->assertEquals(strtolower($charset), html_extract_charset($html)); | 66 | $this->assertEquals(strtolower($charset), html_extract_charset($html)); |
61 | } | 67 | } |
62 | 68 | ||
@@ -72,11 +78,56 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
72 | } | 78 | } |
73 | 79 | ||
74 | /** | 80 | /** |
81 | * Test html_extract_tag() when the tag <meta name= is found. | ||
82 | */ | ||
83 | public function testHtmlExtractExistentNameTag() | ||
84 | { | ||
85 | $description = 'Bob and Alice share cookies.'; | ||
86 | $html = '<html><meta>stuff2</meta><meta name="description" content="' . $description . '"/></html>'; | ||
87 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * Test html_extract_tag() when the tag <meta name= is not found. | ||
92 | */ | ||
93 | public function testHtmlExtractNonExistentNameTag() | ||
94 | { | ||
95 | $html = '<html><meta>stuff2</meta><meta name="image" content="img"/></html>'; | ||
96 | $this->assertFalse(html_extract_tag('description', $html)); | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * Test html_extract_tag() when the tag <meta property="og: is found. | ||
101 | */ | ||
102 | public function testHtmlExtractExistentOgTag() | ||
103 | { | ||
104 | $description = 'Bob and Alice share cookies.'; | ||
105 | $html = '<html><meta>stuff2</meta><meta property="og:description" content="' . $description . '"/></html>'; | ||
106 | $this->assertEquals($description, html_extract_tag('description', $html)); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * Test html_extract_tag() when the tag <meta property="og: is not found. | ||
111 | */ | ||
112 | public function testHtmlExtractNonExistentOgTag() | ||
113 | { | ||
114 | $html = '<html><meta>stuff2</meta><meta name="image" content="img"/></html>'; | ||
115 | $this->assertFalse(html_extract_tag('description', $html)); | ||
116 | } | ||
117 | |||
118 | /** | ||
75 | * Test the download callback with valid value | 119 | * Test the download callback with valid value |
76 | */ | 120 | */ |
77 | public function testCurlDownloadCallbackOk() | 121 | public function testCurlDownloadCallbackOk() |
78 | { | 122 | { |
79 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_ok'); | 123 | $callback = get_curl_download_callback( |
124 | $charset, | ||
125 | $title, | ||
126 | $desc, | ||
127 | $keywords, | ||
128 | false, | ||
129 | 'ut_curl_getinfo_ok' | ||
130 | ); | ||
80 | $data = [ | 131 | $data = [ |
81 | 'HTTP/1.1 200 OK', | 132 | 'HTTP/1.1 200 OK', |
82 | 'Server: GitHub.com', | 133 | 'Server: GitHub.com', |
@@ -84,9 +135,11 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
84 | 'Content-Type: text/html; charset=utf-8', | 135 | 'Content-Type: text/html; charset=utf-8', |
85 | 'Status: 200 OK', | 136 | 'Status: 200 OK', |
86 | 'end' => 'th=device-width">' | 137 | 'end' => 'th=device-width">' |
87 | .'<title>Refactoring · GitHub</title>' | 138 | . '<title>Refactoring · GitHub</title>' |
88 | .'<link rel="search" type="application/opensea', | 139 | . '<link rel="search" type="application/opensea', |
89 | '<title>ignored</title>', | 140 | '<title>ignored</title>' |
141 | . '<meta name="description" content="desc" />' | ||
142 | . '<meta name="keywords" content="key1,key2" />', | ||
90 | ]; | 143 | ]; |
91 | foreach ($data as $key => $line) { | 144 | foreach ($data as $key => $line) { |
92 | $ignore = null; | 145 | $ignore = null; |
@@ -98,6 +151,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
98 | } | 151 | } |
99 | $this->assertEquals('utf-8', $charset); | 152 | $this->assertEquals('utf-8', $charset); |
100 | $this->assertEquals('Refactoring · GitHub', $title); | 153 | $this->assertEquals('Refactoring · GitHub', $title); |
154 | $this->assertEmpty($desc); | ||
155 | $this->assertEmpty($keywords); | ||
101 | } | 156 | } |
102 | 157 | ||
103 | /** | 158 | /** |
@@ -105,13 +160,22 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
105 | */ | 160 | */ |
106 | public function testCurlDownloadCallbackOkNoCharset() | 161 | public function testCurlDownloadCallbackOkNoCharset() |
107 | { | 162 | { |
108 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_no_charset'); | 163 | $callback = get_curl_download_callback( |
164 | $charset, | ||
165 | $title, | ||
166 | $desc, | ||
167 | $keywords, | ||
168 | false, | ||
169 | 'ut_curl_getinfo_no_charset' | ||
170 | ); | ||
109 | $data = [ | 171 | $data = [ |
110 | 'HTTP/1.1 200 OK', | 172 | 'HTTP/1.1 200 OK', |
111 | 'end' => 'th=device-width">' | 173 | 'end' => 'th=device-width">' |
112 | .'<title>Refactoring · GitHub</title>' | 174 | . '<title>Refactoring · GitHub</title>' |
113 | .'<link rel="search" type="application/opensea', | 175 | . '<link rel="search" type="application/opensea', |
114 | '<title>ignored</title>', | 176 | '<title>ignored</title>' |
177 | . '<meta name="description" content="desc" />' | ||
178 | . '<meta name="keywords" content="key1,key2" />', | ||
115 | ]; | 179 | ]; |
116 | foreach ($data as $key => $line) { | 180 | foreach ($data as $key => $line) { |
117 | $ignore = null; | 181 | $ignore = null; |
@@ -119,6 +183,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
119 | } | 183 | } |
120 | $this->assertEmpty($charset); | 184 | $this->assertEmpty($charset); |
121 | $this->assertEquals('Refactoring · GitHub', $title); | 185 | $this->assertEquals('Refactoring · GitHub', $title); |
186 | $this->assertEmpty($desc); | ||
187 | $this->assertEmpty($keywords); | ||
122 | } | 188 | } |
123 | 189 | ||
124 | /** | 190 | /** |
@@ -126,14 +192,23 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
126 | */ | 192 | */ |
127 | public function testCurlDownloadCallbackOkHtmlCharset() | 193 | public function testCurlDownloadCallbackOkHtmlCharset() |
128 | { | 194 | { |
129 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_no_charset'); | 195 | $callback = get_curl_download_callback( |
196 | $charset, | ||
197 | $title, | ||
198 | $desc, | ||
199 | $keywords, | ||
200 | false, | ||
201 | 'ut_curl_getinfo_no_charset' | ||
202 | ); | ||
130 | $data = [ | 203 | $data = [ |
131 | 'HTTP/1.1 200 OK', | 204 | 'HTTP/1.1 200 OK', |
132 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', | 205 | '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', |
133 | 'end' => 'th=device-width">' | 206 | 'end' => 'th=device-width">' |
134 | .'<title>Refactoring · GitHub</title>' | 207 | . '<title>Refactoring · GitHub</title>' |
135 | .'<link rel="search" type="application/opensea', | 208 | . '<link rel="search" type="application/opensea', |
136 | '<title>ignored</title>', | 209 | '<title>ignored</title>' |
210 | . '<meta name="description" content="desc" />' | ||
211 | . '<meta name="keywords" content="key1,key2" />', | ||
137 | ]; | 212 | ]; |
138 | foreach ($data as $key => $line) { | 213 | foreach ($data as $key => $line) { |
139 | $ignore = null; | 214 | $ignore = null; |
@@ -145,6 +220,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
145 | } | 220 | } |
146 | $this->assertEquals('utf-8', $charset); | 221 | $this->assertEquals('utf-8', $charset); |
147 | $this->assertEquals('Refactoring · GitHub', $title); | 222 | $this->assertEquals('Refactoring · GitHub', $title); |
223 | $this->assertEmpty($desc); | ||
224 | $this->assertEmpty($keywords); | ||
148 | } | 225 | } |
149 | 226 | ||
150 | /** | 227 | /** |
@@ -152,7 +229,14 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
152 | */ | 229 | */ |
153 | public function testCurlDownloadCallbackOkNoTitle() | 230 | public function testCurlDownloadCallbackOkNoTitle() |
154 | { | 231 | { |
155 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_ok'); | 232 | $callback = get_curl_download_callback( |
233 | $charset, | ||
234 | $title, | ||
235 | $desc, | ||
236 | $keywords, | ||
237 | false, | ||
238 | 'ut_curl_getinfo_ok' | ||
239 | ); | ||
156 | $data = [ | 240 | $data = [ |
157 | 'HTTP/1.1 200 OK', | 241 | 'HTTP/1.1 200 OK', |
158 | 'end' => 'th=device-width">Refactoring · GitHub<link rel="search" type="application/opensea', | 242 | 'end' => 'th=device-width">Refactoring · GitHub<link rel="search" type="application/opensea', |
@@ -164,6 +248,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
164 | } | 248 | } |
165 | $this->assertEquals('utf-8', $charset); | 249 | $this->assertEquals('utf-8', $charset); |
166 | $this->assertEmpty($title); | 250 | $this->assertEmpty($title); |
251 | $this->assertEmpty($desc); | ||
252 | $this->assertEmpty($keywords); | ||
167 | } | 253 | } |
168 | 254 | ||
169 | /** | 255 | /** |
@@ -171,7 +257,14 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
171 | */ | 257 | */ |
172 | public function testCurlDownloadCallbackInvalidContentType() | 258 | public function testCurlDownloadCallbackInvalidContentType() |
173 | { | 259 | { |
174 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_ct_ko'); | 260 | $callback = get_curl_download_callback( |
261 | $charset, | ||
262 | $title, | ||
263 | $desc, | ||
264 | $keywords, | ||
265 | false, | ||
266 | 'ut_curl_getinfo_ct_ko' | ||
267 | ); | ||
175 | $ignore = null; | 268 | $ignore = null; |
176 | $this->assertFalse($callback($ignore, '')); | 269 | $this->assertFalse($callback($ignore, '')); |
177 | $this->assertEmpty($charset); | 270 | $this->assertEmpty($charset); |
@@ -183,7 +276,14 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
183 | */ | 276 | */ |
184 | public function testCurlDownloadCallbackInvalidResponseCode() | 277 | public function testCurlDownloadCallbackInvalidResponseCode() |
185 | { | 278 | { |
186 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_rc_ko'); | 279 | $callback = $callback = get_curl_download_callback( |
280 | $charset, | ||
281 | $title, | ||
282 | $desc, | ||
283 | $keywords, | ||
284 | false, | ||
285 | 'ut_curl_getinfo_rc_ko' | ||
286 | ); | ||
187 | $ignore = null; | 287 | $ignore = null; |
188 | $this->assertFalse($callback($ignore, '')); | 288 | $this->assertFalse($callback($ignore, '')); |
189 | $this->assertEmpty($charset); | 289 | $this->assertEmpty($charset); |
@@ -195,7 +295,14 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
195 | */ | 295 | */ |
196 | public function testCurlDownloadCallbackInvalidContentTypeAndResponseCode() | 296 | public function testCurlDownloadCallbackInvalidContentTypeAndResponseCode() |
197 | { | 297 | { |
198 | $callback = get_curl_download_callback($charset, $title, 'ut_curl_getinfo_rs_ct_ko'); | 298 | $callback = $callback = get_curl_download_callback( |
299 | $charset, | ||
300 | $title, | ||
301 | $desc, | ||
302 | $keywords, | ||
303 | false, | ||
304 | 'ut_curl_getinfo_rs_ct_ko' | ||
305 | ); | ||
199 | $ignore = null; | 306 | $ignore = null; |
200 | $this->assertFalse($callback($ignore, '')); | 307 | $this->assertFalse($callback($ignore, '')); |
201 | $this->assertEmpty($charset); | 308 | $this->assertEmpty($charset); |
@@ -203,6 +310,85 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
203 | } | 310 | } |
204 | 311 | ||
205 | /** | 312 | /** |
313 | * Test the download callback with valid value, and retrieve_description option enabled. | ||
314 | */ | ||
315 | public function testCurlDownloadCallbackOkWithDesc() | ||
316 | { | ||
317 | $callback = get_curl_download_callback( | ||
318 | $charset, | ||
319 | $title, | ||
320 | $desc, | ||
321 | $keywords, | ||
322 | true, | ||
323 | 'ut_curl_getinfo_ok' | ||
324 | ); | ||
325 | $data = [ | ||
326 | 'HTTP/1.1 200 OK', | ||
327 | 'Server: GitHub.com', | ||
328 | 'Date: Sat, 28 Oct 2017 12:01:33 GMT', | ||
329 | 'Content-Type: text/html; charset=utf-8', | ||
330 | 'Status: 200 OK', | ||
331 | 'th=device-width">' | ||
332 | . '<title>Refactoring · GitHub</title>' | ||
333 | . '<link rel="search" type="application/opensea', | ||
334 | 'end' => '<title>ignored</title>' | ||
335 | . '<meta name="description" content="link desc" />' | ||
336 | . '<meta name="keywords" content="key1,key2" />', | ||
337 | ]; | ||
338 | foreach ($data as $key => $line) { | ||
339 | $ignore = null; | ||
340 | $expected = $key !== 'end' ? strlen($line) : false; | ||
341 | $this->assertEquals($expected, $callback($ignore, $line)); | ||
342 | if ($expected === false) { | ||
343 | break; | ||
344 | } | ||
345 | } | ||
346 | $this->assertEquals('utf-8', $charset); | ||
347 | $this->assertEquals('Refactoring · GitHub', $title); | ||
348 | $this->assertEquals('link desc', $desc); | ||
349 | $this->assertEquals('key1 key2', $keywords); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Test the download callback with valid value, and retrieve_description option enabled, | ||
354 | * but no desc or keyword defined in the page. | ||
355 | */ | ||
356 | public function testCurlDownloadCallbackOkWithDescNotFound() | ||
357 | { | ||
358 | $callback = get_curl_download_callback( | ||
359 | $charset, | ||
360 | $title, | ||
361 | $desc, | ||
362 | $keywords, | ||
363 | true, | ||
364 | 'ut_curl_getinfo_ok' | ||
365 | ); | ||
366 | $data = [ | ||
367 | 'HTTP/1.1 200 OK', | ||
368 | 'Server: GitHub.com', | ||
369 | 'Date: Sat, 28 Oct 2017 12:01:33 GMT', | ||
370 | 'Content-Type: text/html; charset=utf-8', | ||
371 | 'Status: 200 OK', | ||
372 | 'th=device-width">' | ||
373 | . '<title>Refactoring · GitHub</title>' | ||
374 | . '<link rel="search" type="application/opensea', | ||
375 | 'end' => '<title>ignored</title>', | ||
376 | ]; | ||
377 | foreach ($data as $key => $line) { | ||
378 | $ignore = null; | ||
379 | $expected = $key !== 'end' ? strlen($line) : false; | ||
380 | $this->assertEquals($expected, $callback($ignore, $line)); | ||
381 | if ($expected === false) { | ||
382 | break; | ||
383 | } | ||
384 | } | ||
385 | $this->assertEquals('utf-8', $charset); | ||
386 | $this->assertEquals('Refactoring · GitHub', $title); | ||
387 | $this->assertEmpty($desc); | ||
388 | $this->assertEmpty($keywords); | ||
389 | } | ||
390 | |||
391 | /** | ||
206 | * Test count_private. | 392 | * Test count_private. |
207 | */ | 393 | */ |
208 | public function testCountPrivateLinks() | 394 | public function testCountPrivateLinks() |
@@ -212,56 +398,27 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
212 | } | 398 | } |
213 | 399 | ||
214 | /** | 400 | /** |
215 | * Test text2clickable without a redirector being set. | 401 | * Test text2clickable. |
216 | */ | 402 | */ |
217 | public function testText2clickableWithoutRedirector() | 403 | public function testText2clickable() |
218 | { | 404 | { |
219 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | 405 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; |
220 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' | 406 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' |
221 | .'http://hello.there/is=someone#here</a> otherstuff'; | 407 | . 'http://hello.there/is=someone#here</a> otherstuff'; |
222 | $processedText = text2clickable($text, ''); | 408 | $processedText = text2clickable($text); |
223 | $this->assertEquals($expectedText, $processedText); | 409 | $this->assertEquals($expectedText, $processedText); |
224 | 410 | ||
225 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; | 411 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; |
226 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' | 412 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' |
227 | .'http://hello.there/is=someone#here(please)</a> otherstuff'; | 413 | . 'http://hello.there/is=someone#here(please)</a> otherstuff'; |
228 | $processedText = text2clickable($text, ''); | 414 | $processedText = text2clickable($text); |
229 | $this->assertEquals($expectedText, $processedText); | 415 | $this->assertEquals($expectedText, $processedText); |
230 | 416 | ||
231 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | 417 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; |
418 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | ||
232 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' | 419 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' |
233 | .'http://hello.there/is=someone#here(please)&no</a> otherstuff'; | 420 | . 'http://hello.there/is=someone#here(please)&no</a> otherstuff'; |
234 | $processedText = text2clickable($text, ''); | 421 | $processedText = text2clickable($text); |
235 | $this->assertEquals($expectedText, $processedText); | ||
236 | } | ||
237 | |||
238 | /** | ||
239 | * Test text2clickable with a redirector set. | ||
240 | */ | ||
241 | public function testText2clickableWithRedirector() | ||
242 | { | ||
243 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
244 | $redirector = 'http://redirector.to'; | ||
245 | $expectedText = 'stuff <a href="'. | ||
246 | $redirector . | ||
247 | urlencode('http://hello.there/is=someone#here') . | ||
248 | '">http://hello.there/is=someone#here</a> otherstuff'; | ||
249 | $processedText = text2clickable($text, $redirector); | ||
250 | $this->assertEquals($expectedText, $processedText); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Test text2clickable a redirector set and without URL encode. | ||
255 | */ | ||
256 | public function testText2clickableWithRedirectorDontEncode() | ||
257 | { | ||
258 | $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; | ||
259 | $redirector = 'http://redirector.to'; | ||
260 | $expectedText = 'stuff <a href="'. | ||
261 | $redirector . | ||
262 | 'http://hello.there/?is=someone&or=something#here' . | ||
263 | '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; | ||
264 | $processedText = text2clickable($text, $redirector, false); | ||
265 | $this->assertEquals($expectedText, $processedText); | 422 | $this->assertEquals($expectedText, $processedText); |
266 | } | 423 | } |
267 | 424 | ||
@@ -270,8 +427,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
270 | */ | 427 | */ |
271 | public function testSpace2nbsp() | 428 | public function testSpace2nbsp() |
272 | { | 429 | { |
273 | $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | 430 | $text = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?'; |
274 | $expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | 431 | $expectedText = ' Are you thrilled by flags ?' . PHP_EOL . ' Really?'; |
275 | $processedText = space2nbsp($text); | 432 | $processedText = space2nbsp($text); |
276 | $this->assertEquals($expectedText, $processedText); | 433 | $this->assertEquals($expectedText, $processedText); |
277 | } | 434 | } |
@@ -314,108 +471,36 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
314 | } | 471 | } |
315 | 472 | ||
316 | /** | 473 | /** |
474 | * Test is_note with note URLs. | ||
475 | */ | ||
476 | public function testIsNote() | ||
477 | { | ||
478 | $this->assertTrue(is_note('?')); | ||
479 | $this->assertTrue(is_note('?abcDEf')); | ||
480 | $this->assertTrue(is_note('?_abcDEf#123')); | ||
481 | } | ||
482 | |||
483 | /** | ||
484 | * Test is_note with non note URLs. | ||
485 | */ | ||
486 | public function testIsNotNote() | ||
487 | { | ||
488 | $this->assertFalse(is_note('')); | ||
489 | $this->assertFalse(is_note('nope')); | ||
490 | $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi')); | ||
491 | } | ||
492 | |||
493 | /** | ||
317 | * Util function to build an hashtag link. | 494 | * Util function to build an hashtag link. |
318 | * | 495 | * |
319 | * @param string $hashtag Hashtag name. | 496 | * @param string $hashtag Hashtag name. |
320 | * @param string $index Index URL. | 497 | * @param string $index Index URL. |
321 | * | 498 | * |
322 | * @return string HTML hashtag link. | 499 | * @return string HTML hashtag link. |
323 | */ | 500 | */ |
324 | private function getHashtagLink($hashtag, $index = '') | 501 | private function getHashtagLink($hashtag, $index = '') |
325 | { | 502 | { |
326 | $hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>'; | 503 | $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>'; |
327 | return str_replace('$1', $hashtag, $hashtagLink); | 504 | return str_replace('$1', $hashtag, $hashtagLink); |
328 | } | 505 | } |
329 | } | 506 | } |
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 | */ | ||
341 | function 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 | */ | ||
359 | function 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 | */ | ||
377 | function 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 | */ | ||
395 | function 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 | */ | ||
413 | function 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 | */ |
7 | class ConfigJsonTest extends \PHPUnit_Framework_TestCase | 7 | class 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 | */ |
10 | class ConfigManagerTest extends \PHPUnit_Framework_TestCase | 10 | class 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 | */ |
7 | class ConfigPhpTest extends \PHPUnit_Framework_TestCase | 7 | class 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 | */ |
11 | class ConfigPluginTest extends \PHPUnit_Framework_TestCase | 11 | class 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 | */ |
5 | namespace Shaarli\Feed; | ||
5 | 6 | ||
6 | // required to access $_SESSION array | 7 | // required to access $_SESSION array |
7 | session_start(); | 8 | session_start(); |
8 | 9 | ||
9 | require_once 'application/Cache.php'; | 10 | require_once 'application/feed/Cache.php'; |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * Unitary tests for cached pages | 13 | * Unitary tests for cached pages |
13 | */ | 14 | */ |
14 | class CacheTest extends PHPUnit_Framework_TestCase | 15 | class 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 | 5 | namespace Shaarli\Feed; | |
6 | require_once 'application/CachedPage.php'; | ||
7 | 6 | ||
8 | /** | 7 | /** |
9 | * Unitary tests for cached pages | 8 | * Unitary tests for cached pages |
10 | */ | 9 | */ |
11 | class CachedPageTest extends PHPUnit_Framework_TestCase | 10 | class 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 | ||
3 | require_once 'application/FeedBuilder.php'; | 3 | namespace Shaarli\Feed; |
4 | require_once 'application/LinkDB.php'; | 4 | |
5 | use DateTime; | ||
6 | use ReferenceLinkDB; | ||
7 | use 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 | */ |
11 | class FeedBuilderTest extends PHPUnit_Framework_TestCase | 14 | class 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 | ||
6 | require_once 'application/HttpUtils.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_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 | */ |
11 | class ClientIpIdTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
6 | require_once 'application/HttpUtils.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_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 | */ |
11 | class GetHttpUrlTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
3 | require_once 'application/HttpUtils.php'; | 3 | namespace Shaarli\Http; |
4 | |||
5 | require_once 'application/http/HttpUtils.php'; | ||
4 | 6 | ||
5 | /** | 7 | /** |
6 | * Unitary tests for getIpAddressFromProxy() | 8 | * Unitary tests for getIpAddressFromProxy() |
7 | */ | 9 | */ |
8 | class GetIpAdressFromProxyTest extends PHPUnit_Framework_TestCase | 10 | class 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 | ||
6 | require_once 'application/HttpUtils.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_once 'application/http/HttpUtils.php'; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * Unitary tests for index_url() | 11 | * Unitary tests for index_url() |
10 | */ | 12 | */ |
11 | class IndexUrlTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
3 | namespace Shaarli\Http; | ||
4 | |||
5 | require_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 | */ |
9 | class IsHttpsTest extends PHPUnit_Framework_TestCase | 12 | class 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 | ||
6 | require_once 'application/HttpUtils.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_once 'application/http/HttpUtils.php'; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * Unitary tests for page_url() | 11 | * Unitary tests for page_url() |
10 | */ | 12 | */ |
11 | class PageUrlTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
6 | require_once 'application/HttpUtils.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_once 'application/http/HttpUtils.php'; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * Unitary tests for server_url() | 11 | * Unitary tests for server_url() |
10 | */ | 12 | */ |
11 | class ServerUrlTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
6 | require_once 'application/Url.php'; | 6 | namespace Shaarli\Http; |
7 | 7 | ||
8 | /** | 8 | /** |
9 | * Unitary tests for URL utilities | 9 | * Unitary tests for URL utilities |
10 | */ | 10 | */ |
11 | class UrlTest extends PHPUnit_Framework_TestCase | 11 | class 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 | ||
6 | require_once 'application/Url.php'; | 6 | namespace Shaarli\Http; |
7 | 7 | ||
8 | class CleanupUrlTest extends PHPUnit_Framework_TestCase | 8 | require_once 'application/http/UrlUtils.php'; |
9 | |||
10 | class 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 | ||
6 | require_once 'application/Url.php'; | 6 | namespace Shaarli\Http; |
7 | 7 | ||
8 | class GetUrlSchemeTest extends PHPUnit_Framework_TestCase | 8 | require_once 'application/http/UrlUtils.php'; |
9 | |||
10 | class 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 | ||
6 | require_once 'application/Url.php'; | 6 | namespace Shaarli\Http; |
7 | |||
8 | require_once 'application/http/UrlUtils.php'; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * Unitary tests for unparse_url() | 11 | * Unitary tests for unparse_url() |
10 | */ | 12 | */ |
11 | class UnparseUrlTest extends PHPUnit_Framework_TestCase | 13 | class 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 | ||
3 | require_once 'application/Url.php'; | 3 | namespace Shaarli\Http; |
4 | 4 | ||
5 | use Shaarli\Config\ConfigManager; | 5 | require_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 | */ |
12 | class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase | 12 | class 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 | */ |
15 | class LanguagesFrTest extends \PHPUnit_Framework_TestCase | 15 | class 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 |
2 | namespace Shaarli\Netscape; | ||
2 | 3 | ||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | 4 | use Shaarli\Bookmark\LinkDB; |
5 | |||
6 | require_once 'tests/utils/ReferenceLinkDB.php'; | ||
4 | 7 | ||
5 | /** | 8 | /** |
6 | * Netscape bookmark export | 9 | * Netscape bookmark export |
7 | */ | 10 | */ |
8 | class BookmarkExportTest extends PHPUnit_Framework_TestCase | 11 | class 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 |
2 | namespace Shaarli\Netscape; | ||
2 | 3 | ||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | 4 | use DateTime; |
4 | 5 | use Shaarli\Bookmark\LinkDB; | |
5 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use 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 | */ |
29 | class BookmarkImportTest extends PHPUnit_Framework_TestCase | 31 | class 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 |
2 | namespace Shaarli\Plugin\Addlink; | ||
2 | 3 | ||
3 | /** | 4 | use Shaarli\Plugin\PluginManager; |
4 | * PluginPlayvideosTest.php | 5 | use Shaarli\Router; |
5 | */ | ||
6 | 6 | ||
7 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; | 7 | require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; |
8 | require_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 | */ |
14 | class PluginAddlinkTest extends PHPUnit_Framework_TestCase | 12 | class 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 |
2 | namespace Shaarli\Plugin\Archiveorg; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * PluginArchiveorgTest.php | 5 | * PluginArchiveorgTest.php |
5 | */ | 6 | */ |
6 | 7 | ||
8 | use Shaarli\Plugin\PluginManager; | ||
9 | |||
7 | require_once 'plugins/archiveorg/archiveorg.php'; | 10 | require_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 | */ |
13 | class PluginArchiveorgTest extends PHPUnit_Framework_TestCase | 16 | class PluginArchiveorgTest extends \PHPUnit\Framework\TestCase |
14 | { | 17 | { |
15 | /** | 18 | /** |
16 | * Reset plugin path | 19 | * Reset plugin path |
diff --git a/tests/plugins/PluginDefaultColorsTest.php b/tests/plugins/PluginDefaultColorsTest.php new file mode 100644 index 00000000..b9951cca --- /dev/null +++ b/tests/plugins/PluginDefaultColorsTest.php | |||
@@ -0,0 +1,195 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli\Plugin\DefaultColors; | ||
4 | |||
5 | use DateTime; | ||
6 | use PHPUnit\Framework\TestCase; | ||
7 | use Shaarli\Bookmark\LinkDB; | ||
8 | use Shaarli\Config\ConfigManager; | ||
9 | use Shaarli\Plugin\PluginManager; | ||
10 | |||
11 | require_once 'plugins/default_colors/default_colors.php'; | ||
12 | |||
13 | /** | ||
14 | * Class PluginDefaultColorsTest | ||
15 | * | ||
16 | * Test the DefaultColors plugin (allowing to override default template colors). | ||
17 | */ | ||
18 | class PluginDefaultColorsTest extends TestCase | ||
19 | { | ||
20 | /** | ||
21 | * Reset plugin path | ||
22 | */ | ||
23 | public function setUp() | ||
24 | { | ||
25 | PluginManager::$PLUGINS_PATH = 'sandbox'; | ||
26 | mkdir(PluginManager::$PLUGINS_PATH . '/default_colors/'); | ||
27 | copy( | ||
28 | 'plugins/default_colors/default_colors.css.template', | ||
29 | PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template' | ||
30 | ); | ||
31 | } | ||
32 | |||
33 | /** | ||
34 | * Remove sandbox files and folder | ||
35 | */ | ||
36 | public function tearDown() | ||
37 | { | ||
38 | if (file_exists('sandbox/default_colors/default_colors.css.template')) { | ||
39 | unlink('sandbox/default_colors/default_colors.css.template'); | ||
40 | } | ||
41 | |||
42 | if (file_exists('sandbox/default_colors/default_colors.css')) { | ||
43 | unlink('sandbox/default_colors/default_colors.css'); | ||
44 | } | ||
45 | |||
46 | if (is_dir('sandbox/default_colors')) { | ||
47 | rmdir('sandbox/default_colors'); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Test DefaultColors init without errors. | ||
53 | */ | ||
54 | public function testDefaultColorsInitNoError() | ||
55 | { | ||
56 | $conf = new ConfigManager(''); | ||
57 | $conf->set('plugins.DEFAULT_COLORS_BACKGROUND', 'value'); | ||
58 | $errors = default_colors_init($conf); | ||
59 | $this->assertEmpty($errors); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Test DefaultColors init with errors. | ||
64 | */ | ||
65 | public function testDefaultColorsInitError() | ||
66 | { | ||
67 | $conf = new ConfigManager(''); | ||
68 | $errors = default_colors_init($conf); | ||
69 | $this->assertNotEmpty($errors); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * Test the save plugin parameters hook with all colors specified. | ||
74 | */ | ||
75 | public function testSavePluginParametersAll() | ||
76 | { | ||
77 | $post = [ | ||
78 | 'other1' => true, | ||
79 | 'DEFAULT_COLORS_MAIN' => 'blue', | ||
80 | 'DEFAULT_COLORS_BACKGROUND' => 'pink', | ||
81 | 'other2' => ['yep'], | ||
82 | 'DEFAULT_COLORS_DARK_MAIN' => 'green', | ||
83 | ]; | ||
84 | |||
85 | hook_default_colors_save_plugin_parameters($post); | ||
86 | $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); | ||
87 | $content = file_get_contents($file); | ||
88 | $expected = ':root { | ||
89 | --main-color: blue; | ||
90 | --background-color: pink; | ||
91 | --dark-main-color: green; | ||
92 | |||
93 | } | ||
94 | '; | ||
95 | $this->assertEquals($expected, $content); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * Test the save plugin parameters hook with only one color specified. | ||
100 | */ | ||
101 | public function testSavePluginParametersSingle() | ||
102 | { | ||
103 | $post = [ | ||
104 | 'other1' => true, | ||
105 | 'DEFAULT_COLORS_BACKGROUND' => 'pink', | ||
106 | 'other2' => ['yep'], | ||
107 | 'DEFAULT_COLORS_DARK_MAIN' => '', | ||
108 | ]; | ||
109 | |||
110 | hook_default_colors_save_plugin_parameters($post); | ||
111 | $this->assertFileExists($file = 'sandbox/default_colors/default_colors.css'); | ||
112 | $content = file_get_contents($file); | ||
113 | $expected = ':root { | ||
114 | --background-color: pink; | ||
115 | |||
116 | } | ||
117 | '; | ||
118 | $this->assertEquals($expected, $content); | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * Test the save plugin parameters hook with no color specified. | ||
123 | */ | ||
124 | public function testSavePluginParametersNone() | ||
125 | { | ||
126 | hook_default_colors_save_plugin_parameters([]); | ||
127 | $this->assertFileNotExists($file = 'sandbox/default_colors/default_colors.css'); | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * Make sure that the CSS is properly included by the include hook. | ||
132 | */ | ||
133 | public function testIncludeWithFile() | ||
134 | { | ||
135 | $data = [ | ||
136 | 'css_files' => ['file1'], | ||
137 | 'js_files' => ['file2'], | ||
138 | ]; | ||
139 | touch($file = 'sandbox/default_colors/default_colors.css'); | ||
140 | $processedData = hook_default_colors_render_includes($data); | ||
141 | |||
142 | $this->assertCount(2, $processedData['css_files']); | ||
143 | $this->assertEquals($file, $processedData['css_files'][1]); | ||
144 | $this->assertCount(1, $processedData['js_files']); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * Make sure that the CSS is not included by the include hook if the CSS file does not exist. | ||
149 | */ | ||
150 | public function testIncludeWithoutFile() | ||
151 | { | ||
152 | $data = [ | ||
153 | 'css_files' => ['file1'], | ||
154 | 'js_files' => ['file2'], | ||
155 | ]; | ||
156 | $processedData = hook_default_colors_render_includes($data); | ||
157 | |||
158 | $this->assertEquals($data, $processedData); | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * Test helper function which generates CSS rules with valid input. | ||
163 | */ | ||
164 | public function testFormatCssRuleValid() | ||
165 | { | ||
166 | $data = [ | ||
167 | 'other1' => true, | ||
168 | 'DEFAULT_COLORS_BLIP_BLOP' => 'shinyColor', | ||
169 | 'other2' => ['yep'], | ||
170 | ]; | ||
171 | $result = default_colors_format_css_rule($data, 'DEFAULT_COLORS_BLIP_BLOP'); | ||
172 | $this->assertEquals(' --blip-blop-color: shinyColor', $result); | ||
173 | |||
174 | $data = ['unknown-parameter' => true]; | ||
175 | $result = default_colors_format_css_rule($data, 'unknown-parameter'); | ||
176 | $this->assertEquals(' --unknown-parameter-color: 1', $result); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Test helper function which generates CSS rules with invalid input. | ||
181 | */ | ||
182 | public function testFormatCssRuleInvalid() | ||
183 | { | ||
184 | $result = default_colors_format_css_rule([], 'DEFAULT_COLORS_BLIP_BLOP'); | ||
185 | $this->assertEmpty($result); | ||
186 | |||
187 | $data = [ | ||
188 | 'other1' => true, | ||
189 | 'DEFAULT_COLORS_BLIP_BLOP' => 'shinyColor', | ||
190 | 'other2' => ['yep'], | ||
191 | ]; | ||
192 | $result = default_colors_format_css_rule($data, ''); | ||
193 | $this->assertEmpty($result); | ||
194 | } | ||
195 | } | ||
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 |
2 | namespace Shaarli\Plugin\Isso; | ||
3 | |||
4 | use DateTime; | ||
5 | use Shaarli\Bookmark\LinkDB; | ||
2 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\Plugin\PluginManager; | ||
3 | 8 | ||
4 | require_once 'plugins/isso/isso.php'; | 9 | require_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 | */ |
11 | class PluginIssoTest extends PHPUnit_Framework_TestCase | 16 | class 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..9ddbc558 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -1,10 +1,14 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Plugin\Markdown; | ||
3 | |||
2 | use Shaarli\Config\ConfigManager; | 4 | use Shaarli\Config\ConfigManager; |
5 | use Shaarli\Plugin\PluginManager; | ||
3 | 6 | ||
4 | /** | 7 | /** |
5 | * PluginMarkdownTest.php | 8 | * PluginMarkdownTest.php |
6 | */ | 9 | */ |
7 | 10 | ||
11 | require_once 'application/bookmark/LinkUtils.php'; | ||
8 | require_once 'application/Utils.php'; | 12 | require_once 'application/Utils.php'; |
9 | require_once 'plugins/markdown/markdown.php'; | 13 | require_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 | */ |
15 | class PluginMarkdownTest extends PHPUnit_Framework_TestCase | 19 | class PluginMarkdownTest extends \PHPUnit\Framework\TestCase |
16 | { | 20 | { |
17 | /** | 21 | /** |
18 | * @var ConfigManager instance. | 22 | * @var ConfigManager instance. |
@@ -103,7 +107,7 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
103 | public function testReverseText2clickable() | 107 | public function testReverseText2clickable() |
104 | { | 108 | { |
105 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | 109 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; |
106 | $clickableText = text2clickable($text, ''); | 110 | $clickableText = text2clickable($text); |
107 | $reversedText = reverse_text2clickable($clickableText); | 111 | $reversedText = reverse_text2clickable($clickableText); |
108 | $this->assertEquals($text, $reversedText); | 112 | $this->assertEquals($text, $reversedText); |
109 | } | 113 | } |
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 |
2 | namespace Shaarli\Plugin\Playvideos; | ||
2 | 3 | ||
3 | /** | 4 | /** |
4 | * PluginPlayvideosTest.php | 5 | * PluginPlayvideosTest.php |
5 | */ | 6 | */ |
6 | 7 | ||
8 | use Shaarli\Plugin\PluginManager; | ||
9 | use Shaarli\Router; | ||
10 | |||
7 | require_once 'plugins/playvideos/playvideos.php'; | 11 | require_once 'plugins/playvideos/playvideos.php'; |
8 | require_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 | */ |
14 | class PluginPlayvideosTest extends PHPUnit_Framework_TestCase | 17 | class 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 |
2 | namespace Shaarli\Plugin\Pubsubhubbub; | ||
3 | |||
2 | use Shaarli\Config\ConfigManager; | 4 | use Shaarli\Config\ConfigManager; |
5 | use Shaarli\Plugin\PluginManager; | ||
6 | use Shaarli\Router; | ||
3 | 7 | ||
4 | require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; | 8 | require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; |
5 | require_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 | */ |
11 | class PluginPubsubhubbubTest extends PHPUnit_Framework_TestCase | 14 | class 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 |
2 | namespace Shaarli\Plugin\Qrcode; | ||
3 | |||
2 | /** | 4 | /** |
3 | * PluginQrcodeTest.php | 5 | * PluginQrcodeTest.php |
4 | */ | 6 | */ |
5 | 7 | ||
8 | use Shaarli\Plugin\PluginManager; | ||
9 | use Shaarli\Router; | ||
10 | |||
6 | require_once 'plugins/qrcode/qrcode.php'; | 11 | require_once 'plugins/qrcode/qrcode.php'; |
7 | require_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 | */ |
13 | class PluginQrcodeTest extends PHPUnit_Framework_TestCase | 17 | class 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 |
2 | use Shaarli\Config\ConfigManager; | 2 | namespace Shaarli\Plugin\Wallabag; |
3 | 3 | ||
4 | /** | 4 | use Shaarli\Config\ConfigManager; |
5 | * PluginWallabagTest.php.php | 5 | use Shaarli\Plugin\PluginManager; |
6 | */ | ||
7 | 6 | ||
8 | require_once 'plugins/wallabag/wallabag.php'; | 7 | require_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 | */ |
14 | class PluginWallabagTest extends PHPUnit_Framework_TestCase | 13 | class 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 | 2 | namespace Shaarli\Plugin\Wallabag; | |
3 | require_once 'plugins/wallabag/WallabagInstance.php'; | ||
4 | 3 | ||
5 | /** | 4 | /** |
6 | * Class WallabagInstanceTest | 5 | * Class WallabagInstanceTest |
7 | */ | 6 | */ |
8 | class WallabagInstanceTest extends PHPUnit_Framework_TestCase | 7 | class 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 | ||
3 | namespace Shaarli; | 3 | namespace Shaarli\Render; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Class ThemeUtilsTest | 6 | * Class ThemeUtilsTest |
7 | * | 7 | * |
8 | * @package Shaarli | 8 | * @package Shaarli |
9 | */ | 9 | */ |
10 | class ThemeUtilsTest extends \PHPUnit_Framework_TestCase | 10 | class 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/BanManagerTest.php b/tests/security/BanManagerTest.php new file mode 100644 index 00000000..bba7c8ad --- /dev/null +++ b/tests/security/BanManagerTest.php | |||
@@ -0,0 +1,393 @@ | |||
1 | <?php | ||
2 | |||
3 | |||
4 | namespace Shaarli\Security; | ||
5 | |||
6 | use PHPUnit\Framework\TestCase; | ||
7 | use Shaarli\FileUtils; | ||
8 | |||
9 | /** | ||
10 | * Test coverage for BanManager | ||
11 | */ | ||
12 | class BanManagerTest extends TestCase | ||
13 | { | ||
14 | /** @var BanManager Ban Manager instance */ | ||
15 | protected $banManager; | ||
16 | |||
17 | /** @var string Banned IP filename */ | ||
18 | protected $banFile = 'sandbox/ipbans.php'; | ||
19 | |||
20 | /** @var string Log filename */ | ||
21 | protected $logFile = 'sandbox/shaarli.log'; | ||
22 | |||
23 | /** @var string Local client IP address */ | ||
24 | protected $ipAddr = '127.0.0.1'; | ||
25 | |||
26 | /** @var string Trusted proxy IP address */ | ||
27 | protected $trustedProxy = '10.1.1.100'; | ||
28 | |||
29 | /** @var array Simulates the $_SERVER array */ | ||
30 | protected $server = []; | ||
31 | |||
32 | /** | ||
33 | * Prepare or reset test resources | ||
34 | */ | ||
35 | public function setUp() | ||
36 | { | ||
37 | if (file_exists($this->banFile)) { | ||
38 | unlink($this->banFile); | ||
39 | } | ||
40 | |||
41 | $this->banManager = $this->getNewBanManagerInstance(); | ||
42 | $this->server['REMOTE_ADDR'] = $this->ipAddr; | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Test constructor with initial file. | ||
47 | */ | ||
48 | public function testInstantiateFromFile() | ||
49 | { | ||
50 | $time = time() + 10; | ||
51 | FileUtils::writeFlatDB( | ||
52 | $this->banFile, | ||
53 | [ | ||
54 | 'failures' => [ | ||
55 | $this->ipAddr => 2, | ||
56 | $ip = '1.2.3.4' => 1, | ||
57 | ], | ||
58 | 'bans' => [ | ||
59 | $ip2 = '8.8.8.8' => $time, | ||
60 | $ip3 = '1.1.1.1' => $time + 1, | ||
61 | ], | ||
62 | ] | ||
63 | ); | ||
64 | $this->banManager = $this->getNewBanManagerInstance(); | ||
65 | |||
66 | $this->assertCount(2, $this->banManager->getFailures()); | ||
67 | $this->assertEquals(2, $this->banManager->getFailures()[$this->ipAddr]); | ||
68 | $this->assertEquals(1, $this->banManager->getFailures()[$ip]); | ||
69 | $this->assertCount(2, $this->banManager->getBans()); | ||
70 | $this->assertEquals($time, $this->banManager->getBans()[$ip2]); | ||
71 | $this->assertEquals($time + 1, $this->banManager->getBans()[$ip3]); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Test constructor with initial file with invalid values | ||
76 | */ | ||
77 | public function testInstantiateFromCrappyFile() | ||
78 | { | ||
79 | FileUtils::writeFlatDB($this->banFile, 'plop'); | ||
80 | $this->banManager = $this->getNewBanManagerInstance(); | ||
81 | |||
82 | $this->assertEquals([], $this->banManager->getFailures()); | ||
83 | $this->assertEquals([], $this->banManager->getBans()); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * Test failed attempt with a direct IP. | ||
88 | */ | ||
89 | public function testHandleFailedAttempt() | ||
90 | { | ||
91 | $this->assertCount(0, $this->banManager->getFailures()); | ||
92 | |||
93 | $this->banManager->handleFailedAttempt($this->server); | ||
94 | $this->assertCount(1, $this->banManager->getFailures()); | ||
95 | $this->assertEquals(1, $this->banManager->getFailures()[$this->ipAddr]); | ||
96 | |||
97 | $this->banManager->handleFailedAttempt($this->server); | ||
98 | $this->assertCount(1, $this->banManager->getFailures()); | ||
99 | $this->assertEquals(2, $this->banManager->getFailures()[$this->ipAddr]); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Test failed attempt behind a trusted proxy IP (with proper IP forwarding). | ||
104 | */ | ||
105 | public function testHandleFailedAttemptBehingProxy() | ||
106 | { | ||
107 | $server = [ | ||
108 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
109 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, | ||
110 | ]; | ||
111 | $this->assertCount(0, $this->banManager->getFailures()); | ||
112 | |||
113 | $this->banManager->handleFailedAttempt($server); | ||
114 | $this->assertCount(1, $this->banManager->getFailures()); | ||
115 | $this->assertEquals(1, $this->banManager->getFailures()[$this->ipAddr]); | ||
116 | |||
117 | $this->banManager->handleFailedAttempt($server); | ||
118 | $this->assertCount(1, $this->banManager->getFailures()); | ||
119 | $this->assertEquals(2, $this->banManager->getFailures()[$this->ipAddr]); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * Test failed attempt behind a trusted proxy IP but without IP forwarding. | ||
124 | */ | ||
125 | public function testHandleFailedAttemptBehindNotConfiguredProxy() | ||
126 | { | ||
127 | $server = [ | ||
128 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
129 | ]; | ||
130 | $this->assertCount(0, $this->banManager->getFailures()); | ||
131 | |||
132 | $this->banManager->handleFailedAttempt($server); | ||
133 | $this->assertCount(0, $this->banManager->getFailures()); | ||
134 | |||
135 | $this->banManager->handleFailedAttempt($server); | ||
136 | $this->assertCount(0, $this->banManager->getFailures()); | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Test failed attempts with multiple direct IP. | ||
141 | */ | ||
142 | public function testHandleFailedAttemptMultipleIp() | ||
143 | { | ||
144 | $this->assertCount(0, $this->banManager->getFailures()); | ||
145 | $this->banManager->handleFailedAttempt($this->server); | ||
146 | $this->server['REMOTE_ADDR'] = '1.2.3.4'; | ||
147 | $this->banManager->handleFailedAttempt($this->server); | ||
148 | $this->banManager->handleFailedAttempt($this->server); | ||
149 | $this->assertCount(2, $this->banManager->getFailures()); | ||
150 | $this->assertEquals(1, $this->banManager->getFailures()[$this->ipAddr]); | ||
151 | $this->assertEquals(2, $this->banManager->getFailures()[$this->server['REMOTE_ADDR']]); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * Test clear failure for provided IP without any additional data. | ||
156 | */ | ||
157 | public function testClearFailuresEmpty() | ||
158 | { | ||
159 | $this->assertCount(0, $this->banManager->getFailures()); | ||
160 | $this->banManager->clearFailures($this->server); | ||
161 | $this->assertCount(0, $this->banManager->getFailures()); | ||
162 | } | ||
163 | |||
164 | /** | ||
165 | * Test clear failure for provided IP with failed attempts. | ||
166 | */ | ||
167 | public function testClearFailuresFromFile() | ||
168 | { | ||
169 | FileUtils::writeFlatDB( | ||
170 | $this->banFile, | ||
171 | [ | ||
172 | 'failures' => [ | ||
173 | $this->ipAddr => 2, | ||
174 | $ip = '1.2.3.4' => 1, | ||
175 | ] | ||
176 | ] | ||
177 | ); | ||
178 | $this->banManager = $this->getNewBanManagerInstance(); | ||
179 | |||
180 | $this->assertCount(2, $this->banManager->getFailures()); | ||
181 | $this->banManager->clearFailures($this->server); | ||
182 | $this->assertCount(1, $this->banManager->getFailures()); | ||
183 | $this->assertEquals(1, $this->banManager->getFailures()[$ip]); | ||
184 | } | ||
185 | |||
186 | /** | ||
187 | * Test clear failure for provided IP with failed attempts, behind a reverse proxy. | ||
188 | */ | ||
189 | public function testClearFailuresFromFileBehindProxy() | ||
190 | { | ||
191 | $server = [ | ||
192 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
193 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, | ||
194 | ]; | ||
195 | |||
196 | FileUtils::writeFlatDB( | ||
197 | $this->banFile, | ||
198 | [ | ||
199 | 'failures' => [ | ||
200 | $this->ipAddr => 2, | ||
201 | $ip = '1.2.3.4' => 1, | ||
202 | ] | ||
203 | ] | ||
204 | ); | ||
205 | $this->banManager = $this->getNewBanManagerInstance(); | ||
206 | |||
207 | $this->assertCount(2, $this->banManager->getFailures()); | ||
208 | $this->banManager->clearFailures($server); | ||
209 | $this->assertCount(1, $this->banManager->getFailures()); | ||
210 | $this->assertEquals(1, $this->banManager->getFailures()[$ip]); | ||
211 | } | ||
212 | |||
213 | /** | ||
214 | * Test clear failure for provided IP with failed attempts, | ||
215 | * behind a reverse proxy without forwarding. | ||
216 | */ | ||
217 | public function testClearFailuresFromFileBehindNotConfiguredProxy() | ||
218 | { | ||
219 | $server = [ | ||
220 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
221 | ]; | ||
222 | |||
223 | FileUtils::writeFlatDB( | ||
224 | $this->banFile, | ||
225 | [ | ||
226 | 'failures' => [ | ||
227 | $this->ipAddr => 2, | ||
228 | $ip = '1.2.3.4' => 1, | ||
229 | ] | ||
230 | ] | ||
231 | ); | ||
232 | $this->banManager = $this->getNewBanManagerInstance(); | ||
233 | |||
234 | $this->assertCount(2, $this->banManager->getFailures()); | ||
235 | $this->banManager->clearFailures($server); | ||
236 | $this->assertCount(2, $this->banManager->getFailures()); | ||
237 | } | ||
238 | |||
239 | /** | ||
240 | * Test isBanned without any data | ||
241 | */ | ||
242 | public function testIsBannedEmpty() | ||
243 | { | ||
244 | $this->assertFalse($this->banManager->isBanned($this->server)); | ||
245 | } | ||
246 | |||
247 | /** | ||
248 | * Test isBanned with banned IP from file data | ||
249 | */ | ||
250 | public function testBannedFromFile() | ||
251 | { | ||
252 | FileUtils::writeFlatDB( | ||
253 | $this->banFile, | ||
254 | [ | ||
255 | 'bans' => [ | ||
256 | $this->ipAddr => time() + 10, | ||
257 | ] | ||
258 | ] | ||
259 | ); | ||
260 | $this->banManager = $this->getNewBanManagerInstance(); | ||
261 | |||
262 | $this->assertCount(1, $this->banManager->getBans()); | ||
263 | $this->assertTrue($this->banManager->isBanned($this->server)); | ||
264 | } | ||
265 | |||
266 | /** | ||
267 | * Test isBanned with banned IP from file data behind a reverse proxy | ||
268 | */ | ||
269 | public function testBannedFromFileBehindProxy() | ||
270 | { | ||
271 | $server = [ | ||
272 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
273 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, | ||
274 | ]; | ||
275 | FileUtils::writeFlatDB( | ||
276 | $this->banFile, | ||
277 | [ | ||
278 | 'bans' => [ | ||
279 | $this->ipAddr => time() + 10, | ||
280 | ] | ||
281 | ] | ||
282 | ); | ||
283 | $this->banManager = $this->getNewBanManagerInstance(); | ||
284 | |||
285 | $this->assertCount(1, $this->banManager->getBans()); | ||
286 | $this->assertTrue($this->banManager->isBanned($server)); | ||
287 | } | ||
288 | |||
289 | /** | ||
290 | * Test isBanned with banned IP from file data behind a reverse proxy, | ||
291 | * without IP forwarding | ||
292 | */ | ||
293 | public function testBannedFromFileBehindNotConfiguredProxy() | ||
294 | { | ||
295 | $server = [ | ||
296 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
297 | ]; | ||
298 | FileUtils::writeFlatDB( | ||
299 | $this->banFile, | ||
300 | [ | ||
301 | 'bans' => [ | ||
302 | $this->ipAddr => time() + 10, | ||
303 | ] | ||
304 | ] | ||
305 | ); | ||
306 | $this->banManager = $this->getNewBanManagerInstance(); | ||
307 | |||
308 | $this->assertCount(1, $this->banManager->getBans()); | ||
309 | $this->assertFalse($this->banManager->isBanned($server)); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Test isBanned with an expired ban | ||
314 | */ | ||
315 | public function testLiftBan() | ||
316 | { | ||
317 | FileUtils::writeFlatDB( | ||
318 | $this->banFile, | ||
319 | [ | ||
320 | 'bans' => [ | ||
321 | $this->ipAddr => time() - 10, | ||
322 | ] | ||
323 | ] | ||
324 | ); | ||
325 | $this->banManager = $this->getNewBanManagerInstance(); | ||
326 | |||
327 | $this->assertCount(1, $this->banManager->getBans()); | ||
328 | $this->assertFalse($this->banManager->isBanned($this->server)); | ||
329 | } | ||
330 | |||
331 | /** | ||
332 | * Test isBanned with an expired ban behind a reverse proxy | ||
333 | */ | ||
334 | public function testLiftBanBehindProxy() | ||
335 | { | ||
336 | $server = [ | ||
337 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
338 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, | ||
339 | ]; | ||
340 | |||
341 | FileUtils::writeFlatDB( | ||
342 | $this->banFile, | ||
343 | [ | ||
344 | 'bans' => [ | ||
345 | $this->ipAddr => time() - 10, | ||
346 | ] | ||
347 | ] | ||
348 | ); | ||
349 | $this->banManager = $this->getNewBanManagerInstance(); | ||
350 | |||
351 | $this->assertCount(1, $this->banManager->getBans()); | ||
352 | $this->assertFalse($this->banManager->isBanned($server)); | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * Test isBanned with an expired ban behind a reverse proxy | ||
357 | */ | ||
358 | public function testLiftBanBehindNotConfiguredProxy() | ||
359 | { | ||
360 | $server = [ | ||
361 | 'REMOTE_ADDR' => $this->trustedProxy, | ||
362 | ]; | ||
363 | |||
364 | FileUtils::writeFlatDB( | ||
365 | $this->banFile, | ||
366 | [ | ||
367 | 'bans' => [ | ||
368 | $this->ipAddr => time() - 10, | ||
369 | ] | ||
370 | ] | ||
371 | ); | ||
372 | $this->banManager = $this->getNewBanManagerInstance(); | ||
373 | |||
374 | $this->assertCount(1, $this->banManager->getBans()); | ||
375 | $this->assertFalse($this->banManager->isBanned($server)); | ||
376 | } | ||
377 | |||
378 | /** | ||
379 | * Build a new instance of BanManager, which will reread the ban file. | ||
380 | * | ||
381 | * @return BanManager instance | ||
382 | */ | ||
383 | protected function getNewBanManagerInstance() | ||
384 | { | ||
385 | return new BanManager( | ||
386 | [$this->trustedProxy], | ||
387 | 3, | ||
388 | 1800, | ||
389 | $this->banFile, | ||
390 | $this->logFile | ||
391 | ); | ||
392 | } | ||
393 | } | ||
diff --git a/tests/security/LoginManagerTest.php b/tests/security/LoginManagerTest.php index f26cd1eb..eef0f22a 100644 --- a/tests/security/LoginManagerTest.php +++ b/tests/security/LoginManagerTest.php | |||
@@ -2,7 +2,8 @@ | |||
2 | namespace Shaarli\Security; | 2 | namespace Shaarli\Security; |
3 | 3 | ||
4 | require_once 'tests/utils/FakeConfigManager.php'; | 4 | require_once 'tests/utils/FakeConfigManager.php'; |
5 | use \PHPUnit\Framework\TestCase; | 5 | |
6 | use PHPUnit\Framework\TestCase; | ||
6 | 7 | ||
7 | /** | 8 | /** |
8 | * Test coverage for LoginManager | 9 | * Test coverage for LoginManager |
@@ -74,54 +75,27 @@ class LoginManagerTest extends TestCase | |||
74 | 'credentials.salt' => $this->salt, | 75 | 'credentials.salt' => $this->salt, |
75 | 'resource.ban_file' => $this->banFile, | 76 | 'resource.ban_file' => $this->banFile, |
76 | 'resource.log' => $this->logFile, | 77 | 'resource.log' => $this->logFile, |
77 | 'security.ban_after' => 4, | 78 | 'security.ban_after' => 2, |
78 | 'security.ban_duration' => 3600, | 79 | 'security.ban_duration' => 3600, |
79 | 'security.trusted_proxies' => [$this->trustedProxy], | 80 | 'security.trusted_proxies' => [$this->trustedProxy], |
80 | ]); | 81 | ]); |
81 | 82 | ||
82 | $this->cookie = []; | 83 | $this->cookie = []; |
83 | |||
84 | $this->globals = &$GLOBALS; | ||
85 | unset($this->globals['IPBANS']); | ||
86 | |||
87 | $this->session = []; | 84 | $this->session = []; |
88 | 85 | ||
89 | $this->sessionManager = new SessionManager($this->session, $this->configManager); | 86 | $this->sessionManager = new SessionManager($this->session, $this->configManager); |
90 | $this->loginManager = new LoginManager($this->globals, $this->configManager, $this->sessionManager); | 87 | $this->loginManager = new LoginManager($this->configManager, $this->sessionManager); |
91 | $this->server['REMOTE_ADDR'] = $this->ipAddr; | 88 | $this->server['REMOTE_ADDR'] = $this->ipAddr; |
92 | } | 89 | } |
93 | 90 | ||
94 | /** | 91 | /** |
95 | * Wipe test resources | ||
96 | */ | ||
97 | public function tearDown() | ||
98 | { | ||
99 | unset($this->globals['IPBANS']); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * Instantiate a LoginManager and load ban records | ||
104 | */ | ||
105 | public function testReadBanFile() | ||
106 | { | ||
107 | file_put_contents( | ||
108 | $this->banFile, | ||
109 | "<?php\n\$GLOBALS['IPBANS']=array('FAILURES' => array('127.0.0.1' => 99));\n?>" | ||
110 | ); | ||
111 | new LoginManager($this->globals, $this->configManager, null); | ||
112 | $this->assertEquals(99, $this->globals['IPBANS']['FAILURES']['127.0.0.1']); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * Record a failed login attempt | 92 | * Record a failed login attempt |
117 | */ | 93 | */ |
118 | public function testHandleFailedLogin() | 94 | public function testHandleFailedLogin() |
119 | { | 95 | { |
120 | $this->loginManager->handleFailedLogin($this->server); | 96 | $this->loginManager->handleFailedLogin($this->server); |
121 | $this->assertEquals(1, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
122 | |||
123 | $this->loginManager->handleFailedLogin($this->server); | 97 | $this->loginManager->handleFailedLogin($this->server); |
124 | $this->assertEquals(2, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | 98 | $this->assertFalse($this->loginManager->canLogin($this->server)); |
125 | } | 99 | } |
126 | 100 | ||
127 | /** | 101 | /** |
@@ -134,10 +108,8 @@ class LoginManagerTest extends TestCase | |||
134 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, | 108 | 'HTTP_X_FORWARDED_FOR' => $this->ipAddr, |
135 | ]; | 109 | ]; |
136 | $this->loginManager->handleFailedLogin($server); | 110 | $this->loginManager->handleFailedLogin($server); |
137 | $this->assertEquals(1, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
138 | |||
139 | $this->loginManager->handleFailedLogin($server); | 111 | $this->loginManager->handleFailedLogin($server); |
140 | $this->assertEquals(2, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | 112 | $this->assertFalse($this->loginManager->canLogin($server)); |
141 | } | 113 | } |
142 | 114 | ||
143 | /** | 115 | /** |
@@ -149,39 +121,8 @@ class LoginManagerTest extends TestCase | |||
149 | 'REMOTE_ADDR' => $this->trustedProxy, | 121 | 'REMOTE_ADDR' => $this->trustedProxy, |
150 | ]; | 122 | ]; |
151 | $this->loginManager->handleFailedLogin($server); | 123 | $this->loginManager->handleFailedLogin($server); |
152 | $this->assertFalse(isset($this->globals['IPBANS']['FAILURES'][$this->ipAddr])); | ||
153 | |||
154 | $this->loginManager->handleFailedLogin($server); | 124 | $this->loginManager->handleFailedLogin($server); |
155 | $this->assertFalse(isset($this->globals['IPBANS']['FAILURES'][$this->ipAddr])); | 125 | $this->assertTrue($this->loginManager->canLogin($server)); |
156 | } | ||
157 | |||
158 | /** | ||
159 | * Record a failed login attempt and ban the IP after too many failures | ||
160 | */ | ||
161 | public function testHandleFailedLoginBanIp() | ||
162 | { | ||
163 | $this->loginManager->handleFailedLogin($this->server); | ||
164 | $this->assertEquals(1, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
165 | $this->assertTrue($this->loginManager->canLogin($this->server)); | ||
166 | |||
167 | $this->loginManager->handleFailedLogin($this->server); | ||
168 | $this->assertEquals(2, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
169 | $this->assertTrue($this->loginManager->canLogin($this->server)); | ||
170 | |||
171 | $this->loginManager->handleFailedLogin($this->server); | ||
172 | $this->assertEquals(3, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
173 | $this->assertTrue($this->loginManager->canLogin($this->server)); | ||
174 | |||
175 | $this->loginManager->handleFailedLogin($this->server); | ||
176 | $this->assertEquals(4, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
177 | $this->assertFalse($this->loginManager->canLogin($this->server)); | ||
178 | |||
179 | // handleFailedLogin is not supposed to be called at this point: | ||
180 | // - no login form should be displayed once an IP has been banned | ||
181 | // - yet this could happen when using custom templates / scripts | ||
182 | $this->loginManager->handleFailedLogin($this->server); | ||
183 | $this->assertEquals(5, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
184 | $this->assertFalse($this->loginManager->canLogin($this->server)); | ||
185 | } | 126 | } |
186 | 127 | ||
187 | /** | 128 | /** |
@@ -201,14 +142,11 @@ class LoginManagerTest extends TestCase | |||
201 | public function testHandleSuccessfulLoginAfterFailure() | 142 | public function testHandleSuccessfulLoginAfterFailure() |
202 | { | 143 | { |
203 | $this->loginManager->handleFailedLogin($this->server); | 144 | $this->loginManager->handleFailedLogin($this->server); |
204 | $this->loginManager->handleFailedLogin($this->server); | ||
205 | $this->assertEquals(2, $this->globals['IPBANS']['FAILURES'][$this->ipAddr]); | ||
206 | $this->assertTrue($this->loginManager->canLogin($this->server)); | 145 | $this->assertTrue($this->loginManager->canLogin($this->server)); |
207 | 146 | ||
208 | $this->loginManager->handleSuccessfulLogin($this->server); | 147 | $this->loginManager->handleSuccessfulLogin($this->server); |
148 | $this->loginManager->handleFailedLogin($this->server); | ||
209 | $this->assertTrue($this->loginManager->canLogin($this->server)); | 149 | $this->assertTrue($this->loginManager->canLogin($this->server)); |
210 | $this->assertFalse(isset($this->globals['IPBANS']['FAILURES'][$this->ipAddr])); | ||
211 | $this->assertFalse(isset($this->globals['IPBANS']['BANS'][$this->ipAddr])); | ||
212 | } | 150 | } |
213 | 151 | ||
214 | /** | 152 | /** |
@@ -220,41 +158,28 @@ class LoginManagerTest extends TestCase | |||
220 | } | 158 | } |
221 | 159 | ||
222 | /** | 160 | /** |
223 | * The IP is banned | 161 | * Generate a token depending on the user credentials and client IP |
224 | */ | ||
225 | public function testCanLoginIpBanned() | ||
226 | { | ||
227 | // ban the IP for an hour | ||
228 | $this->globals['IPBANS']['FAILURES'][$this->ipAddr] = 10; | ||
229 | $this->globals['IPBANS']['BANS'][$this->ipAddr] = time() + 3600; | ||
230 | |||
231 | $this->assertFalse($this->loginManager->canLogin($this->server)); | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * The IP is banned, and the ban duration is over | ||
236 | */ | 162 | */ |
237 | public function testCanLoginIpBanExpired() | 163 | public function testGenerateStaySignedInToken() |
238 | { | 164 | { |
239 | // ban the IP for an hour | 165 | $this->loginManager->generateStaySignedInToken($this->clientIpAddress); |
240 | $this->globals['IPBANS']['FAILURES'][$this->ipAddr] = 10; | ||
241 | $this->globals['IPBANS']['BANS'][$this->ipAddr] = time() + 3600; | ||
242 | $this->assertFalse($this->loginManager->canLogin($this->server)); | ||
243 | 166 | ||
244 | // lift the ban | 167 | $this->assertEquals( |
245 | $this->globals['IPBANS']['BANS'][$this->ipAddr] = time() - 3600; | 168 | sha1($this->passwordHash . $this->clientIpAddress . $this->salt), |
246 | $this->assertTrue($this->loginManager->canLogin($this->server)); | 169 | $this->loginManager->getStaySignedInToken() |
170 | ); | ||
247 | } | 171 | } |
248 | 172 | ||
249 | /** | 173 | /** |
250 | * Generate a token depending on the user credentials and client IP | 174 | * Generate a token depending on the user credentials with session protected disabled |
251 | */ | 175 | */ |
252 | public function testGenerateStaySignedInToken() | 176 | public function testGenerateStaySignedInTokenSessionProtectionDisabled() |
253 | { | 177 | { |
178 | $this->configManager->set('security.session_protection_disabled', true); | ||
254 | $this->loginManager->generateStaySignedInToken($this->clientIpAddress); | 179 | $this->loginManager->generateStaySignedInToken($this->clientIpAddress); |
255 | 180 | ||
256 | $this->assertEquals( | 181 | $this->assertEquals( |
257 | sha1($this->passwordHash . $this->clientIpAddress . $this->salt), | 182 | sha1($this->passwordHash . $this->salt), |
258 | $this->loginManager->getStaySignedInToken() | 183 | $this->loginManager->getStaySignedInToken() |
259 | ); | 184 | ); |
260 | } | 185 | } |
@@ -267,7 +192,7 @@ class LoginManagerTest extends TestCase | |||
267 | $configManager = new \FakeConfigManager([ | 192 | $configManager = new \FakeConfigManager([ |
268 | 'resource.ban_file' => $this->banFile, | 193 | 'resource.ban_file' => $this->banFile, |
269 | ]); | 194 | ]); |
270 | $loginManager = new LoginManager($this->globals, $configManager, null); | 195 | $loginManager = new LoginManager($configManager, null); |
271 | $loginManager->checkLoginState([], ''); | 196 | $loginManager->checkLoginState([], ''); |
272 | 197 | ||
273 | $this->assertFalse($loginManager->isLoggedIn()); | 198 | $this->assertFalse($loginManager->isLoggedIn()); |
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'; | |||
5 | require_once 'tests/utils/ReferenceSessionIdHashes.php'; | 5 | require_once 'tests/utils/ReferenceSessionIdHashes.php'; |
6 | ReferenceSessionIdHashes::genAllHashes(); | 6 | ReferenceSessionIdHashes::genAllHashes(); |
7 | 7 | ||
8 | use \Shaarli\Security\SessionManager; | 8 | use PHPUnit\Framework\TestCase; |
9 | use \PHPUnit\Framework\TestCase; | 9 | use 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 |
2 | namespace Shaarli\Updater; | ||
2 | 3 | ||
3 | require_once 'application/Updater.php'; | 4 | use Exception; |
5 | use ReflectionClass; | ||
6 | use ReflectionMethod; | ||
7 | use Shaarli\Bookmark\LinkDB; | ||
8 | use 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 | */ |
9 | class DummyUpdater extends Updater | 14 | class DummyUpdater extends Updater |
10 | { | 15 | { |
diff --git a/tests/Updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index c4a6e7ef..93bc86c1 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php | |||
@@ -1,17 +1,24 @@ | |||
1 | <?php | 1 | <?php |
2 | namespace Shaarli\Updater; | ||
3 | |||
4 | use DateTime; | ||
5 | use Exception; | ||
6 | use Shaarli\Bookmark\LinkDB; | ||
2 | use Shaarli\Config\ConfigJson; | 7 | use Shaarli\Config\ConfigJson; |
3 | use Shaarli\Config\ConfigManager; | 8 | use Shaarli\Config\ConfigManager; |
4 | use Shaarli\Config\ConfigPhp; | 9 | use Shaarli\Config\ConfigPhp; |
5 | use Shaarli\Thumbnailer; | 10 | use Shaarli\Thumbnailer; |
6 | 11 | ||
7 | require_once 'tests/Updater/DummyUpdater.php'; | 12 | require_once 'application/updater/UpdaterUtils.php'; |
13 | require_once 'tests/updater/DummyUpdater.php'; | ||
14 | require_once 'tests/utils/ReferenceLinkDB.php'; | ||
8 | require_once 'inc/rain.tpl.class.php'; | 15 | require_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 | */ |
14 | class UpdaterTest extends PHPUnit_Framework_TestCase | 21 | class 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 | ||
@@ -280,17 +287,14 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
280 | $this->conf = new ConfigManager($sandbox); | 287 | $this->conf = new ConfigManager($sandbox); |
281 | $title = '<script>alert("title");</script>'; | 288 | $title = '<script>alert("title");</script>'; |
282 | $headerLink = '<script>alert("header_link");</script>'; | 289 | $headerLink = '<script>alert("header_link");</script>'; |
283 | $redirectorUrl = '<script>alert("redirector");</script>'; | ||
284 | $this->conf->set('general.title', $title); | 290 | $this->conf->set('general.title', $title); |
285 | $this->conf->set('general.header_link', $headerLink); | 291 | $this->conf->set('general.header_link', $headerLink); |
286 | $this->conf->set('redirector.url', $redirectorUrl); | ||
287 | $updater = new Updater(array(), array(), $this->conf, true); | 292 | $updater = new Updater(array(), array(), $this->conf, true); |
288 | $done = $updater->updateMethodEscapeUnescapedConfig(); | 293 | $done = $updater->updateMethodEscapeUnescapedConfig(); |
289 | $this->assertTrue($done); | 294 | $this->assertTrue($done); |
290 | $this->conf->reload(); | 295 | $this->conf->reload(); |
291 | $this->assertEquals(escape($title), $this->conf->get('general.title')); | 296 | $this->assertEquals(escape($title), $this->conf->get('general.title')); |
292 | $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link')); | 297 | $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link')); |
293 | $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url')); | ||
294 | unlink($sandbox . '.json.php'); | 298 | unlink($sandbox . '.json.php'); |
295 | } | 299 | } |
296 | 300 | ||
@@ -362,7 +366,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
362 | 'private' => true, | 366 | 'private' => true, |
363 | ), | 367 | ), |
364 | ); | 368 | ); |
365 | $refDB = new ReferenceLinkDB(); | 369 | $refDB = new \ReferenceLinkDB(); |
366 | $refDB->setLinks($links); | 370 | $refDB->setLinks($links); |
367 | $refDB->write(self::$testDatastore); | 371 | $refDB->write(self::$testDatastore); |
368 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 372 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
@@ -426,7 +430,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
426 | */ | 430 | */ |
427 | public function testDatastoreIdsNothingToDo() | 431 | public function testDatastoreIdsNothingToDo() |
428 | { | 432 | { |
429 | $refDB = new ReferenceLinkDB(); | 433 | $refDB = new \ReferenceLinkDB(); |
430 | $refDB->write(self::$testDatastore); | 434 | $refDB->write(self::$testDatastore); |
431 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 435 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
432 | 436 | ||
@@ -700,7 +704,6 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
700 | } | 704 | } |
701 | 705 | ||
702 | /** | 706 | /** |
703 | <<<<<<< HEAD | ||
704 | * Test updateMethodWebThumbnailer with thumbnails enabled. | 707 | * Test updateMethodWebThumbnailer with thumbnails enabled. |
705 | */ | 708 | */ |
706 | public function testUpdateMethodWebThumbnailerEnabled() | 709 | public function testUpdateMethodWebThumbnailerEnabled() |
@@ -763,7 +766,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
763 | 1 => ['id' => 1] + $blank, | 766 | 1 => ['id' => 1] + $blank, |
764 | 2 => ['id' => 2] + $blank, | 767 | 2 => ['id' => 2] + $blank, |
765 | ]; | 768 | ]; |
766 | $refDB = new ReferenceLinkDB(); | 769 | $refDB = new \ReferenceLinkDB(); |
767 | $refDB->setLinks($links); | 770 | $refDB->setLinks($links); |
768 | $refDB->write(self::$testDatastore); | 771 | $refDB->write(self::$testDatastore); |
769 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 772 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
@@ -794,7 +797,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
794 | 1 => ['id' => 1, 'sticky' => true] + $blank, | 797 | 1 => ['id' => 1, 'sticky' => true] + $blank, |
795 | 2 => ['id' => 2] + $blank, | 798 | 2 => ['id' => 2] + $blank, |
796 | ]; | 799 | ]; |
797 | $refDB = new ReferenceLinkDB(); | 800 | $refDB = new \ReferenceLinkDB(); |
798 | $refDB->setLinks($links); | 801 | $refDB->setLinks($links); |
799 | $refDB->write(self::$testDatastore); | 802 | $refDB->write(self::$testDatastore); |
800 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 803 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
@@ -805,4 +808,19 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
805 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 808 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
806 | $this->assertTrue($linkDB[1]['sticky']); | 809 | $this->assertTrue($linkDB[1]['sticky']); |
807 | } | 810 | } |
811 | |||
812 | /** | ||
813 | * Test updateMethodRemoveRedirector(). | ||
814 | */ | ||
815 | public function testUpdateRemoveRedirector() | ||
816 | { | ||
817 | $sandboxConf = 'sandbox/config'; | ||
818 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
819 | $this->conf = new ConfigManager($sandboxConf); | ||
820 | $updater = new Updater([], null, $this->conf, true); | ||
821 | $this->assertTrue($updater->updateMethodRemoveRedirector()); | ||
822 | $this->assertFalse($this->conf->exists('redirector')); | ||
823 | $this->conf = new ConfigManager($sandboxConf); | ||
824 | $this->assertFalse($this->conf->exists('redirector')); | ||
825 | } | ||
808 | } | 826 | } |
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 | */ | ||
14 | function 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 | */ | ||
32 | function 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 | */ | ||
50 | function 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 | */ | ||
68 | function 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 | */ | ||
86 | function 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 | |||
3 | namespace Shaarli; | ||
4 | |||
5 | /** | ||
6 | * Fake ApplicationUtils class to avoid HTTP requests | ||
7 | */ | ||
8 | class 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 | ||
3 | use Shaarli\FileUtils; | ||
4 | use 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 | |||
3 | use 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'; |