]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/utils/ReferenceLinkDB.php
FeedBuilder unit tests
[github/shaarli/Shaarli.git] / tests / utils / ReferenceLinkDB.php
CommitLineData
ca74886f
V
1<?php
2/**
3 * Populates a reference datastore to test LinkDB
4 */
5class ReferenceLinkDB
6{
89baf23d
A
7 public static $NB_LINKS_TOTAL = 7;
8
07b6fa75
V
9 private $_links = array();
10 private $_publicCount = 0;
11 private $_privateCount = 0;
ca74886f
V
12
13 /**
14 * Populates the test DB with reference data
15 */
16 function __construct()
17 {
89baf23d
A
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.',
22 0,
23 '20150310_114651',
24 'stuff'
25 );
26
ca74886f 27 $this->addLink(
522b278b 28 'Free as in Freedom 2.0 @website',
ca74886f 29 'https://static.fsf.org/nosvn/faif-2.0.pdf',
bedd176a 30 'Richard Stallman and the Free Software Revolution. Read this.',
ca74886f
V
31 0,
32 '20150310_114633',
522b278b 33 'free gnu software stallman -exclude stuff'
ca74886f
V
34 );
35
36 $this->addLink(
37 'MediaGoblin',
38 'http://mediagoblin.org/',
39 'A free software media publishing platform',
40 0,
41 '20130614_184135',
195acf9f 42 'gnu media web .hidden'
ca74886f
V
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',
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...',
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'
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 );
07b6fa75 95 $this->_links[$date] = $link;
ca74886f
V
96
97 if ($private) {
07b6fa75 98 $this->_privateCount++;
ca74886f
V
99 return;
100 }
07b6fa75 101 $this->_publicCount++;
ca74886f
V
102 }
103
104 /**
105 * Writes data to the datastore
106 */
9c8752a2 107 public function write($filename)
ca74886f
V
108 {
109 file_put_contents(
110 $filename,
07b6fa75 111 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>'
ca74886f
V
112 );
113 }
114
115 /**
116 * Returns the number of links in the reference data
117 */
118 public function countLinks()
119 {
07b6fa75 120 return $this->_publicCount + $this->_privateCount;
ca74886f
V
121 }
122
123 /**
124 * Returns the number of public links in the reference data
125 */
126 public function countPublicLinks()
127 {
07b6fa75 128 return $this->_publicCount;
ca74886f
V
129 }
130
131 /**
132 * Returns the number of private links in the reference data
133 */
134 public function countPrivateLinks()
135 {
07b6fa75 136 return $this->_privateCount;
ca74886f 137 }
822bffce
A
138
139 public function getLinks()
140 {
141 return $this->_links;
142 }
ca74886f 143}