aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-11-28 16:17:25 +0100
committerArthurHoaro <arthur@hoa.ro>2016-12-12 03:03:12 +0100
commitc3dfd8995921083ff7250c25d0b6ab1184b91aff (patch)
treecb7cb17ad607a5bd2e7d9ee59c0e804e590fa6af
parent01878a75b93b9966f7366ea2937c118bbc3e459e (diff)
downloadShaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.tar.gz
Shaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.tar.zst
Shaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.zip
Unit Test for the new ID system
-rw-r--r--tests/FeedBuilderTest.php31
-rw-r--r--tests/LinkDBTest.php39
-rw-r--r--tests/LinkFilterTest.php6
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkExportTest.php6
-rw-r--r--tests/NetscapeBookmarkUtils/BookmarkImportTest.php146
-rw-r--r--tests/Updater/UpdaterTest.php98
-rw-r--r--tests/plugins/PluginIssoTest.php14
-rw-r--r--tests/utils/ReferenceLinkDB.php61
8 files changed, 306 insertions, 95 deletions
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php
index d7839402..ea1dde25 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/FeedBuilderTest.php
@@ -84,8 +84,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
84 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 84 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
85 85
86 // Test first link (note link) 86 // Test first link (note link)
87 $link = array_shift($data['links']); 87 $link = reset($data['links']);
88 $this->assertEquals('20150310_114651', $link['linkdate']); 88 $this->assertEquals(41, $link['id']);
89 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
89 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 90 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 91 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 92 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
@@ -99,14 +100,14 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
99 $this->assertEquals('sTuff', $link['taglist'][0]); 100 $this->assertEquals('sTuff', $link['taglist'][0]);
100 101
101 // Test URL with external link. 102 // Test URL with external link.
102 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']); 103 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links'][8]['url']);
103 104
104 // Test multitags. 105 // Test multitags.
105 $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); 106 $this->assertEquals(5, count($data['links'][6]['taglist']));
106 $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); 107 $this->assertEquals('css', $data['links'][6]['taglist'][0]);
107 108
108 // Test update date 109 // Test update date
109 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); 110 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
110 } 111 }
111 112
112 /** 113 /**
@@ -119,9 +120,9 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
119 $data = $feedBuilder->buildData(); 120 $data = $feedBuilder->buildData();
120 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 121 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
121 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']); 122 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
122 $link = array_shift($data['links']); 123 $link = reset($data['links']);
123 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']); 124 $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
124 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']); 125 $this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
125 } 126 }
126 127
127 /** 128 /**
@@ -138,7 +139,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
138 $data = $feedBuilder->buildData(); 139 $data = $feedBuilder->buildData();
139 $this->assertEquals(1, count($data['links'])); 140 $this->assertEquals(1, count($data['links']));
140 $link = array_shift($data['links']); 141 $link = array_shift($data['links']);
141 $this->assertEquals('20150310_114651', $link['linkdate']); 142 $this->assertEquals(41, $link['id']);
143 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
142 } 144 }
143 145
144 /** 146 /**
@@ -154,7 +156,8 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
154 $data = $feedBuilder->buildData(); 156 $data = $feedBuilder->buildData();
155 $this->assertEquals(1, count($data['links'])); 157 $this->assertEquals(1, count($data['links']));
156 $link = array_shift($data['links']); 158 $link = array_shift($data['links']);
157 $this->assertEquals('20150310_114651', $link['linkdate']); 159 $this->assertEquals(41, $link['id']);
160 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
158 } 161 }
159 162
160 /** 163 /**
@@ -170,15 +173,17 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
170 $this->assertTrue($data['usepermalinks']); 173 $this->assertTrue($data['usepermalinks']);
171 // First link is a permalink 174 // First link is a permalink
172 $link = array_shift($data['links']); 175 $link = array_shift($data['links']);
173 $this->assertEquals('20150310_114651', $link['linkdate']); 176 $this->assertEquals(41, $link['id']);
177 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
174 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); 178 $this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
175 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 179 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
176 $this->assertContains('Direct link', $link['description']); 180 $this->assertContains('Direct link', $link['description']);
177 $this->assertContains('http://host.tld/?WDWyig', $link['description']); 181 $this->assertContains('http://host.tld/?WDWyig', $link['description']);
178 // Second link is a direct link 182 // Second link is a direct link
179 $link = array_shift($data['links']); 183 $link = array_shift($data['links']);
180 $this->assertEquals('20150310_114633', $link['linkdate']); 184 $this->assertEquals(8, $link['id']);
181 $this->assertEquals('http://host.tld/?kLHmZg', $link['guid']); 185 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114633'), $link['created']);
186 $this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
182 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); 187 $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
183 $this->assertContains('Direct link', $link['description']); 188 $this->assertContains('Direct link', $link['description']);
184 $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); 189 $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 9d79386c..bedc680e 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -186,14 +186,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
186 $dbSize = sizeof($testDB); 186 $dbSize = sizeof($testDB);
187 187
188 $link = array( 188 $link = array(
189 'id' => 42,
189 'title'=>'an additional link', 190 'title'=>'an additional link',
190 'url'=>'http://dum.my', 191 'url'=>'http://dum.my',
191 'description'=>'One more', 192 'description'=>'One more',
192 'private'=>0, 193 'private'=>0,
193 'linkdate'=>'20150518_190000', 194 'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'),
194 'tags'=>'unit test' 195 'tags'=>'unit test'
195 ); 196 );
196 $testDB[$link['linkdate']] = $link; 197 $testDB[$link['id']] = $link;
197 $testDB->save('tests'); 198 $testDB->save('tests');
198 199
199 $testDB = new LinkDB(self::$testDatastore, true, false); 200 $testDB = new LinkDB(self::$testDatastore, true, false);
@@ -238,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
238 public function testDays() 239 public function testDays()
239 { 240 {
240 $this->assertEquals( 241 $this->assertEquals(
241 array('20121206', '20130614', '20150310'), 242 array('20100310', '20121206', '20130614', '20150310'),
242 self::$publicLinkDB->days() 243 self::$publicLinkDB->days()
243 ); 244 );
244 245
245 $this->assertEquals( 246 $this->assertEquals(
246 array('20121206', '20130614', '20141125', '20150310'), 247 array('20100310', '20121206', '20130614', '20141125', '20150310'),
247 self::$privateLinkDB->days() 248 self::$privateLinkDB->days()
248 ); 249 );
249 } 250 }
@@ -290,10 +291,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
290 'stallman' => 1, 291 'stallman' => 1,
291 'free' => 1, 292 'free' => 1,
292 '-exclude' => 1, 293 '-exclude' => 1,
294 'hashtag' => 2,
293 // The DB contains a link with `sTuff` and another one with `stuff` tag. 295 // The DB contains a link with `sTuff` and another one with `stuff` tag.
294 // They need to be grouped with the first case found (`sTuff`). 296 // They need to be grouped with the first case found - order by date DESC: `sTuff`.
295 'sTuff' => 2, 297 'sTuff' => 2,
296 'hashtag' => 2, 298 'ut' => 1,
297 ), 299 ),
298 self::$publicLinkDB->allTags() 300 self::$publicLinkDB->allTags()
299 ); 301 );
@@ -321,6 +323,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
321 'tag2' => 1, 323 'tag2' => 1,
322 'tag3' => 1, 324 'tag3' => 1,
323 'tag4' => 1, 325 'tag4' => 1,
326 'ut' => 1,
324 ), 327 ),
325 self::$privateLinkDB->allTags() 328 self::$privateLinkDB->allTags()
326 ); 329 );
@@ -411,6 +414,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
411 1, 414 1,
412 count(self::$publicLinkDB->filterHash($request)) 415 count(self::$publicLinkDB->filterHash($request))
413 ); 416 );
417 $request = smallHash('20150310_114633' . 8);
418 $this->assertEquals(
419 1,
420 count(self::$publicLinkDB->filterHash($request))
421 );
414 } 422 }
415 423
416 /** 424 /**
@@ -433,4 +441,23 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
433 { 441 {
434 self::$publicLinkDB->filterHash(''); 442 self::$publicLinkDB->filterHash('');
435 } 443 }
444
445 /**
446 * Test reorder with asc/desc parameter.
447 */
448 public function testReorderLinksDesc()
449 {
450 self::$publicLinkDB->reorder('ASC');
451 $linkIdToTest = 42;
452 foreach (self::$publicLinkDB as $key => $value) {
453 $this->assertEquals($linkIdToTest, $key);
454 break;
455 }
456 self::$publicLinkDB->reorder('DESC');
457 $linkIdToTest = 41;
458 foreach (self::$publicLinkDB as $key => $value) {
459 $this->assertEquals($linkIdToTest, $key);
460 break;
461 }
462 }
436} 463}
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php
index 7d45fc59..21d680a5 100644
--- a/tests/LinkFilterTest.php
+++ b/tests/LinkFilterTest.php
@@ -159,7 +159,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
159 159
160 $this->assertEquals( 160 $this->assertEquals(
161 'MediaGoblin', 161 'MediaGoblin',
162 $links['20130614_184135']['title'] 162 $links[7]['title']
163 ); 163 );
164 } 164 }
165 165
@@ -286,7 +286,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
286 ); 286 );
287 287
288 $this->assertEquals( 288 $this->assertEquals(
289 6, 289 7,
290 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution')) 290 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution'))
291 ); 291 );
292 } 292 }
@@ -346,7 +346,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
346 ); 346 );
347 347
348 $this->assertEquals( 348 $this->assertEquals(
349 6, 349 7,
350 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free')) 350 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
351 ); 351 );
352 } 352 }
diff --git a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php b/tests/NetscapeBookmarkUtils/BookmarkExportTest.php
index cc54ab9f..6a47bbb9 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkExportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkExportTest.php
@@ -50,7 +50,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
50 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); 50 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, '');
51 $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); 51 $this->assertEquals(self::$refDb->countLinks(), sizeof($links));
52 foreach ($links as $link) { 52 foreach ($links as $link) {
53 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 53 $date = $link['created'];
54 $this->assertEquals( 54 $this->assertEquals(
55 $date->getTimestamp(), 55 $date->getTimestamp(),
56 $link['timestamp'] 56 $link['timestamp']
@@ -70,7 +70,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
70 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); 70 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, '');
71 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); 71 $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
72 foreach ($links as $link) { 72 foreach ($links as $link) {
73 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 73 $date = $link['created'];
74 $this->assertEquals( 74 $this->assertEquals(
75 $date->getTimestamp(), 75 $date->getTimestamp(),
76 $link['timestamp'] 76 $link['timestamp']
@@ -90,7 +90,7 @@ class BookmarkExportTest extends PHPUnit_Framework_TestCase
90 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); 90 $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
91 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); 91 $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
92 foreach ($links as $link) { 92 foreach ($links as $link) {
93 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); 93 $date = $link['created'];
94 $this->assertEquals( 94 $this->assertEquals(
95 $date->getTimestamp(), 95 $date->getTimestamp(),
96 $link['timestamp'] 96 $link['timestamp']
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
index f0ad500f..96895b00 100644
--- a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
+++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php
@@ -43,6 +43,18 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
43 protected $pagecache = 'tests'; 43 protected $pagecache = 'tests';
44 44
45 /** 45 /**
46 * @var string Save the current timezone.
47 */
48 protected static $defaultTimeZone;
49
50 public static function setUpBeforeClass()
51 {
52 self::$defaultTimeZone = date_default_timezone_get();
53 // Timezone without DST for test consistency
54 date_default_timezone_set('Africa/Nairobi');
55 }
56
57 /**
46 * Resets test data before each test 58 * Resets test data before each test
47 */ 59 */
48 protected function setUp() 60 protected function setUp()
@@ -55,6 +67,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
55 $this->linkDb = new LinkDB(self::$testDatastore, true, false); 67 $this->linkDb = new LinkDB(self::$testDatastore, true, false);
56 } 68 }
57 69
70 public static function tearDownAfterClass()
71 {
72 date_default_timezone_set(self::$defaultTimeZone);
73 }
74
58 /** 75 /**
59 * Attempt to import bookmarks from an empty file 76 * Attempt to import bookmarks from an empty file
60 */ 77 */
@@ -98,18 +115,19 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
98 115
99 $this->assertEquals( 116 $this->assertEquals(
100 array( 117 array(
101 'linkdate' => '20160618_173944', 118 'id' => 0,
119 'created' => DateTime::createFromFormat('Ymd_His', '20160618_203944'),
102 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky', 120 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
103 'url' => 'http://hginit.com/', 121 'url' => 'http://hginit.com/',
104 'description' => '', 122 'description' => '',
105 'private' => 0, 123 'private' => 0,
106 'tags' => '' 124 'tags' => '',
125 'shorturl' => 'La37cg',
107 ), 126 ),
108 $this->linkDb->getLinkFromUrl('http://hginit.com/') 127 $this->linkDb->getLinkFromUrl('http://hginit.com/')
109 ); 128 );
110 } 129 }
111 130
112
113 /** 131 /**
114 * Import bookmarks nested in a folder hierarchy 132 * Import bookmarks nested in a folder hierarchy
115 */ 133 */
@@ -126,89 +144,105 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
126 144
127 $this->assertEquals( 145 $this->assertEquals(
128 array( 146 array(
129 'linkdate' => '20160225_205541', 147 'id' => 0,
148 'created' => DateTime::createFromFormat('Ymd_His', '20160225_235541'),
130 'title' => 'Nested 1', 149 'title' => 'Nested 1',
131 'url' => 'http://nest.ed/1', 150 'url' => 'http://nest.ed/1',
132 'description' => '', 151 'description' => '',
133 'private' => 0, 152 'private' => 0,
134 'tags' => 'tag1 tag2' 153 'tags' => 'tag1 tag2',
154 'shorturl' => 'KyDNKA',
135 ), 155 ),
136 $this->linkDb->getLinkFromUrl('http://nest.ed/1') 156 $this->linkDb->getLinkFromUrl('http://nest.ed/1')
137 ); 157 );
138 $this->assertEquals( 158 $this->assertEquals(
139 array( 159 array(
140 'linkdate' => '20160225_205542', 160 'id' => 1,
161 'created' => DateTime::createFromFormat('Ymd_His', '20160225_235542'),
141 'title' => 'Nested 1-1', 162 'title' => 'Nested 1-1',
142 'url' => 'http://nest.ed/1-1', 163 'url' => 'http://nest.ed/1-1',
143 'description' => '', 164 'description' => '',
144 'private' => 0, 165 'private' => 0,
145 'tags' => 'folder1 tag1 tag2' 166 'tags' => 'folder1 tag1 tag2',
167 'shorturl' => 'T2LnXg',
146 ), 168 ),
147 $this->linkDb->getLinkFromUrl('http://nest.ed/1-1') 169 $this->linkDb->getLinkFromUrl('http://nest.ed/1-1')
148 ); 170 );
149 $this->assertEquals( 171 $this->assertEquals(
150 array( 172 array(
151 'linkdate' => '20160225_205547', 173 'id' => 2,
174 'created' => DateTime::createFromFormat('Ymd_His', '20160225_235547'),
152 'title' => 'Nested 1-2', 175 'title' => 'Nested 1-2',
153 'url' => 'http://nest.ed/1-2', 176 'url' => 'http://nest.ed/1-2',
154 'description' => '', 177 'description' => '',
155 'private' => 0, 178 'private' => 0,
156 'tags' => 'folder1 tag3 tag4' 179 'tags' => 'folder1 tag3 tag4',
180 'shorturl' => '46SZxA',
157 ), 181 ),
158 $this->linkDb->getLinkFromUrl('http://nest.ed/1-2') 182 $this->linkDb->getLinkFromUrl('http://nest.ed/1-2')
159 ); 183 );
160 $this->assertEquals( 184 $this->assertEquals(
161 array( 185 array(
162 'linkdate' => '20160202_172222', 186 'id' => 3,
187 'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
163 'title' => 'Nested 2-1', 188 'title' => 'Nested 2-1',
164 'url' => 'http://nest.ed/2-1', 189 'url' => 'http://nest.ed/2-1',
165 'description' => 'First link of the second section', 190 'description' => 'First link of the second section',
166 'private' => 1, 191 'private' => 1,
167 'tags' => 'folder2' 192 'tags' => 'folder2',
193 'shorturl' => '4UHOSw',
168 ), 194 ),
169 $this->linkDb->getLinkFromUrl('http://nest.ed/2-1') 195 $this->linkDb->getLinkFromUrl('http://nest.ed/2-1')
170 ); 196 );
171 $this->assertEquals( 197 $this->assertEquals(
172 array( 198 array(
173 'linkdate' => '20160119_200227', 199 'id' => 4,
200 'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
174 'title' => 'Nested 2-2', 201 'title' => 'Nested 2-2',
175 'url' => 'http://nest.ed/2-2', 202 'url' => 'http://nest.ed/2-2',
176 'description' => 'Second link of the second section', 203 'description' => 'Second link of the second section',
177 'private' => 1, 204 'private' => 1,
178 'tags' => 'folder2' 205 'tags' => 'folder2',
206 'shorturl' => 'yfzwbw',
179 ), 207 ),
180 $this->linkDb->getLinkFromUrl('http://nest.ed/2-2') 208 $this->linkDb->getLinkFromUrl('http://nest.ed/2-2')
181 ); 209 );
182 $this->assertEquals( 210 $this->assertEquals(
183 array( 211 array(
184 'linkdate' => '20160202_172223', 212 'id' => 5,
213 'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
185 'title' => 'Nested 3-1', 214 'title' => 'Nested 3-1',
186 'url' => 'http://nest.ed/3-1', 215 'url' => 'http://nest.ed/3-1',
187 'description' => '', 216 'description' => '',
188 'private' => 0, 217 'private' => 0,
189 'tags' => 'folder3 folder3-1 tag3' 218 'tags' => 'folder3 folder3-1 tag3',
219 'shorturl' => 'UwxIUQ',
190 ), 220 ),
191 $this->linkDb->getLinkFromUrl('http://nest.ed/3-1') 221 $this->linkDb->getLinkFromUrl('http://nest.ed/3-1')
192 ); 222 );
193 $this->assertEquals( 223 $this->assertEquals(
194 array( 224 array(
195 'linkdate' => '20160119_200228', 225 'id' => 6,
226 'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
196 'title' => 'Nested 3-2', 227 'title' => 'Nested 3-2',
197 'url' => 'http://nest.ed/3-2', 228 'url' => 'http://nest.ed/3-2',
198 'description' => '', 229 'description' => '',
199 'private' => 0, 230 'private' => 0,
200 'tags' => 'folder3 folder3-1' 231 'tags' => 'folder3 folder3-1',
232 'shorturl' => 'p8dyZg',
201 ), 233 ),
202 $this->linkDb->getLinkFromUrl('http://nest.ed/3-2') 234 $this->linkDb->getLinkFromUrl('http://nest.ed/3-2')
203 ); 235 );
204 $this->assertEquals( 236 $this->assertEquals(
205 array( 237 array(
206 'linkdate' => '20160229_081541', 238 'id' => 7,
239 'created' => DateTime::createFromFormat('Ymd_His', '20160229_111541'),
207 'title' => 'Nested 2', 240 'title' => 'Nested 2',
208 'url' => 'http://nest.ed/2', 241 'url' => 'http://nest.ed/2',
209 'description' => '', 242 'description' => '',
210 'private' => 0, 243 'private' => 0,
211 'tags' => 'tag4' 244 'tags' => 'tag4',
245 'shorturl' => 'Gt3Uug',
212 ), 246 ),
213 $this->linkDb->getLinkFromUrl('http://nest.ed/2') 247 $this->linkDb->getLinkFromUrl('http://nest.ed/2')
214 ); 248 );
@@ -227,28 +261,34 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
227 .' 2 links imported, 0 links overwritten, 0 links skipped.', 261 .' 2 links imported, 0 links overwritten, 0 links skipped.',
228 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) 262 NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
229 ); 263 );
264
230 $this->assertEquals(2, count($this->linkDb)); 265 $this->assertEquals(2, count($this->linkDb));
231 $this->assertEquals(1, count_private($this->linkDb)); 266 $this->assertEquals(1, count_private($this->linkDb));
232 267
233 $this->assertEquals( 268 $this->assertEquals(
234 array( 269 array(
235 'linkdate' => '20001010_105536', 270 'id' => 0,
271 // Old link - UTC+4 (note that TZ in the import file is ignored).
272 'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
236 'title' => 'Secret stuff', 273 'title' => 'Secret stuff',
237 'url' => 'https://private.tld', 274 'url' => 'https://private.tld',
238 'description' => "Super-secret stuff you're not supposed to know about", 275 'description' => "Super-secret stuff you're not supposed to know about",
239 'private' => 1, 276 'private' => 1,
240 'tags' => 'private secret' 277 'tags' => 'private secret',
278 'shorturl' => 'EokDtA',
241 ), 279 ),
242 $this->linkDb->getLinkFromUrl('https://private.tld') 280 $this->linkDb->getLinkFromUrl('https://private.tld')
243 ); 281 );
244 $this->assertEquals( 282 $this->assertEquals(
245 array( 283 array(
246 'linkdate' => '20160225_205548', 284 'id' => 1,
285 'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
247 'title' => 'Public stuff', 286 'title' => 'Public stuff',
248 'url' => 'http://public.tld', 287 'url' => 'http://public.tld',
249 'description' => '', 288 'description' => '',
250 'private' => 0, 289 'private' => 0,
251 'tags' => 'public hello world' 290 'tags' => 'public hello world',
291 'shorturl' => 'Er9ddA',
252 ), 292 ),
253 $this->linkDb->getLinkFromUrl('http://public.tld') 293 $this->linkDb->getLinkFromUrl('http://public.tld')
254 ); 294 );
@@ -271,23 +311,28 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
271 311
272 $this->assertEquals( 312 $this->assertEquals(
273 array( 313 array(
274 'linkdate' => '20001010_105536', 314 'id' => 0,
315 // Note that TZ in the import file is ignored.
316 'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
275 'title' => 'Secret stuff', 317 'title' => 'Secret stuff',
276 'url' => 'https://private.tld', 318 'url' => 'https://private.tld',
277 'description' => "Super-secret stuff you're not supposed to know about", 319 'description' => "Super-secret stuff you're not supposed to know about",
278 'private' => 1, 320 'private' => 1,
279 'tags' => 'private secret' 321 'tags' => 'private secret',
322 'shorturl' => 'EokDtA',
280 ), 323 ),
281 $this->linkDb->getLinkFromUrl('https://private.tld') 324 $this->linkDb->getLinkFromUrl('https://private.tld')
282 ); 325 );
283 $this->assertEquals( 326 $this->assertEquals(
284 array( 327 array(
285 'linkdate' => '20160225_205548', 328 'id' => 1,
329 'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
286 'title' => 'Public stuff', 330 'title' => 'Public stuff',
287 'url' => 'http://public.tld', 331 'url' => 'http://public.tld',
288 'description' => '', 332 'description' => '',
289 'private' => 0, 333 'private' => 0,
290 'tags' => 'public hello world' 334 'tags' => 'public hello world',
335 'shorturl' => 'Er9ddA',
291 ), 336 ),
292 $this->linkDb->getLinkFromUrl('http://public.tld') 337 $this->linkDb->getLinkFromUrl('http://public.tld')
293 ); 338 );
@@ -309,11 +354,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
309 $this->assertEquals(0, count_private($this->linkDb)); 354 $this->assertEquals(0, count_private($this->linkDb));
310 $this->assertEquals( 355 $this->assertEquals(
311 0, 356 0,
312 $this->linkDb['20001010_105536']['private'] 357 $this->linkDb[0]['private']
313 ); 358 );
314 $this->assertEquals( 359 $this->assertEquals(
315 0, 360 0,
316 $this->linkDb['20160225_205548']['private'] 361 $this->linkDb[1]['private']
317 ); 362 );
318 } 363 }
319 364
@@ -333,11 +378,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
333 $this->assertEquals(2, count_private($this->linkDb)); 378 $this->assertEquals(2, count_private($this->linkDb));
334 $this->assertEquals( 379 $this->assertEquals(
335 1, 380 1,
336 $this->linkDb['20001010_105536']['private'] 381 $this->linkDb['0']['private']
337 ); 382 );
338 $this->assertEquals( 383 $this->assertEquals(
339 1, 384 1,
340 $this->linkDb['20160225_205548']['private'] 385 $this->linkDb['1']['private']
341 ); 386 );
342 } 387 }
343 388
@@ -359,13 +404,12 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
359 $this->assertEquals(2, count_private($this->linkDb)); 404 $this->assertEquals(2, count_private($this->linkDb));
360 $this->assertEquals( 405 $this->assertEquals(
361 1, 406 1,
362 $this->linkDb['20001010_105536']['private'] 407 $this->linkDb[0]['private']
363 ); 408 );
364 $this->assertEquals( 409 $this->assertEquals(
365 1, 410 1,
366 $this->linkDb['20160225_205548']['private'] 411 $this->linkDb[1]['private']
367 ); 412 );
368
369 // re-import as public, enable overwriting 413 // re-import as public, enable overwriting
370 $post = array( 414 $post = array(
371 'privacy' => 'public', 415 'privacy' => 'public',
@@ -380,11 +424,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
380 $this->assertEquals(0, count_private($this->linkDb)); 424 $this->assertEquals(0, count_private($this->linkDb));
381 $this->assertEquals( 425 $this->assertEquals(
382 0, 426 0,
383 $this->linkDb['20001010_105536']['private'] 427 $this->linkDb[0]['private']
384 ); 428 );
385 $this->assertEquals( 429 $this->assertEquals(
386 0, 430 0,
387 $this->linkDb['20160225_205548']['private'] 431 $this->linkDb[1]['private']
388 ); 432 );
389 } 433 }
390 434
@@ -406,11 +450,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
406 $this->assertEquals(0, count_private($this->linkDb)); 450 $this->assertEquals(0, count_private($this->linkDb));
407 $this->assertEquals( 451 $this->assertEquals(
408 0, 452 0,
409 $this->linkDb['20001010_105536']['private'] 453 $this->linkDb['0']['private']
410 ); 454 );
411 $this->assertEquals( 455 $this->assertEquals(
412 0, 456 0,
413 $this->linkDb['20160225_205548']['private'] 457 $this->linkDb['1']['private']
414 ); 458 );
415 459
416 // re-import as private, enable overwriting 460 // re-import as private, enable overwriting
@@ -427,11 +471,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
427 $this->assertEquals(2, count_private($this->linkDb)); 471 $this->assertEquals(2, count_private($this->linkDb));
428 $this->assertEquals( 472 $this->assertEquals(
429 1, 473 1,
430 $this->linkDb['20001010_105536']['private'] 474 $this->linkDb['0']['private']
431 ); 475 );
432 $this->assertEquals( 476 $this->assertEquals(
433 1, 477 1,
434 $this->linkDb['20160225_205548']['private'] 478 $this->linkDb['1']['private']
435 ); 479 );
436 } 480 }
437 481
@@ -480,11 +524,11 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
480 $this->assertEquals(0, count_private($this->linkDb)); 524 $this->assertEquals(0, count_private($this->linkDb));
481 $this->assertEquals( 525 $this->assertEquals(
482 'tag1 tag2 tag3 private secret', 526 'tag1 tag2 tag3 private secret',
483 $this->linkDb['20001010_105536']['tags'] 527 $this->linkDb['0']['tags']
484 ); 528 );
485 $this->assertEquals( 529 $this->assertEquals(
486 'tag1 tag2 tag3 public hello world', 530 'tag1 tag2 tag3 public hello world',
487 $this->linkDb['20160225_205548']['tags'] 531 $this->linkDb['1']['tags']
488 ); 532 );
489 } 533 }
490 534
@@ -507,16 +551,16 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
507 $this->assertEquals(0, count_private($this->linkDb)); 551 $this->assertEquals(0, count_private($this->linkDb));
508 $this->assertEquals( 552 $this->assertEquals(
509 'tag1&amp; tag2 &quot;tag3&quot; private secret', 553 'tag1&amp; tag2 &quot;tag3&quot; private secret',
510 $this->linkDb['20001010_105536']['tags'] 554 $this->linkDb['0']['tags']
511 ); 555 );
512 $this->assertEquals( 556 $this->assertEquals(
513 'tag1&amp; tag2 &quot;tag3&quot; public hello world', 557 'tag1&amp; tag2 &quot;tag3&quot; public hello world',
514 $this->linkDb['20160225_205548']['tags'] 558 $this->linkDb['1']['tags']
515 ); 559 );
516 } 560 }
517 561
518 /** 562 /**
519 * Ensure each imported bookmark has a unique linkdate 563 * Ensure each imported bookmark has a unique id
520 * 564 *
521 * See https://github.com/shaarli/Shaarli/issues/351 565 * See https://github.com/shaarli/Shaarli/issues/351
522 */ 566 */
@@ -531,16 +575,16 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
531 $this->assertEquals(3, count($this->linkDb)); 575 $this->assertEquals(3, count($this->linkDb));
532 $this->assertEquals(0, count_private($this->linkDb)); 576 $this->assertEquals(0, count_private($this->linkDb));
533 $this->assertEquals( 577 $this->assertEquals(
534 '20160225_205548', 578 0,
535 $this->linkDb['20160225_205548']['linkdate'] 579 $this->linkDb[0]['id']
536 ); 580 );
537 $this->assertEquals( 581 $this->assertEquals(
538 '20160225_205549', 582 1,
539 $this->linkDb['20160225_205549']['linkdate'] 583 $this->linkDb[1]['id']
540 ); 584 );
541 $this->assertEquals( 585 $this->assertEquals(
542 '20160225_205550', 586 2,
543 $this->linkDb['20160225_205550']['linkdate'] 587 $this->linkDb[2]['id']
544 ); 588 );
545 } 589 }
546} 590}
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index 0d0ad922..b8a050b0 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -214,6 +214,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
214 $refDB = new ReferenceLinkDB(); 214 $refDB = new ReferenceLinkDB();
215 $refDB->write(self::$testDatastore); 215 $refDB->write(self::$testDatastore);
216 $linkDB = new LinkDB(self::$testDatastore, true, false); 216 $linkDB = new LinkDB(self::$testDatastore, true, false);
217
217 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); 218 $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
218 $updater = new Updater(array(), $linkDB, $this->conf, true); 219 $updater = new Updater(array(), $linkDB, $this->conf, true);
219 $updater->updateMethodRenameDashTags(); 220 $updater->updateMethodRenameDashTags();
@@ -287,4 +288,101 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
287 $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url')); 288 $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
288 unlink($sandbox .'.json.php'); 289 unlink($sandbox .'.json.php');
289 } 290 }
291
292 /**
293 * Test updateMethodDatastoreIds().
294 */
295 public function testDatastoreIds()
296 {
297 $links = array(
298 '20121206_182539' => array(
299 'linkdate' => '20121206_182539',
300 'title' => 'Geek and Poke',
301 'url' => 'http://geek-and-poke.com/',
302 'description' => 'desc',
303 'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
304 'updated' => '20121206_190301',
305 'private' => false,
306 ),
307 '20121206_172539' => array(
308 'linkdate' => '20121206_172539',
309 'title' => 'UserFriendly - Samba',
310 'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
311 'description' => '',
312 'tags' => 'samba cartoon web',
313 'private' => false,
314 ),
315 '20121206_142300' => array(
316 'linkdate' => '20121206_142300',
317 'title' => 'UserFriendly - Web Designer',
318 'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
319 'description' => 'Naming conventions... #private',
320 'tags' => 'samba cartoon web',
321 'private' => true,
322 ),
323 );
324 $refDB = new ReferenceLinkDB();
325 $refDB->setLinks($links);
326 $refDB->write(self::$testDatastore);
327 $linkDB = new LinkDB(self::$testDatastore, true, false);
328
329 $checksum = hash_file('sha1', self::$testDatastore);
330
331 $this->conf->set('resource.data_dir', 'sandbox');
332 $this->conf->set('resource.datastore', self::$testDatastore);
333
334 $updater = new Updater(array(), $linkDB, $this->conf, true);
335 $this->assertTrue($updater->updateMethodDatastoreIds());
336
337 $linkDB = new LinkDB(self::$testDatastore, true, false);
338
339 $backup = glob($this->conf->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
340 $backup = $backup[0];
341
342 $this->assertFileExists($backup);
343 $this->assertEquals($checksum, hash_file('sha1', $backup));
344 unlink($backup);
345
346 $this->assertEquals(3, count($linkDB));
347 $this->assertTrue(isset($linkDB[0]));
348 $this->assertFalse(isset($linkDB[0]['linkdate']));
349 $this->assertEquals(0, $linkDB[0]['id']);
350 $this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
351 $this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
352 $this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
353 $this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
354 $this->assertTrue($linkDB[0]['private']);
355 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_142300'), $linkDB[0]['created']);
356
357 $this->assertTrue(isset($linkDB[1]));
358 $this->assertFalse(isset($linkDB[1]['linkdate']));
359 $this->assertEquals(1, $linkDB[1]['id']);
360 $this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
361 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_172539'), $linkDB[1]['created']);
362
363 $this->assertTrue(isset($linkDB[2]));
364 $this->assertFalse(isset($linkDB[2]['linkdate']));
365 $this->assertEquals(2, $linkDB[2]['id']);
366 $this->assertEquals('Geek and Poke', $linkDB[2]['title']);
367 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_182539'), $linkDB[2]['created']);
368 $this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_190301'), $linkDB[2]['updated']);
369 }
370
371 /**
372 * Test updateMethodDatastoreIds() with the update already applied: nothing to do.
373 */
374 public function testDatastoreIdsNothingToDo()
375 {
376 $refDB = new ReferenceLinkDB();
377 $refDB->write(self::$testDatastore);
378 $linkDB = new LinkDB(self::$testDatastore, true, false);
379
380 $this->conf->set('resource.data_dir', 'sandbox');
381 $this->conf->set('resource.datastore', self::$testDatastore);
382
383 $checksum = hash_file('sha1', self::$testDatastore);
384 $updater = new Updater(array(), $linkDB, $this->conf, true);
385 $this->assertTrue($updater->updateMethodDatastoreIds());
386 $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
387 }
290} 388}
diff --git a/tests/plugins/PluginIssoTest.php b/tests/plugins/PluginIssoTest.php
index 1f545c7d..ea86a05c 100644
--- a/tests/plugins/PluginIssoTest.php
+++ b/tests/plugins/PluginIssoTest.php
@@ -47,12 +47,13 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
47 $conf->set('plugins.ISSO_SERVER', 'value'); 47 $conf->set('plugins.ISSO_SERVER', 'value');
48 48
49 $str = 'http://randomstr.com/test'; 49 $str = 'http://randomstr.com/test';
50 $date = '20161118_100001';
50 $data = array( 51 $data = array(
51 'title' => $str, 52 'title' => $str,
52 'links' => array( 53 'links' => array(
53 array( 54 array(
54 'url' => $str, 55 'url' => $str,
55 'linkdate' => 'abc', 56 'created' => DateTime::createFromFormat('Ymd_His', $date),
56 ) 57 )
57 ) 58 )
58 ); 59 );
@@ -65,7 +66,7 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
65 66
66 // plugin data 67 // plugin data
67 $this->assertEquals(1, count($data['plugin_end_zone'])); 68 $this->assertEquals(1, count($data['plugin_end_zone']));
68 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc')); 69 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date));
69 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js')); 70 $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
70 } 71 }
71 72
@@ -78,16 +79,18 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
78 $conf->set('plugins.ISSO_SERVER', 'value'); 79 $conf->set('plugins.ISSO_SERVER', 'value');
79 80
80 $str = 'http://randomstr.com/test'; 81 $str = 'http://randomstr.com/test';
82 $date1 = '20161118_100001';
83 $date2 = '20161118_100002';
81 $data = array( 84 $data = array(
82 'title' => $str, 85 'title' => $str,
83 'links' => array( 86 'links' => array(
84 array( 87 array(
85 'url' => $str, 88 'url' => $str,
86 'linkdate' => 'abc', 89 'created' => DateTime::createFromFormat('Ymd_His', $date1),
87 ), 90 ),
88 array( 91 array(
89 'url' => $str . '2', 92 'url' => $str . '2',
90 'linkdate' => 'abc2', 93 'created' => DateTime::createFromFormat('Ymd_His', $date2),
91 ), 94 ),
92 ) 95 )
93 ); 96 );
@@ -106,12 +109,13 @@ class PluginIssoTest extends PHPUnit_Framework_TestCase
106 $conf->set('plugins.ISSO_SERVER', 'value'); 109 $conf->set('plugins.ISSO_SERVER', 'value');
107 110
108 $str = 'http://randomstr.com/test'; 111 $str = 'http://randomstr.com/test';
112 $date = '20161118_100001';
109 $data = array( 113 $data = array(
110 'title' => $str, 114 'title' => $str,
111 'links' => array( 115 'links' => array(
112 array( 116 array(
113 'url' => $str, 117 'url' => $str,
114 'linkdate' => 'abc', 118 'created' => DateTime::createFromFormat('Ymd_His', $date),
115 ) 119 )
116 ), 120 ),
117 'search_term' => $str 121 'search_term' => $str
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index abca4656..6b16c9e8 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -4,7 +4,7 @@
4 */ 4 */
5class ReferenceLinkDB 5class ReferenceLinkDB
6{ 6{
7 public static $NB_LINKS_TOTAL = 7; 7 public static $NB_LINKS_TOTAL = 8;
8 8
9 private $_links = array(); 9 private $_links = array();
10 private $_publicCount = 0; 10 private $_publicCount = 0;
@@ -16,66 +16,87 @@ class ReferenceLinkDB
16 public function __construct() 16 public function __construct()
17 { 17 {
18 $this->addLink( 18 $this->addLink(
19 41,
19 'Link title: @website', 20 'Link title: @website',
20 '?WDWyig', 21 '?WDWyig',
21 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag', 22 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
22 0, 23 0,
23 '20150310_114651', 24 DateTime::createFromFormat('Ymd_His', '20150310_114651'),
24 'sTuff' 25 'sTuff',
26 null,
27 'WDWyig'
25 ); 28 );
26 29
27 $this->addLink( 30 $this->addLink(
31 42,
32 'Note: I have a big ID but an old date',
33 '?WDWyig',
34 'Used to test links reordering.',
35 0,
36 DateTime::createFromFormat('Ymd_His', '20100310_101010'),
37 'ut'
38 );
39
40 $this->addLink(
41 8,
28 'Free as in Freedom 2.0 @website', 42 'Free as in Freedom 2.0 @website',
29 'https://static.fsf.org/nosvn/faif-2.0.pdf', 43 'https://static.fsf.org/nosvn/faif-2.0.pdf',
30 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', 44 'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
31 0, 45 0,
32 '20150310_114633', 46 DateTime::createFromFormat('Ymd_His', '20150310_114633'),
33 'free gnu software stallman -exclude stuff hashtag', 47 'free gnu software stallman -exclude stuff hashtag',
34 '20160803_093033' 48 DateTime::createFromFormat('Ymd_His', '20160803_093033')
35 ); 49 );
36 50
37 $this->addLink( 51 $this->addLink(
52 7,
38 'MediaGoblin', 53 'MediaGoblin',
39 'http://mediagoblin.org/', 54 'http://mediagoblin.org/',
40 'A free software media publishing platform #hashtagOther', 55 'A free software media publishing platform #hashtagOther',
41 0, 56 0,
42 '20130614_184135', 57 DateTime::createFromFormat('Ymd_His', '20130614_184135'),
43 'gnu media web .hidden hashtag' 58 'gnu media web .hidden hashtag',
59 null,
60 'IuWvgA'
44 ); 61 );
45 62
46 $this->addLink( 63 $this->addLink(
64 6,
47 'w3c-markup-validator', 65 'w3c-markup-validator',
48 'https://dvcs.w3.org/hg/markup-validator/summary', 66 'https://dvcs.w3.org/hg/markup-validator/summary',
49 'Mercurial repository for the W3C Validator #private', 67 'Mercurial repository for the W3C Validator #private',
50 1, 68 1,
51 '20141125_084734', 69 DateTime::createFromFormat('Ymd_His', '20141125_084734'),
52 'css html w3c web Mercurial' 70 'css html w3c web Mercurial'
53 ); 71 );
54 72
55 $this->addLink( 73 $this->addLink(
74 4,
56 'UserFriendly - Web Designer', 75 'UserFriendly - Web Designer',
57 'http://ars.userfriendly.org/cartoons/?id=20121206', 76 'http://ars.userfriendly.org/cartoons/?id=20121206',
58 'Naming conventions... #private', 77 'Naming conventions... #private',
59 0, 78 0,
60 '20121206_142300', 79 DateTime::createFromFormat('Ymd_His', '20121206_142300'),
61 'dev cartoon web' 80 'dev cartoon web'
62 ); 81 );
63 82
64 $this->addLink( 83 $this->addLink(
84 1,
65 'UserFriendly - Samba', 85 'UserFriendly - Samba',
66 'http://ars.userfriendly.org/cartoons/?id=20010306', 86 'http://ars.userfriendly.org/cartoons/?id=20010306',
67 'Tropical printing', 87 'Tropical printing',
68 0, 88 0,
69 '20121206_172539', 89 DateTime::createFromFormat('Ymd_His', '20121206_172539'),
70 'samba cartoon web' 90 'samba cartoon web'
71 ); 91 );
72 92
73 $this->addLink( 93 $this->addLink(
94 0,
74 'Geek and Poke', 95 'Geek and Poke',
75 'http://geek-and-poke.com/', 96 'http://geek-and-poke.com/',
76 '', 97 '',
77 1, 98 1,
78 '20121206_182539', 99 DateTime::createFromFormat('Ymd_His', '20121206_182539'),
79 'dev cartoon tag1 tag2 tag3 tag4 ' 100 'dev cartoon tag1 tag2 tag3 tag4 '
80 ); 101 );
81 } 102 }
@@ -83,18 +104,20 @@ class ReferenceLinkDB
83 /** 104 /**
84 * Adds a new link 105 * Adds a new link
85 */ 106 */
86 protected function addLink($title, $url, $description, $private, $date, $tags, $updated = '') 107 protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '')
87 { 108 {
88 $link = array( 109 $link = array(
110 'id' => $id,
89 'title' => $title, 111 'title' => $title,
90 'url' => $url, 112 'url' => $url,
91 'description' => $description, 113 'description' => $description,
92 'private' => $private, 114 'private' => $private,
93 'linkdate' => $date,
94 'tags' => $tags, 115 'tags' => $tags,
116 'created' => $date,
95 'updated' => $updated, 117 'updated' => $updated,
118 'shorturl' => $shorturl ? $shorturl : smallHash($date->format('Ymd_His') . $id),
96 ); 119 );
97 $this->_links[$date] = $link; 120 $this->_links[$id] = $link;
98 121
99 if ($private) { 122 if ($private) {
100 $this->_privateCount++; 123 $this->_privateCount++;
@@ -142,4 +165,14 @@ class ReferenceLinkDB
142 { 165 {
143 return $this->_links; 166 return $this->_links;
144 } 167 }
168
169 /**
170 * Setter to override link creation.
171 *
172 * @param array $links List of links.
173 */
174 public function setLinks($links)
175 {
176 $this->_links = $links;
177 }
145} 178}