aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils/ReferenceLinkDB.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils/ReferenceLinkDB.php')
-rw-r--r--tests/utils/ReferenceLinkDB.php52
1 files changed, 48 insertions, 4 deletions
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index e887aa78..c12bcb67 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -1,10 +1,13 @@
1<?php 1<?php
2
3use Shaarli\Bookmark\LinkDB;
4
2/** 5/**
3 * Populates a reference datastore to test LinkDB 6 * Populates a reference datastore to test LinkDB
4 */ 7 */
5class ReferenceLinkDB 8class ReferenceLinkDB
6{ 9{
7 public static $NB_LINKS_TOTAL = 9; 10 public static $NB_LINKS_TOTAL = 11;
8 11
9 private $_links = array(); 12 private $_links = array();
10 private $_publicCount = 0; 13 private $_publicCount = 0;
@@ -16,6 +19,32 @@ class ReferenceLinkDB
16 public function __construct() 19 public function __construct()
17 { 20 {
18 $this->addLink( 21 $this->addLink(
22 11,
23 'Pined older',
24 '?PCRizQ',
25 'This is an older pinned link',
26 0,
27 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100309_101010'),
28 '',
29 null,
30 'PCRizQ',
31 true
32 );
33
34 $this->addLink(
35 10,
36 'Pined',
37 '?0gCTjQ',
38 'This is a pinned link',
39 0,
40 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121207_152312'),
41 '',
42 null,
43 '0gCTjQ',
44 true
45 );
46
47 $this->addLink(
19 41, 48 41,
20 'Link title: @website', 49 'Link title: @website',
21 '?WDWyig', 50 '?WDWyig',
@@ -114,8 +143,18 @@ class ReferenceLinkDB
114 /** 143 /**
115 * Adds a new link 144 * Adds a new link
116 */ 145 */
117 protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '') 146 protected function addLink(
118 { 147 $id,
148 $title,
149 $url,
150 $description,
151 $private,
152 $date,
153 $tags,
154 $updated = '',
155 $shorturl = '',
156 $pinned = false
157 ) {
119 $link = array( 158 $link = array(
120 'id' => $id, 159 'id' => $id,
121 'title' => $title, 160 'title' => $title,
@@ -126,6 +165,7 @@ class ReferenceLinkDB
126 'created' => $date, 165 'created' => $date,
127 'updated' => $updated, 166 'updated' => $updated,
128 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), 167 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id),
168 'sticky' => $pinned
129 ); 169 );
130 $this->_links[$id] = $link; 170 $this->_links[$id] = $link;
131 171
@@ -164,7 +204,11 @@ class ReferenceLinkDB
164 204
165 $order = $order === 'ASC' ? -1 : 1; 205 $order = $order === 'ASC' ? -1 : 1;
166 // Reorder array by dates. 206 // Reorder array by dates.
167 usort($this->_links, function($a, $b) use ($order) { 207 usort($this->_links, function ($a, $b) use ($order) {
208 if (isset($a['sticky']) && isset($b['sticky']) && $a['sticky'] !== $b['sticky']) {
209 return $a['sticky'] ? -1 : 1;
210 }
211
168 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; 212 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
169 }); 213 });
170 } 214 }