diff options
Diffstat (limited to 'tests/utils')
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php new file mode 100644 index 00000000..2cb05bae --- /dev/null +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -0,0 +1,128 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Populates a reference datastore to test LinkDB | ||
4 | */ | ||
5 | class ReferenceLinkDB | ||
6 | { | ||
7 | private $links = array(); | ||
8 | private $publicCount = 0; | ||
9 | private $privateCount = 0; | ||
10 | |||
11 | /** | ||
12 | * Populates the test DB with reference data | ||
13 | */ | ||
14 | function __construct() | ||
15 | { | ||
16 | $this->addLink( | ||
17 | 'Free as in Freedom 2.0', | ||
18 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', | ||
19 | 'Richard Stallman and the Free Software Revolution', | ||
20 | 0, | ||
21 | '20150310_114633', | ||
22 | 'free gnu software stallman' | ||
23 | ); | ||
24 | |||
25 | $this->addLink( | ||
26 | 'MediaGoblin', | ||
27 | 'http://mediagoblin.org/', | ||
28 | 'A free software media publishing platform', | ||
29 | 0, | ||
30 | '20130614_184135', | ||
31 | 'gnu media web' | ||
32 | ); | ||
33 | |||
34 | $this->addLink( | ||
35 | 'w3c-markup-validator', | ||
36 | 'https://dvcs.w3.org/hg/markup-validator/summary', | ||
37 | 'Mercurial repository for the W3C Validator', | ||
38 | 1, | ||
39 | '20141125_084734', | ||
40 | 'css html w3c web Mercurial' | ||
41 | ); | ||
42 | |||
43 | $this->addLink( | ||
44 | 'UserFriendly - Web Designer', | ||
45 | 'http://ars.userfriendly.org/cartoons/?id=20121206', | ||
46 | 'Naming conventions...', | ||
47 | 0, | ||
48 | '20121206_142300', | ||
49 | 'dev cartoon web' | ||
50 | ); | ||
51 | |||
52 | $this->addLink( | ||
53 | 'UserFriendly - Samba', | ||
54 | 'http://ars.userfriendly.org/cartoons/?id=20010306', | ||
55 | 'Tropical printing', | ||
56 | 0, | ||
57 | '20121206_172539', | ||
58 | 'samba cartoon web' | ||
59 | ); | ||
60 | |||
61 | $this->addLink( | ||
62 | 'Geek and Poke', | ||
63 | 'http://geek-and-poke.com/', | ||
64 | '', | ||
65 | 1, | ||
66 | '20121206_182539', | ||
67 | 'dev cartoon' | ||
68 | ); | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * Adds a new link | ||
73 | */ | ||
74 | protected function addLink($title, $url, $description, $private, $date, $tags) | ||
75 | { | ||
76 | $link = array( | ||
77 | 'title' => $title, | ||
78 | 'url' => $url, | ||
79 | 'description' => $description, | ||
80 | 'private' => $private, | ||
81 | 'linkdate' => $date, | ||
82 | 'tags' => $tags, | ||
83 | ); | ||
84 | $this->links[$date] = $link; | ||
85 | |||
86 | if ($private) { | ||
87 | $this->privateCount++; | ||
88 | return; | ||
89 | } | ||
90 | $this->publicCount++; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Writes data to the datastore | ||
95 | */ | ||
96 | public function write($filename, $prefix, $suffix) | ||
97 | { | ||
98 | file_put_contents( | ||
99 | $filename, | ||
100 | $prefix.base64_encode(gzdeflate(serialize($this->links))).$suffix | ||
101 | ); | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * Returns the number of links in the reference data | ||
106 | */ | ||
107 | public function countLinks() | ||
108 | { | ||
109 | return $this->publicCount + $this->privateCount; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * Returns the number of public links in the reference data | ||
114 | */ | ||
115 | public function countPublicLinks() | ||
116 | { | ||
117 | return $this->publicCount; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Returns the number of private links in the reference data | ||
122 | */ | ||
123 | public function countPrivateLinks() | ||
124 | { | ||
125 | return $this->privateCount; | ||
126 | } | ||
127 | } | ||
128 | ?> | ||