File: Tests-Use-mocked-Guzzle-client-in-Modcss-action-test.patch

package info (click to toggle)
roundcube 1.6.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,880 kB
  • sloc: javascript: 195,591; php: 76,888; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (57 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 17 Dec 2023 14:02:51 +0100
Subject: Tests: Use mocked Guzzle client in Modcss action test

Origin: https://github.com/roundcube/roundcubemail/commit/2546d2e2e728eb187167a356243138da7a39d796
Forwarded: not-needed
---
 tests/Actions/Utils/Modcss.php |  5 +++++
 tests/bootstrap.php            | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/tests/Actions/Utils/Modcss.php b/tests/Actions/Utils/Modcss.php
index 232e912..1081886 100644
--- a/tests/Actions/Utils/Modcss.php
+++ b/tests/Actions/Utils/Modcss.php
@@ -47,6 +47,11 @@ class Actions_Utils_Modcss extends ActionTestCase
         // Valid url pointing to non-existing resource
         $_SESSION['modcssurls'][$key] = $url;
 
+        setHttpClientMock([
+            ['code' => 404],
+            ['code' => 200, 'headers' => ['Content-Type' => 'text/css'], 'response' => 'div.pre { display: none; }'],
+        ]);
+
         $this->runAndAssert($action, OutputHtmlMock::E_EXIT);
 
         $this->assertSame(404, $output->getProperty('errorCode'));
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 6cfd610..e49cda4 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -128,3 +128,25 @@ function getHTMLNodes($html, $xpath_query)
 
     return $xpath->query($xpath_query);
 }
+
+/**
+ * Mock Guzzle HTTP Client
+ */
+function setHttpClientMock(array $responses)
+{
+    foreach ($responses as $idx => $response) {
+        if (is_array($response)) {
+            $responses[$idx] = new \GuzzleHttp\Psr7\Response(
+                $response['code'] ?? 200,
+                $response['headers'] ?? [],
+                $response['response'] ?? ''
+            );
+        }
+    }
+
+    $mock = new \GuzzleHttp\Handler\MockHandler($responses);
+    $handler = \GuzzleHttp\HandlerStack::create($mock);
+    $rcube = rcube::get_instance();
+
+    $rcube->config->set('http_client', ['handler' => $handler]);
+}