]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/utils/ReferenceLinkDB.php
Unit Test for the new ID system
[github/shaarli/Shaarli.git] / tests / utils / ReferenceLinkDB.php
1 <?php
2 /**
3 * Populates a reference datastore to test LinkDB
4 */
5 class ReferenceLinkDB
6 {
7 public static $NB_LINKS_TOTAL = 8;
8
9 private $_links = array();
10 private $_publicCount = 0;
11 private $_privateCount = 0;
12
13 /**
14 * Populates the test DB with reference data
15 */
16 public function __construct()
17 {
18 $this->addLink(
19 41,
20 'Link title: @website',
21 '?WDWyig',
22 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
23 0,
24 DateTime::createFromFormat('Ymd_His', '20150310_114651'),
25 'sTuff',
26 null,
27 'WDWyig'
28 );
29
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,
42 'Free as in Freedom 2.0 @website',
43 'https://static.fsf.org/nosvn/faif-2.0.pdf',
44 'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
45 0,
46 DateTime::createFromFormat('Ymd_His', '20150310_114633'),
47 'free gnu software stallman -exclude stuff hashtag',
48 DateTime::createFromFormat('Ymd_His', '20160803_093033')
49 );
50
51 $this->addLink(
52 7,
53 'MediaGoblin',
54 'http://mediagoblin.org/',
55 'A free software media publishing platform #hashtagOther',
56 0,
57 DateTime::createFromFormat('Ymd_His', '20130614_184135'),
58 'gnu media web .hidden hashtag',
59 null,
60 'IuWvgA'
61 );
62
63 $this->addLink(
64 6,
65 'w3c-markup-validator',
66 'https://dvcs.w3.org/hg/markup-validator/summary',
67 'Mercurial repository for the W3C Validator #private',
68 1,
69 DateTime::createFromFormat('Ymd_His', '20141125_084734'),
70 'css html w3c web Mercurial'
71 );
72
73 $this->addLink(
74 4,
75 'UserFriendly - Web Designer',
76 'http://ars.userfriendly.org/cartoons/?id=20121206',
77 'Naming conventions... #private',
78 0,
79 DateTime::createFromFormat('Ymd_His', '20121206_142300'),
80 'dev cartoon web'
81 );
82
83 $this->addLink(
84 1,
85 'UserFriendly - Samba',
86 'http://ars.userfriendly.org/cartoons/?id=20010306',
87 'Tropical printing',
88 0,
89 DateTime::createFromFormat('Ymd_His', '20121206_172539'),
90 'samba cartoon web'
91 );
92
93 $this->addLink(
94 0,
95 'Geek and Poke',
96 'http://geek-and-poke.com/',
97 '',
98 1,
99 DateTime::createFromFormat('Ymd_His', '20121206_182539'),
100 'dev cartoon tag1 tag2 tag3 tag4 '
101 );
102 }
103
104 /**
105 * Adds a new link
106 */
107 protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '')
108 {
109 $link = array(
110 'id' => $id,
111 'title' => $title,
112 'url' => $url,
113 'description' => $description,
114 'private' => $private,
115 'tags' => $tags,
116 'created' => $date,
117 'updated' => $updated,
118 'shorturl' => $shorturl ? $shorturl : smallHash($date->format('Ymd_His') . $id),
119 );
120 $this->_links[$id] = $link;
121
122 if ($private) {
123 $this->_privateCount++;
124 return;
125 }
126 $this->_publicCount++;
127 }
128
129 /**
130 * Writes data to the datastore
131 */
132 public function write($filename)
133 {
134 file_put_contents(
135 $filename,
136 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>'
137 );
138 }
139
140 /**
141 * Returns the number of links in the reference data
142 */
143 public function countLinks()
144 {
145 return $this->_publicCount + $this->_privateCount;
146 }
147
148 /**
149 * Returns the number of public links in the reference data
150 */
151 public function countPublicLinks()
152 {
153 return $this->_publicCount;
154 }
155
156 /**
157 * Returns the number of private links in the reference data
158 */
159 public function countPrivateLinks()
160 {
161 return $this->_privateCount;
162 }
163
164 public function getLinks()
165 {
166 return $this->_links;
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 }
178 }