diff options
Diffstat (limited to 'tests/api')
-rw-r--r-- | tests/api/ApiMiddlewareTest.php | 3 | ||||
-rw-r--r-- | tests/api/ApiUtilsTest.php | 7 | ||||
-rw-r--r-- | tests/api/controllers/history/HistoryTest.php | 29 | ||||
-rw-r--r-- | tests/api/controllers/info/InfoTest.php | 9 | ||||
-rw-r--r-- | tests/api/controllers/links/DeleteLinkTest.php | 18 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinkIdTest.php | 7 | ||||
-rw-r--r-- | tests/api/controllers/links/GetLinksTest.php | 31 | ||||
-rw-r--r-- | tests/api/controllers/links/PostLinkTest.php | 28 | ||||
-rw-r--r-- | tests/api/controllers/links/PutLinkTest.php | 26 | ||||
-rw-r--r-- | tests/api/controllers/tags/DeleteTagTest.php | 22 | ||||
-rw-r--r-- | tests/api/controllers/tags/GetTagNameTest.php | 6 | ||||
-rw-r--r-- | tests/api/controllers/tags/GetTagsTest.php | 8 | ||||
-rw-r--r-- | tests/api/controllers/tags/PutTagTest.php | 18 |
13 files changed, 111 insertions, 101 deletions
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 62baf4c5..ea0ae500 100644 --- a/tests/api/ApiUtilsTest.php +++ b/tests/api/ApiUtilsTest.php | |||
@@ -2,13 +2,12 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api; | 3 | namespace Shaarli\Api; |
4 | 4 | ||
5 | use Shaarli\Base64Url; | 5 | use Shaarli\Http\Base64Url; |
6 | |||
7 | 6 | ||
8 | /** | 7 | /** |
9 | * Class ApiUtilsTest | 8 | * Class ApiUtilsTest |
10 | */ | 9 | */ |
11 | class ApiUtilsTest extends \PHPUnit_Framework_TestCase | 10 | class ApiUtilsTest extends \PHPUnit\Framework\TestCase |
12 | { | 11 | { |
13 | /** | 12 | /** |
14 | * Force the timezone for ISO datetimes. | 13 | * Force the timezone for ISO datetimes. |
@@ -34,7 +33,7 @@ class ApiUtilsTest extends \PHPUnit_Framework_TestCase | |||
34 | $payload = Base64Url::encode('{ | 33 | $payload = Base64Url::encode('{ |
35 | "iat": '. time() .' | 34 | "iat": '. time() .' |
36 | }'); | 35 | }'); |
37 | $signature = Base64Url::encode(hash_hmac('sha512', $header .'.'. $payload , $secret, true)); | 36 | $signature = Base64Url::encode(hash_hmac('sha512', $header .'.'. $payload, $secret, true)); |
38 | return $header .'.'. $payload .'.'. $signature; | 37 | return $header .'.'. $payload .'.'. $signature; |
39 | } | 38 | } |
40 | 39 | ||
diff --git a/tests/api/controllers/history/HistoryTest.php b/tests/api/controllers/history/HistoryTest.php index 61046d97..e287f239 100644 --- a/tests/api/controllers/history/HistoryTest.php +++ b/tests/api/controllers/history/HistoryTest.php | |||
@@ -1,10 +1,9 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | |||
4 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
5 | 4 | ||
6 | |||
7 | use Shaarli\Config\ConfigManager; | 5 | use Shaarli\Config\ConfigManager; |
6 | use Shaarli\History; | ||
8 | use Slim\Container; | 7 | use Slim\Container; |
9 | use Slim\Http\Environment; | 8 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 9 | use Slim\Http\Request; |
@@ -12,7 +11,7 @@ use Slim\Http\Response; | |||
12 | 11 | ||
13 | require_once 'tests/utils/ReferenceHistory.php'; | 12 | require_once 'tests/utils/ReferenceHistory.php'; |
14 | 13 | ||
15 | class HistoryTest extends \PHPUnit_Framework_TestCase | 14 | class HistoryTest extends \PHPUnit\Framework\TestCase |
16 | { | 15 | { |
17 | /** | 16 | /** |
18 | * @var string datastore to test write operations | 17 | * @var string datastore to test write operations |
@@ -35,7 +34,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
35 | protected $container; | 34 | protected $container; |
36 | 35 | ||
37 | /** | 36 | /** |
38 | * @var History controller instance. | 37 | * @var HistoryController controller instance. |
39 | */ | 38 | */ |
40 | protected $controller; | 39 | protected $controller; |
41 | 40 | ||
@@ -50,9 +49,9 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
50 | $this->container = new Container(); | 49 | $this->container = new Container(); |
51 | $this->container['conf'] = $this->conf; | 50 | $this->container['conf'] = $this->conf; |
52 | $this->container['db'] = true; | 51 | $this->container['db'] = true; |
53 | $this->container['history'] = new \History(self::$testHistory); | 52 | $this->container['history'] = new History(self::$testHistory); |
54 | 53 | ||
55 | $this->controller = new History($this->container); | 54 | $this->controller = new HistoryController($this->container); |
56 | } | 55 | } |
57 | 56 | ||
58 | /** | 57 | /** |
@@ -79,35 +78,35 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
79 | 78 | ||
80 | $this->assertEquals($this->refHistory->count(), count($data)); | 79 | $this->assertEquals($this->refHistory->count(), count($data)); |
81 | 80 | ||
82 | $this->assertEquals(\History::DELETED, $data[0]['event']); | 81 | $this->assertEquals(History::DELETED, $data[0]['event']); |
83 | $this->assertEquals( | 82 | $this->assertEquals( |
84 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), | 83 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), |
85 | $data[0]['datetime'] | 84 | $data[0]['datetime'] |
86 | ); | 85 | ); |
87 | $this->assertEquals(124, $data[0]['id']); | 86 | $this->assertEquals(124, $data[0]['id']); |
88 | 87 | ||
89 | $this->assertEquals(\History::SETTINGS, $data[1]['event']); | 88 | $this->assertEquals(History::SETTINGS, $data[1]['event']); |
90 | $this->assertEquals( | 89 | $this->assertEquals( |
91 | \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), | 90 | \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), |
92 | $data[1]['datetime'] | 91 | $data[1]['datetime'] |
93 | ); | 92 | ); |
94 | $this->assertNull($data[1]['id']); | 93 | $this->assertNull($data[1]['id']); |
95 | 94 | ||
96 | $this->assertEquals(\History::UPDATED, $data[2]['event']); | 95 | $this->assertEquals(History::UPDATED, $data[2]['event']); |
97 | $this->assertEquals( | 96 | $this->assertEquals( |
98 | \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), | 97 | \DateTime::createFromFormat('Ymd_His', '20170301_121214')->format(\DateTime::ATOM), |
99 | $data[2]['datetime'] | 98 | $data[2]['datetime'] |
100 | ); | 99 | ); |
101 | $this->assertEquals(123, $data[2]['id']); | 100 | $this->assertEquals(123, $data[2]['id']); |
102 | 101 | ||
103 | $this->assertEquals(\History::CREATED, $data[3]['event']); | 102 | $this->assertEquals(History::CREATED, $data[3]['event']); |
104 | $this->assertEquals( | 103 | $this->assertEquals( |
105 | \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), | 104 | \DateTime::createFromFormat('Ymd_His', '20170201_121214')->format(\DateTime::ATOM), |
106 | $data[3]['datetime'] | 105 | $data[3]['datetime'] |
107 | ); | 106 | ); |
108 | $this->assertEquals(124, $data[3]['id']); | 107 | $this->assertEquals(124, $data[3]['id']); |
109 | 108 | ||
110 | $this->assertEquals(\History::CREATED, $data[4]['event']); | 109 | $this->assertEquals(History::CREATED, $data[4]['event']); |
111 | $this->assertEquals( | 110 | $this->assertEquals( |
112 | \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), | 111 | \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), |
113 | $data[4]['datetime'] | 112 | $data[4]['datetime'] |
@@ -132,7 +131,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
132 | 131 | ||
133 | $this->assertEquals(1, count($data)); | 132 | $this->assertEquals(1, count($data)); |
134 | 133 | ||
135 | $this->assertEquals(\History::DELETED, $data[0]['event']); | 134 | $this->assertEquals(History::DELETED, $data[0]['event']); |
136 | $this->assertEquals( | 135 | $this->assertEquals( |
137 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), | 136 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), |
138 | $data[0]['datetime'] | 137 | $data[0]['datetime'] |
@@ -157,7 +156,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
157 | 156 | ||
158 | $this->assertEquals(1, count($data)); | 157 | $this->assertEquals(1, count($data)); |
159 | 158 | ||
160 | $this->assertEquals(\History::CREATED, $data[0]['event']); | 159 | $this->assertEquals(History::CREATED, $data[0]['event']); |
161 | $this->assertEquals( | 160 | $this->assertEquals( |
162 | \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), | 161 | \DateTime::createFromFormat('Ymd_His', '20170101_121212')->format(\DateTime::ATOM), |
163 | $data[0]['datetime'] | 162 | $data[0]['datetime'] |
@@ -182,7 +181,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
182 | 181 | ||
183 | $this->assertEquals(1, count($data)); | 182 | $this->assertEquals(1, count($data)); |
184 | 183 | ||
185 | $this->assertEquals(\History::DELETED, $data[0]['event']); | 184 | $this->assertEquals(History::DELETED, $data[0]['event']); |
186 | $this->assertEquals( | 185 | $this->assertEquals( |
187 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), | 186 | \DateTime::createFromFormat('Ymd_His', '20170303_121216')->format(\DateTime::ATOM), |
188 | $data[0]['datetime'] | 187 | $data[0]['datetime'] |
@@ -207,7 +206,7 @@ class HistoryTest extends \PHPUnit_Framework_TestCase | |||
207 | 206 | ||
208 | $this->assertEquals(1, count($data)); | 207 | $this->assertEquals(1, count($data)); |
209 | 208 | ||
210 | $this->assertEquals(\History::SETTINGS, $data[0]['event']); | 209 | $this->assertEquals(History::SETTINGS, $data[0]['event']); |
211 | $this->assertEquals( | 210 | $this->assertEquals( |
212 | \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), | 211 | \DateTime::createFromFormat('Ymd_His', '20170302_121215')->format(\DateTime::ATOM), |
213 | $data[0]['datetime'] | 212 | $data[0]['datetime'] |
diff --git a/tests/api/controllers/info/InfoTest.php b/tests/api/controllers/info/InfoTest.php index f7e63bfa..e70d371b 100644 --- a/tests/api/controllers/info/InfoTest.php +++ b/tests/api/controllers/info/InfoTest.php | |||
@@ -2,7 +2,6 @@ | |||
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; |
@@ -10,12 +9,12 @@ use Slim\Http\Response; | |||
10 | 9 | ||
11 | /** | 10 | /** |
12 | * Class InfoTest | 11 | * Class InfoTest |
13 | * | 12 | * |
14 | * Test REST API controller Info. | 13 | * Test REST API controller Info. |
15 | * | 14 | * |
16 | * @package Api\Controllers | 15 | * @package Api\Controllers |
17 | */ | 16 | */ |
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 d22ed3bf..711a3152 100644 --- a/tests/api/controllers/links/GetLinksTest.php +++ b/tests/api/controllers/links/GetLinksTest.php | |||
@@ -1,8 +1,8 @@ | |||
1 | <?php | 1 | <?php |
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); |
@@ -95,7 +95,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
95 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 95 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
96 | 96 | ||
97 | // Check order | 97 | // Check order |
98 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; | 98 | $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42]; |
99 | $cpt = 0; | 99 | $cpt = 0; |
100 | foreach ($data as $link) { | 100 | foreach ($data as $link) { |
101 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 101 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
@@ -103,7 +103,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
103 | } | 103 | } |
104 | 104 | ||
105 | // Check first element fields | 105 | // Check first element fields |
106 | $first = $data[0]; | 106 | $first = $data[2]; |
107 | $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); | 107 | $this->assertEquals('http://domain.tld/?WDWyig', $first['url']); |
108 | $this->assertEquals('WDWyig', $first['shorturl']); | 108 | $this->assertEquals('WDWyig', $first['shorturl']); |
109 | $this->assertEquals('Link title: @website', $first['title']); | 109 | $this->assertEquals('Link title: @website', $first['title']); |
@@ -114,18 +114,18 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
114 | $this->assertEquals('sTuff', $first['tags'][0]); | 114 | $this->assertEquals('sTuff', $first['tags'][0]); |
115 | $this->assertEquals(false, $first['private']); | 115 | $this->assertEquals(false, $first['private']); |
116 | $this->assertEquals( | 116 | $this->assertEquals( |
117 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), | 117 | \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651')->format(\DateTime::ATOM), |
118 | $first['created'] | 118 | $first['created'] |
119 | ); | 119 | ); |
120 | $this->assertEmpty($first['updated']); | 120 | $this->assertEmpty($first['updated']); |
121 | 121 | ||
122 | // Multi tags | 122 | // Multi tags |
123 | $link = $data[1]; | 123 | $link = $data[3]; |
124 | $this->assertEquals(7, count($link['tags'])); | 124 | $this->assertEquals(7, count($link['tags'])); |
125 | 125 | ||
126 | // Update date | 126 | // Update date |
127 | $this->assertEquals( | 127 | $this->assertEquals( |
128 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), | 128 | \DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')->format(\DateTime::ATOM), |
129 | $link['updated'] | 129 | $link['updated'] |
130 | ); | 130 | ); |
131 | } | 131 | } |
@@ -138,7 +138,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
138 | { | 138 | { |
139 | $env = Environment::mock([ | 139 | $env = Environment::mock([ |
140 | 'REQUEST_METHOD' => 'GET', | 140 | 'REQUEST_METHOD' => 'GET', |
141 | 'QUERY_STRING' => 'offset=1&limit=1' | 141 | 'QUERY_STRING' => 'offset=3&limit=1' |
142 | ]); | 142 | ]); |
143 | $request = Request::createFromEnvironment($env); | 143 | $request = Request::createFromEnvironment($env); |
144 | $response = $this->controller->getLinks($request, new Response()); | 144 | $response = $this->controller->getLinks($request, new Response()); |
@@ -164,7 +164,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
164 | $data = json_decode((string) $response->getBody(), true); | 164 | $data = json_decode((string) $response->getBody(), true); |
165 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 165 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
166 | // Check order | 166 | // Check order |
167 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; | 167 | $order = [10, 11, 41, 8, 6, 7, 0, 1, 9, 4, 42]; |
168 | $cpt = 0; | 168 | $cpt = 0; |
169 | foreach ($data as $link) { | 169 | foreach ($data as $link) { |
170 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 170 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
@@ -205,7 +205,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
205 | $this->assertEquals(200, $response->getStatusCode()); | 205 | $this->assertEquals(200, $response->getStatusCode()); |
206 | $data = json_decode((string)$response->getBody(), true); | 206 | $data = json_decode((string)$response->getBody(), true); |
207 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 207 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
208 | $this->assertEquals(41, $data[0]['id']); | 208 | $this->assertEquals(10, $data[0]['id']); |
209 | $this->assertEquals(41, $data[2]['id']); | ||
209 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); | 210 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); |
210 | } | 211 | } |
211 | 212 | ||
@@ -243,7 +244,8 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
243 | $this->assertEquals(200, $response->getStatusCode()); | 244 | $this->assertEquals(200, $response->getStatusCode()); |
244 | $data = json_decode((string)$response->getBody(), true); | 245 | $data = json_decode((string)$response->getBody(), true); |
245 | $this->assertEquals($this->refDB->countPublicLinks(), count($data)); | 246 | $this->assertEquals($this->refDB->countPublicLinks(), count($data)); |
246 | $this->assertEquals(41, $data[0]['id']); | 247 | $this->assertEquals(10, $data[0]['id']); |
248 | $this->assertEquals(41, $data[2]['id']); | ||
247 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); | 249 | $this->assertEquals(self::NB_FIELDS_LINK, count($data[0])); |
248 | } | 250 | } |
249 | 251 | ||
@@ -413,8 +415,9 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
413 | $response = $this->controller->getLinks($request, new Response()); | 415 | $response = $this->controller->getLinks($request, new Response()); |
414 | $this->assertEquals(200, $response->getStatusCode()); | 416 | $this->assertEquals(200, $response->getStatusCode()); |
415 | $data = json_decode((string) $response->getBody(), true); | 417 | $data = json_decode((string) $response->getBody(), true); |
416 | $this->assertEquals(9, count($data)); | 418 | $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, count($data)); |
417 | $this->assertEquals(41, $data[0]['id']); | 419 | $this->assertEquals(10, $data[0]['id']); |
420 | $this->assertEquals(41, $data[2]['id']); | ||
418 | 421 | ||
419 | // wildcard: optional ('*' does not need to expand) | 422 | // wildcard: optional ('*' does not need to expand) |
420 | $env = Environment::mock([ | 423 | $env = Environment::mock([ |
diff --git a/tests/api/controllers/links/PostLinkTest.php b/tests/api/controllers/links/PostLinkTest.php index 100a9170..d683a984 100644 --- a/tests/api/controllers/links/PostLinkTest.php +++ b/tests/api/controllers/links/PostLinkTest.php | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
4 | 4 | ||
5 | |||
6 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
7 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
8 | use Slim\Container; | 8 | use Slim\Container; |
9 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
@@ -41,7 +41,7 @@ class PostLinkTest extends TestCase | |||
41 | protected $refDB = null; | 41 | protected $refDB = null; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * @var \History instance. | 44 | * @var HistoryController instance. |
45 | */ | 45 | */ |
46 | protected $history; | 46 | protected $history; |
47 | 47 | ||
@@ -71,12 +71,12 @@ class PostLinkTest extends TestCase | |||
71 | 71 | ||
72 | $refHistory = new \ReferenceHistory(); | 72 | $refHistory = new \ReferenceHistory(); |
73 | $refHistory->write(self::$testHistory); | 73 | $refHistory->write(self::$testHistory); |
74 | $this->history = new \History(self::$testHistory); | 74 | $this->history = new History(self::$testHistory); |
75 | 75 | ||
76 | $this->container = new Container(); | 76 | $this->container = new Container(); |
77 | $this->container['conf'] = $this->conf; | 77 | $this->container['conf'] = $this->conf; |
78 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 78 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); |
79 | $this->container['history'] = new \History(self::$testHistory); | 79 | $this->container['history'] = new History(self::$testHistory); |
80 | 80 | ||
81 | $this->controller = new Links($this->container); | 81 | $this->controller = new Links($this->container); |
82 | 82 | ||
@@ -122,17 +122,19 @@ class PostLinkTest extends TestCase | |||
122 | $data = json_decode((string) $response->getBody(), true); | 122 | $data = json_decode((string) $response->getBody(), true); |
123 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 123 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
124 | $this->assertEquals(43, $data['id']); | 124 | $this->assertEquals(43, $data['id']); |
125 | $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); | 125 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); |
126 | $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); | 126 | $this->assertEquals('http://domain.tld/?' . $data['shorturl'], $data['url']); |
127 | $this->assertEquals('?' . $data['shorturl'], $data['title']); | 127 | $this->assertEquals('?' . $data['shorturl'], $data['title']); |
128 | $this->assertEquals('', $data['description']); | 128 | $this->assertEquals('', $data['description']); |
129 | $this->assertEquals([], $data['tags']); | 129 | $this->assertEquals([], $data['tags']); |
130 | $this->assertEquals(false, $data['private']); | 130 | $this->assertEquals(false, $data['private']); |
131 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); | 131 | $this->assertTrue( |
132 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | ||
133 | ); | ||
132 | $this->assertEquals('', $data['updated']); | 134 | $this->assertEquals('', $data['updated']); |
133 | 135 | ||
134 | $historyEntry = $this->history->getHistory()[0]; | 136 | $historyEntry = $this->history->getHistory()[0]; |
135 | $this->assertEquals(\History::CREATED, $historyEntry['event']); | 137 | $this->assertEquals(History::CREATED, $historyEntry['event']); |
136 | $this->assertTrue( | 138 | $this->assertTrue( |
137 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 139 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
138 | ); | 140 | ); |
@@ -165,13 +167,15 @@ class PostLinkTest extends TestCase | |||
165 | $data = json_decode((string) $response->getBody(), true); | 167 | $data = json_decode((string) $response->getBody(), true); |
166 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); | 168 | $this->assertEquals(self::NB_FIELDS_LINK, count($data)); |
167 | $this->assertEquals(43, $data['id']); | 169 | $this->assertEquals(43, $data['id']); |
168 | $this->assertRegExp('/[\w-_]{6}/', $data['shorturl']); | 170 | $this->assertRegExp('/[\w_-]{6}/', $data['shorturl']); |
169 | $this->assertEquals('http://' . $link['url'], $data['url']); | 171 | $this->assertEquals('http://' . $link['url'], $data['url']); |
170 | $this->assertEquals($link['title'], $data['title']); | 172 | $this->assertEquals($link['title'], $data['title']); |
171 | $this->assertEquals($link['description'], $data['description']); | 173 | $this->assertEquals($link['description'], $data['description']); |
172 | $this->assertEquals($link['tags'], $data['tags']); | 174 | $this->assertEquals($link['tags'], $data['tags']); |
173 | $this->assertEquals(true, $data['private']); | 175 | $this->assertEquals(true, $data['private']); |
174 | $this->assertTrue(new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created'])); | 176 | $this->assertTrue( |
177 | new \DateTime('2 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | ||
178 | ); | ||
175 | $this->assertEquals('', $data['updated']); | 179 | $this->assertEquals('', $data['updated']); |
176 | } | 180 | } |
177 | 181 | ||
@@ -207,11 +211,11 @@ class PostLinkTest extends TestCase | |||
207 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 211 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
208 | $this->assertEquals(false, $data['private']); | 212 | $this->assertEquals(false, $data['private']); |
209 | $this->assertEquals( | 213 | $this->assertEquals( |
210 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 214 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), |
211 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
212 | ); | 216 | ); |
213 | $this->assertEquals( | 217 | $this->assertEquals( |
214 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 218 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), |
215 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 219 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
216 | ); | 220 | ); |
217 | } | 221 | } |
diff --git a/tests/api/controllers/links/PutLinkTest.php b/tests/api/controllers/links/PutLinkTest.php index 8a562571..cd815b66 100644 --- a/tests/api/controllers/links/PutLinkTest.php +++ b/tests/api/controllers/links/PutLinkTest.php | |||
@@ -3,14 +3,14 @@ | |||
3 | 3 | ||
4 | namespace Shaarli\Api\Controllers; | 4 | namespace Shaarli\Api\Controllers; |
5 | 5 | ||
6 | |||
7 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
7 | use Shaarli\History; | ||
8 | use Slim\Container; | 8 | use Slim\Container; |
9 | use Slim\Http\Environment; | 9 | use Slim\Http\Environment; |
10 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
11 | use Slim\Http\Response; | 11 | use Slim\Http\Response; |
12 | 12 | ||
13 | class PutLinkTest extends \PHPUnit_Framework_TestCase | 13 | class PutLinkTest extends \PHPUnit\Framework\TestCase |
14 | { | 14 | { |
15 | /** | 15 | /** |
16 | * @var string datastore to test write operations | 16 | * @var string datastore to test write operations |
@@ -33,7 +33,7 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
33 | protected $refDB = null; | 33 | protected $refDB = null; |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * @var \History instance. | 36 | * @var HistoryController instance. |
37 | */ | 37 | */ |
38 | protected $history; | 38 | protected $history; |
39 | 39 | ||
@@ -63,12 +63,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
63 | 63 | ||
64 | $refHistory = new \ReferenceHistory(); | 64 | $refHistory = new \ReferenceHistory(); |
65 | $refHistory->write(self::$testHistory); | 65 | $refHistory->write(self::$testHistory); |
66 | $this->history = new \History(self::$testHistory); | 66 | $this->history = new History(self::$testHistory); |
67 | 67 | ||
68 | $this->container = new Container(); | 68 | $this->container = new Container(); |
69 | $this->container['conf'] = $this->conf; | 69 | $this->container['conf'] = $this->conf; |
70 | $this->container['db'] = new \LinkDB(self::$testDatastore, true, false); | 70 | $this->container['db'] = new \Shaarli\Bookmark\LinkDB(self::$testDatastore, true, false); |
71 | $this->container['history'] = new \History(self::$testHistory); | 71 | $this->container['history'] = new History(self::$testHistory); |
72 | 72 | ||
73 | $this->controller = new Links($this->container); | 73 | $this->controller = new Links($this->container); |
74 | 74 | ||
@@ -115,10 +115,12 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
115 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), | 115 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), |
116 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 116 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
117 | ); | 117 | ); |
118 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); | 118 | $this->assertTrue( |
119 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | ||
120 | ); | ||
119 | 121 | ||
120 | $historyEntry = $this->history->getHistory()[0]; | 122 | $historyEntry = $this->history->getHistory()[0]; |
121 | $this->assertEquals(\History::UPDATED, $historyEntry['event']); | 123 | $this->assertEquals(History::UPDATED, $historyEntry['event']); |
122 | $this->assertTrue( | 124 | $this->assertTrue( |
123 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 125 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
124 | ); | 126 | ); |
@@ -160,7 +162,9 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
160 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), | 162 | \DateTime::createFromFormat('Ymd_His', '20150310_114651'), |
161 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 163 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
162 | ); | 164 | ); |
163 | $this->assertTrue(new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated'])); | 165 | $this->assertTrue( |
166 | new \DateTime('5 seconds ago') < \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | ||
167 | ); | ||
164 | } | 168 | } |
165 | 169 | ||
166 | /** | 170 | /** |
@@ -195,11 +199,11 @@ class PutLinkTest extends \PHPUnit_Framework_TestCase | |||
195 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); | 199 | $this->assertEquals(['gnu', 'media', 'web', '.hidden', 'hashtag'], $data['tags']); |
196 | $this->assertEquals(false, $data['private']); | 200 | $this->assertEquals(false, $data['private']); |
197 | $this->assertEquals( | 201 | $this->assertEquals( |
198 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), | 202 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130614_184135'), |
199 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) | 203 | \DateTime::createFromFormat(\DateTime::ATOM, $data['created']) |
200 | ); | 204 | ); |
201 | $this->assertEquals( | 205 | $this->assertEquals( |
202 | \DateTime::createFromFormat(\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), | 206 | \DateTime::createFromFormat(\Shaarli\Bookmark\LinkDB::LINK_DATE_FORMAT, '20130615_184230'), |
203 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) | 207 | \DateTime::createFromFormat(\DateTime::ATOM, $data['updated']) |
204 | ); | 208 | ); |
205 | } | 209 | } |
diff --git a/tests/api/controllers/tags/DeleteTagTest.php b/tests/api/controllers/tags/DeleteTagTest.php index e0787ce2..84e1d56e 100644 --- a/tests/api/controllers/tags/DeleteTagTest.php +++ b/tests/api/controllers/tags/DeleteTagTest.php | |||
@@ -3,13 +3,15 @@ | |||
3 | 3 | ||
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 6f7dec22..86106fc7 100644 --- a/tests/api/controllers/tags/PutTagTest.php +++ b/tests/api/controllers/tags/PutTagTest.php | |||
@@ -1,17 +1,17 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | |||
4 | namespace Shaarli\Api\Controllers; | 3 | namespace Shaarli\Api\Controllers; |
5 | 4 | ||
6 | |||
7 | use Shaarli\Api\Exceptions\ApiBadParametersException; | 5 | use Shaarli\Api\Exceptions\ApiBadParametersException; |
6 | use Shaarli\Bookmark\LinkDB; | ||
8 | use Shaarli\Config\ConfigManager; | 7 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | ||
9 | use Slim\Container; | 9 | use Slim\Container; |
10 | use Slim\Http\Environment; | 10 | use Slim\Http\Environment; |
11 | use Slim\Http\Request; | 11 | use Slim\Http\Request; |
12 | use Slim\Http\Response; | 12 | use Slim\Http\Response; |
13 | 13 | ||
14 | class PutTagTest extends \PHPUnit_Framework_TestCase | 14 | class PutTagTest extends \PHPUnit\Framework\TestCase |
15 | { | 15 | { |
16 | /** | 16 | /** |
17 | * @var string datastore to test write operations | 17 | * @var string datastore to test write operations |
@@ -34,7 +34,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase | |||
34 | protected $refDB = null; | 34 | protected $refDB = null; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * @var \History instance. | 37 | * @var HistoryController instance. |
38 | */ | 38 | */ |
39 | protected $history; | 39 | protected $history; |
40 | 40 | ||
@@ -44,7 +44,7 @@ class PutTagTest extends \PHPUnit_Framework_TestCase | |||
44 | protected $container; | 44 | protected $container; |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * @var \LinkDB instance. | 47 | * @var LinkDB instance. |
48 | */ | 48 | */ |
49 | protected $linkDB; | 49 | protected $linkDB; |
50 | 50 | ||
@@ -69,11 +69,11 @@ class PutTagTest extends \PHPUnit_Framework_TestCase | |||
69 | 69 | ||
70 | $refHistory = new \ReferenceHistory(); | 70 | $refHistory = new \ReferenceHistory(); |
71 | $refHistory->write(self::$testHistory); | 71 | $refHistory->write(self::$testHistory); |
72 | $this->history = new \History(self::$testHistory); | 72 | $this->history = new History(self::$testHistory); |
73 | 73 | ||
74 | $this->container = new Container(); | 74 | $this->container = new Container(); |
75 | $this->container['conf'] = $this->conf; | 75 | $this->container['conf'] = $this->conf; |
76 | $this->linkDB = new \LinkDB(self::$testDatastore, true, false); | 76 | $this->linkDB = new LinkDB(self::$testDatastore, true, false); |
77 | $this->container['db'] = $this->linkDB; | 77 | $this->container['db'] = $this->linkDB; |
78 | $this->container['history'] = $this->history; | 78 | $this->container['history'] = $this->history; |
79 | 79 | ||
@@ -114,12 +114,12 @@ class PutTagTest extends \PHPUnit_Framework_TestCase | |||
114 | $this->assertEquals(2, $tags[$newName]); | 114 | $this->assertEquals(2, $tags[$newName]); |
115 | 115 | ||
116 | $historyEntry = $this->history->getHistory()[0]; | 116 | $historyEntry = $this->history->getHistory()[0]; |
117 | $this->assertEquals(\History::UPDATED, $historyEntry['event']); | 117 | $this->assertEquals(History::UPDATED, $historyEntry['event']); |
118 | $this->assertTrue( | 118 | $this->assertTrue( |
119 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 119 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
120 | ); | 120 | ); |
121 | $historyEntry = $this->history->getHistory()[1]; | 121 | $historyEntry = $this->history->getHistory()[1]; |
122 | $this->assertEquals(\History::UPDATED, $historyEntry['event']); | 122 | $this->assertEquals(History::UPDATED, $historyEntry['event']); |
123 | $this->assertTrue( | 123 | $this->assertTrue( |
124 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] | 124 | (new \DateTime())->add(\DateInterval::createFromDateString('-5 seconds')) < $historyEntry['datetime'] |
125 | ); | 125 | ); |