diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:07:13 +0200 |
commit | d9f6275ebca035fec8331652c677981056793ccc (patch) | |
tree | 37a64baf4f0eba6b781040605965383d8aded2cc /tests/utils | |
parent | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff) | |
parent | d63ff87a009313141ae684ec447b902562ff6ee7 (diff) | |
download | Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.gz Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.zst Shaarli-d9f6275ebca035fec8331652c677981056793ccc.zip |
Merge branch 'v0.11' into stablestable
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 | 3 | ||||
-rw-r--r-- | tests/utils/config/configPhp.php | 2 |
5 files changed, 120 insertions, 1 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 59679e38..c12bcb67 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -1,4 +1,7 @@ | |||
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 | */ |
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php index 34b11fcd..7dc81e22 100644 --- a/tests/utils/config/configPhp.php +++ b/tests/utils/config/configPhp.php | |||
@@ -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'; |