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/CurlUtils.php | |
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/CurlUtils.php')
-rw-r--r-- | tests/utils/CurlUtils.php | 94 |
1 files changed, 94 insertions, 0 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 | } | ||