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