aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/CurlUtils.php94
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 */
14function 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 */
32function 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 */
50function 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 */
68function 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 */
86function 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}