about summary refs log tree commit diff stats
path: root/tests_integration/LogoutHandlerTest.php
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-05-27 21:19:36 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-05-27 21:19:39 +0300
commitb434f9127fc67d97ed224b22594ecbd232fa4da3 (patch)
tree90449be52f3d9b85f449cc65707a75e82cc81b3a /tests_integration/LogoutHandlerTest.php
parent2b28a847f97395d756d16400ce3fb29b8c8bb75e (diff)
downloadthe-epube-b434f9127fc67d97ed224b22594ecbd232fa4da3.tar.gz
the-epube-b434f9127fc67d97ed224b22594ecbd232fa4da3.tar.xz
cleanup return values a bit (more json), move common API test stuff to an ancestor class
Diffstat (limited to 'tests_integration/LogoutHandlerTest.php')
-rw-r--r--tests_integration/LogoutHandlerTest.php47
1 files changed, 5 insertions, 42 deletions
diff --git a/tests_integration/LogoutHandlerTest.php b/tests_integration/LogoutHandlerTest.php
index 4495872..93ee596 100644
--- a/tests_integration/LogoutHandlerTest.php
+++ b/tests_integration/LogoutHandlerTest.php
@@ -1,47 +1,8 @@
 <?php
 use PHPUnit\Framework\TestCase;
 
-final class LogoutHandlerTest extends TestCase
+final class LogoutHandlerTest extends ApiTestCase
 {
-	private string $apiUrl;
-
-	protected function setUp(): void
-	{
-		$this->apiUrl = getenv('API_URL') ?: 'http://localhost:9080/backend.php';
-	}
-
-	/**
-	 * Make an HTTP POST request and return [status_code, decoded_body].
-	 * @param array<string, string> $data
-	 * @return array<int, mixed>
-	 */
-	private function post(string $endpoint, array $data, ?string $cookieFile = null): array
-	{
-		$ch = curl_init($endpoint);
-		curl_setopt_array($ch, [
-			CURLOPT_RETURNTRANSFER => true,
-			CURLOPT_POST           => true,
-			CURLOPT_POSTFIELDS     => http_build_query($data),
-			CURLOPT_TIMEOUT        => 10,
-			CURLOPT_CONNECTTIMEOUT => 5,
-			CURLOPT_COOKIEFILE     => $cookieFile ?? '',
-			CURLOPT_COOKIEJAR      => $cookieFile ?? '',
-		]);
-		$body    = curl_exec($ch);
-		$status  = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-		$errno   = curl_errno($ch);
-		$error   = curl_error($ch);
-		curl_close($ch);
-
-		if ($errno) {
-			$this->fail("cURL error ($errno): $error");
-		}
-
-		/** @var array<string, mixed>|null $decoded */
-		$decoded = json_decode($body, true);
-		return [$status, $decoded ?? []];
-	}
-
 	// ── Successful logout ─────────────────────────────────────────────────────
 
 	public function test_logout_returns_ok(): void
@@ -63,8 +24,10 @@ final class LogoutHandlerTest extends TestCase
 			'op' => 'logout',
 		], $cookieFile);
 
+		print_r($body);
+
 		$this->assertEquals(200, $status);
-		$this->assertEquals('OK', $body['result'] ?? null);
+		$this->assertEquals('ok', $body['result'] ?? null);
 
 		unlink($cookieFile);
 	}
@@ -79,7 +42,7 @@ final class LogoutHandlerTest extends TestCase
 		$this->post($this->apiUrl, [
 			'op'       => 'perform-login',
 			'user'     => 'test',
-			'password' => 'test',
+			'password' => 'test1',
 		], $cookieFile);
 
 		// Step 2: Logout