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.php51
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index 36d58c68..e887aa78 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -4,7 +4,7 @@
4 */ 4 */
5class ReferenceLinkDB 5class ReferenceLinkDB
6{ 6{
7 public static $NB_LINKS_TOTAL = 8; 7 public static $NB_LINKS_TOTAL = 9;
8 8
9 private $_links = array(); 9 private $_links = array();
10 private $_publicCount = 0; 10 private $_publicCount = 0;
@@ -38,6 +38,16 @@ class ReferenceLinkDB
38 ); 38 );
39 39
40 $this->addLink( 40 $this->addLink(
41 9,
42 'PSR-2: Coding Style Guide',
43 'http://www.php-fig.org/psr/psr-2/',
44 'This guide extends and expands on PSR-1, the basic coding standard.',
45 0,
46 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_152312'),
47 ''
48 );
49
50 $this->addLink(
41 8, 51 8,
42 'Free as in Freedom 2.0 @website', 52 'Free as in Freedom 2.0 @website',
43 'https://static.fsf.org/nosvn/faif-2.0.pdf', 53 'https://static.fsf.org/nosvn/faif-2.0.pdf',
@@ -56,7 +66,7 @@ class ReferenceLinkDB
56 0, 66 0,
57 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130614_184135'), 67 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
58 'gnu media web .hidden hashtag', 68 'gnu media web .hidden hashtag',
59 null, 69 DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130615_184230'),
60 'IuWvgA' 70 'IuWvgA'
61 ); 71 );
62 72
@@ -131,6 +141,7 @@ class ReferenceLinkDB
131 */ 141 */
132 public function write($filename) 142 public function write($filename)
133 { 143 {
144 $this->reorder();
134 file_put_contents( 145 file_put_contents(
135 $filename, 146 $filename,
136 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>' 147 '<?php /* '.base64_encode(gzdeflate(serialize($this->_links))).' */ ?>'
@@ -138,6 +149,27 @@ class ReferenceLinkDB
138 } 149 }
139 150
140 /** 151 /**
152 * Reorder links by creation date (newest first).
153 *
154 * Also update the urls and ids mapping arrays.
155 *
156 * @param string $order ASC|DESC
157 */
158 public function reorder($order = 'DESC')
159 {
160 // backward compatibility: ignore reorder if the the `created` field doesn't exist
161 if (! isset(array_values($this->_links)[0]['created'])) {
162 return;
163 }
164
165 $order = $order === 'ASC' ? -1 : 1;
166 // Reorder array by dates.
167 usort($this->_links, function($a, $b) use ($order) {
168 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
169 });
170 }
171
172 /**
141 * Returns the number of links in the reference data 173 * Returns the number of links in the reference data
142 */ 174 */
143 public function countLinks() 175 public function countLinks()
@@ -161,8 +193,23 @@ class ReferenceLinkDB
161 return $this->_privateCount; 193 return $this->_privateCount;
162 } 194 }
163 195
196 /**
197 * Returns the number of links without tag
198 */
199 public function countUntaggedLinks()
200 {
201 $cpt = 0;
202 foreach ($this->_links as $link) {
203 if (empty($link['tags'])) {
204 ++$cpt;
205 }
206 }
207 return $cpt;
208 }
209
164 public function getLinks() 210 public function getLinks()
165 { 211 {
212 $this->reorder();
166 return $this->_links; 213 return $this->_links;
167 } 214 }
168 215