diff options
Diffstat (limited to 'tests/utils')
-rw-r--r-- | tests/utils/CurlUtils.php | 94 | ||||
-rw-r--r-- | tests/utils/FakeApplicationUtils.php | 19 | ||||
-rw-r--r-- | tests/utils/ReferenceHistory.php | 3 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 52 | ||||
-rw-r--r-- | tests/utils/config/configJson.json.php | 71 | ||||
-rw-r--r-- | tests/utils/config/configPhp.php | 4 | ||||
-rw-r--r-- | tests/utils/config/wt.json | 12 |
7 files changed, 238 insertions, 17 deletions
diff --git a/tests/utils/CurlUtils.php b/tests/utils/CurlUtils.php new file mode 100644 index 00000000..1cc4907e --- /dev/null +++ b/tests/utils/CurlUtils.php | |||
@@ -0,0 +1,94 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Old-style mock for cURL, as PHPUnit doesn't allow to mock global functions | ||
4 | */ | ||
5 | |||
6 | /** | ||
7 | * Returns code 200 or html content type. | ||
8 | * | ||
9 | * @param resource $ch cURL resource | ||
10 | * @param int $type cURL info type | ||
11 | * | ||
12 | * @return int|string 200 or 'text/html' | ||
13 | */ | ||
14 | function ut_curl_getinfo_ok($ch, $type) | ||
15 | { | ||
16 | switch ($type) { | ||
17 | case CURLINFO_RESPONSE_CODE: | ||
18 | return 200; | ||
19 | case CURLINFO_CONTENT_TYPE: | ||
20 | return 'text/html; charset=utf-8'; | ||
21 | } | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Returns code 200 or html content type without charset. | ||
26 | * | ||
27 | * @param resource $ch cURL resource | ||
28 | * @param int $type cURL info type | ||
29 | * | ||
30 | * @return int|string 200 or 'text/html' | ||
31 | */ | ||
32 | function ut_curl_getinfo_no_charset($ch, $type) | ||
33 | { | ||
34 | switch ($type) { | ||
35 | case CURLINFO_RESPONSE_CODE: | ||
36 | return 200; | ||
37 | case CURLINFO_CONTENT_TYPE: | ||
38 | return 'text/html'; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Invalid response code. | ||
44 | * | ||
45 | * @param resource $ch cURL resource | ||
46 | * @param int $type cURL info type | ||
47 | * | ||
48 | * @return int|string 404 or 'text/html' | ||
49 | */ | ||
50 | function ut_curl_getinfo_rc_ko($ch, $type) | ||
51 | { | ||
52 | switch ($type) { | ||
53 | case CURLINFO_RESPONSE_CODE: | ||
54 | return 404; | ||
55 | case CURLINFO_CONTENT_TYPE: | ||
56 | return 'text/html; charset=utf-8'; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Invalid content type. | ||
62 | * | ||
63 | * @param resource $ch cURL resource | ||
64 | * @param int $type cURL info type | ||
65 | * | ||
66 | * @return int|string 200 or 'text/plain' | ||
67 | */ | ||
68 | function ut_curl_getinfo_ct_ko($ch, $type) | ||
69 | { | ||
70 | switch ($type) { | ||
71 | case CURLINFO_RESPONSE_CODE: | ||
72 | return 200; | ||
73 | case CURLINFO_CONTENT_TYPE: | ||
74 | return 'text/plain'; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * Invalid response code and content type. | ||
80 | * | ||
81 | * @param resource $ch cURL resource | ||
82 | * @param int $type cURL info type | ||
83 | * | ||
84 | * @return int|string 404 or 'text/plain' | ||
85 | */ | ||
86 | function ut_curl_getinfo_rs_ct_ko($ch, $type) | ||
87 | { | ||
88 | switch ($type) { | ||
89 | case CURLINFO_RESPONSE_CODE: | ||
90 | return 404; | ||
91 | case CURLINFO_CONTENT_TYPE: | ||
92 | return 'text/plain'; | ||
93 | } | ||
94 | } | ||
diff --git a/tests/utils/FakeApplicationUtils.php b/tests/utils/FakeApplicationUtils.php new file mode 100644 index 00000000..de83d598 --- /dev/null +++ b/tests/utils/FakeApplicationUtils.php | |||
@@ -0,0 +1,19 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Shaarli; | ||
4 | |||
5 | /** | ||
6 | * Fake ApplicationUtils class to avoid HTTP requests | ||
7 | */ | ||
8 | class FakeApplicationUtils extends ApplicationUtils | ||
9 | { | ||
10 | public static $VERSION_CODE = ''; | ||
11 | |||
12 | /** | ||
13 | * Toggle HTTP requests, allow overriding the version code | ||
14 | */ | ||
15 | public static function getVersion($url, $timeout = 0) | ||
16 | { | ||
17 | return self::$VERSION_CODE; | ||
18 | } | ||
19 | } | ||
diff --git a/tests/utils/ReferenceHistory.php b/tests/utils/ReferenceHistory.php index 75cbb326..e411c417 100644 --- a/tests/utils/ReferenceHistory.php +++ b/tests/utils/ReferenceHistory.php | |||
@@ -1,5 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | use Shaarli\FileUtils; | ||
4 | use Shaarli\History; | ||
5 | |||
3 | /** | 6 | /** |
4 | * Populates a reference history | 7 | * Populates a reference history |
5 | */ | 8 | */ |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index e887aa78..c12bcb67 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -1,10 +1,13 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
3 | use Shaarli\Bookmark\LinkDB; | ||
4 | |||
2 | /** | 5 | /** |
3 | * Populates a reference datastore to test LinkDB | 6 | * Populates a reference datastore to test LinkDB |
4 | */ | 7 | */ |
5 | class ReferenceLinkDB | 8 | class ReferenceLinkDB |
6 | { | 9 | { |
7 | public static $NB_LINKS_TOTAL = 9; | 10 | public static $NB_LINKS_TOTAL = 11; |
8 | 11 | ||
9 | private $_links = array(); | 12 | private $_links = array(); |
10 | private $_publicCount = 0; | 13 | private $_publicCount = 0; |
@@ -16,6 +19,32 @@ class ReferenceLinkDB | |||
16 | public function __construct() | 19 | public function __construct() |
17 | { | 20 | { |
18 | $this->addLink( | 21 | $this->addLink( |
22 | 11, | ||
23 | 'Pined older', | ||
24 | '?PCRizQ', | ||
25 | 'This is an older pinned link', | ||
26 | 0, | ||
27 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100309_101010'), | ||
28 | '', | ||
29 | null, | ||
30 | 'PCRizQ', | ||
31 | true | ||
32 | ); | ||
33 | |||
34 | $this->addLink( | ||
35 | 10, | ||
36 | 'Pined', | ||
37 | '?0gCTjQ', | ||
38 | 'This is a pinned link', | ||
39 | 0, | ||
40 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121207_152312'), | ||
41 | '', | ||
42 | null, | ||
43 | '0gCTjQ', | ||
44 | true | ||
45 | ); | ||
46 | |||
47 | $this->addLink( | ||
19 | 41, | 48 | 41, |
20 | 'Link title: @website', | 49 | 'Link title: @website', |
21 | '?WDWyig', | 50 | '?WDWyig', |
@@ -114,8 +143,18 @@ class ReferenceLinkDB | |||
114 | /** | 143 | /** |
115 | * Adds a new link | 144 | * Adds a new link |
116 | */ | 145 | */ |
117 | protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '') | 146 | protected function addLink( |
118 | { | 147 | $id, |
148 | $title, | ||
149 | $url, | ||
150 | $description, | ||
151 | $private, | ||
152 | $date, | ||
153 | $tags, | ||
154 | $updated = '', | ||
155 | $shorturl = '', | ||
156 | $pinned = false | ||
157 | ) { | ||
119 | $link = array( | 158 | $link = array( |
120 | 'id' => $id, | 159 | 'id' => $id, |
121 | 'title' => $title, | 160 | 'title' => $title, |
@@ -126,6 +165,7 @@ class ReferenceLinkDB | |||
126 | 'created' => $date, | 165 | 'created' => $date, |
127 | 'updated' => $updated, | 166 | 'updated' => $updated, |
128 | 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), | 167 | 'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id), |
168 | 'sticky' => $pinned | ||
129 | ); | 169 | ); |
130 | $this->_links[$id] = $link; | 170 | $this->_links[$id] = $link; |
131 | 171 | ||
@@ -164,7 +204,11 @@ class ReferenceLinkDB | |||
164 | 204 | ||
165 | $order = $order === 'ASC' ? -1 : 1; | 205 | $order = $order === 'ASC' ? -1 : 1; |
166 | // Reorder array by dates. | 206 | // Reorder array by dates. |
167 | usort($this->_links, function($a, $b) use ($order) { | 207 | usort($this->_links, function ($a, $b) use ($order) { |
208 | if (isset($a['sticky']) && isset($b['sticky']) && $a['sticky'] !== $b['sticky']) { | ||
209 | return $a['sticky'] ? -1 : 1; | ||
210 | } | ||
211 | |||
168 | return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; | 212 | return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; |
169 | }); | 213 | }); |
170 | } | 214 | } |
diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 9c9288f3..1549ddfc 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php | |||
@@ -1,35 +1,84 @@ | |||
1 | <?php /* | 1 | <?php /* |
2 | { | 2 | { |
3 | "credentials": { | 3 | "credentials": { |
4 | "login":"root", | 4 | "login": "root", |
5 | "hash":"hash", | 5 | "hash": "hash", |
6 | "salt":"salt" | 6 | "salt": "salt" |
7 | }, | 7 | }, |
8 | "security": { | 8 | "security": { |
9 | "session_protection_disabled":false | 9 | "session_protection_disabled": false, |
10 | "ban_after": 4, | ||
11 | "ban_duration": 1800, | ||
12 | "open_shaarli": false, | ||
13 | "allowed_protocols": [ | ||
14 | "ftp", | ||
15 | "ftps", | ||
16 | "magnet" | ||
17 | ] | ||
10 | }, | 18 | }, |
11 | "general": { | 19 | "general": { |
12 | "timezone":"Europe\/Paris", | 20 | "timezone": "Europe\/Paris", |
13 | "title": "Shaarli", | 21 | "title": "Shaarli", |
14 | "header_link": "?" | 22 | "header_link": "?", |
23 | "links_per_page": 20, | ||
24 | "enabled_plugins": [ | ||
25 | "qrcode" | ||
26 | ], | ||
27 | "default_note_title": "Note: " | ||
15 | }, | 28 | }, |
16 | "privacy": { | 29 | "privacy": { |
17 | "default_private_links":true | 30 | "default_private_links": true, |
31 | "hide_public_links": false, | ||
32 | "force_login": false, | ||
33 | "hide_timestamps": false, | ||
34 | "remember_user_default": true | ||
18 | }, | 35 | }, |
19 | "redirector": { | 36 | "redirector": { |
20 | "url":"lala" | 37 | "url": "lala", |
38 | "encode_url": true | ||
21 | }, | 39 | }, |
22 | "config": { | 40 | "config": { |
23 | "foo": "bar" | 41 | "foo": "bar" |
24 | }, | 42 | }, |
25 | "resource": { | 43 | "resource": { |
26 | "datastore": "tests\/utils\/config\/datastore.php", | 44 | "datastore": "tests\/utils\/config\/datastore.php", |
27 | "data_dir": "sandbox/", | 45 | "data_dir": "sandbox\/", |
28 | "raintpl_tpl": "tpl/" | 46 | "raintpl_tpl": "tpl\/", |
47 | "config": "data\/config.php", | ||
48 | "ban_file": "data\/ipbans.php", | ||
49 | "updates": "data\/updates.txt", | ||
50 | "log": "data\/log.txt", | ||
51 | "update_check": "data\/lastupdatecheck.txt", | ||
52 | "history": "data\/history.php", | ||
53 | "theme": "default", | ||
54 | "raintpl_tmp": "tmp\/", | ||
55 | "thumbnails_cache": "cache", | ||
56 | "page_cache": "pagecache" | ||
29 | }, | 57 | }, |
30 | "plugins": { | 58 | "plugins": { |
31 | "WALLABAG_VERSION": 1 | 59 | "WALLABAG_VERSION": 1 |
60 | }, | ||
61 | "dev": { | ||
62 | "debug": true | ||
63 | }, | ||
64 | "updates": { | ||
65 | "check_updates": false, | ||
66 | "check_updates_branch": "stable", | ||
67 | "check_updates_interval": 86400 | ||
68 | }, | ||
69 | "feed": { | ||
70 | "rss_permalinks": true, | ||
71 | "show_atom": true | ||
72 | }, | ||
73 | "translation": { | ||
74 | "language": "auto", | ||
75 | "mode": "php", | ||
76 | "extensions": [] | ||
77 | }, | ||
78 | "thumbnails": { | ||
79 | "mode": "common", | ||
80 | "width": 90, | ||
81 | "height": 53 | ||
32 | } | 82 | } |
33 | } | 83 | } |
34 | */ ?> | 84 | */ ?> |
35 | |||
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php index 0e034175..7dc81e22 100644 --- a/tests/utils/config/configPhp.php +++ b/tests/utils/config/configPhp.php | |||
@@ -1,4 +1,4 @@ | |||
1 | <?php | 1 | <?php |
2 | $GLOBALS['login'] = 'root'; | 2 | $GLOBALS['login'] = 'root'; |
3 | $GLOBALS['hash'] = 'hash'; | 3 | $GLOBALS['hash'] = 'hash'; |
4 | $GLOBALS['salt'] = 'salt'; | 4 | $GLOBALS['salt'] = 'salt'; |
@@ -8,7 +8,7 @@ $GLOBALS['titleLink'] = 'titleLink'; | |||
8 | $GLOBALS['redirector'] = 'lala'; | 8 | $GLOBALS['redirector'] = 'lala'; |
9 | $GLOBALS['disablesessionprotection'] = false; | 9 | $GLOBALS['disablesessionprotection'] = false; |
10 | $GLOBALS['privateLinkByDefault'] = false; | 10 | $GLOBALS['privateLinkByDefault'] = false; |
11 | $GLOBALS['config']['DATADIR'] = 'tests/Updater'; | 11 | $GLOBALS['config']['DATADIR'] = 'tests/updater'; |
12 | $GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache'; | 12 | $GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache'; |
13 | $GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; | 13 | $GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; |
14 | $GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; | 14 | $GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; |
diff --git a/tests/utils/config/wt.json b/tests/utils/config/wt.json new file mode 100644 index 00000000..69ce49a6 --- /dev/null +++ b/tests/utils/config/wt.json | |||
@@ -0,0 +1,12 @@ | |||
1 | { | ||
2 | "settings": { | ||
3 | "default": { | ||
4 | "_comment": "infinite cache", | ||
5 | "cache_duration": -1, | ||
6 | "timeout": 10 | ||
7 | }, | ||
8 | "path": { | ||
9 | "cache": "sandbox/" | ||
10 | } | ||
11 | } | ||
12 | } \ No newline at end of file | ||