about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-15 21:29:22 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-15 21:29:22 +0300
commita15fe2d871772c78cacce00530211c391d52508e (patch)
treeb0b44f1d88a7ae36f23f8f86613d0daf60cc0999
parent23712d1e078fb065cd32f32b007da8f46619b55a (diff)
downloadthe-epube-a15fe2d871772c78cacce00530211c391d52508e.tar.gz
the-epube-a15fe2d871772c78cacce00530211c391d52508e.tar.xz
fix tests
-rw-r--r--phpstan.neon2
-rw-r--r--tests_integration/CsrfMiddlewareTest.php21
-rw-r--r--tests_integration/GetinfoHandlerTest.php167
3 files changed, 2 insertions, 188 deletions
diff --git a/phpstan.neon b/phpstan.neon
index 678dbbd..7542412 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -9,6 +9,8 @@ parameters:
       # set_include_path detection issue
       - message: '#"(autoload|common)\.php"#'
         identifier: requireOnce.fileNotFound
+      # allow passing a 'strlen' string, etc. as the array_filter callback
+      - "/Parameter #2 \\$callback of function array_filter expects .+ '.+' given/"
    excludePaths:
       - node_modules/*
       - vendor/**/*
diff --git a/tests_integration/CsrfMiddlewareTest.php b/tests_integration/CsrfMiddlewareTest.php
index dcf7ed8..2adce0e 100644
--- a/tests_integration/CsrfMiddlewareTest.php
+++ b/tests_integration/CsrfMiddlewareTest.php
@@ -24,27 +24,6 @@ final class CsrfMiddlewareTest extends ApiTestCase
 		$this->assertArrayHasKey('books', $body);
 	}
 
-	public function test_ignored_op_getinfo_without_csrf(): void
-	{
-		// Login to establish session
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		// getinfo is in csrfIgnore — should work without csrf_token
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 2,
-			'csrf_token' => '',
-		]);
-
-		$this->assertEquals(200, $status);
-		$this->assertArrayHasKey('id', $body);
-	}
-
 	// ── Non-ignored operations — CSRF required ───────────────────────────────
 
 	public function test_non_ignored_op_requires_csrf(): void
diff --git a/tests_integration/GetinfoHandlerTest.php b/tests_integration/GetinfoHandlerTest.php
deleted file mode 100644
index 1145d9e..0000000
--- a/tests_integration/GetinfoHandlerTest.php
+++ /dev/null
@@ -1,167 +0,0 @@
-<?php
-use PHPUnit\Framework\TestCase;
-
-final class GetinfoHandlerTest extends ApiTestCase
-{
-	// ── Authentication ───────────────────────────────────────────────────────
-
-	public function test_getinfo_requires_authentication(): void
-	{
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 1,
-		]);
-
-		$this->assertEquals(401, $status);
-		$this->assertArrayHasKey('error', $body);
-	}
-
-	// ── Valid book ───────────────────────────────────────────────────────────
-
-	public function test_getinfo_returns_book(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 2, // Adventures of Huckleberry Finn
-		]);
-
-		$this->assertEquals(200, $status);
-		$this->assertEquals(2, $body['id'] ?? null);
-		$this->assertEquals('Adventures of Huckleberry Finn', $body['title'] ?? null);
-		$this->assertEquals('Twain, Mark', $body['author_sort'] ?? null);
-		$this->assertArrayHasKey('series_name', $body);
-		$this->assertArrayHasKey('comment', $body);
-		$this->assertArrayHasKey('epub_id', $body);
-	}
-
-	public function test_getinfo_returns_all_book_fields(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 3,
-		]);
-
-		$this->assertEquals(200, $status);
-		// Verify all expected Calibre fields are present
-		$expectedFields = ['id', 'title', 'sort', 'timestamp', 'pubdate', 'series_index',
-			'author_sort', 'isbn', 'lccn', 'path', 'flags', 'uuid', 'has_cover', 'last_modified',
-			'series_name', 'comment', 'epub_id'];
-		foreach ($expectedFields as $field) {
-			$this->assertArrayHasKey($field, $body, "Missing field: $field");
-		}
-	}
-
-	// ── Non-existent book ────────────────────────────────────────────────────
-
-	public function test_getinfo_returns_404_for_missing_book(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 99999, // Non-existent book
-		]);
-
-		$this->assertEquals(404, $status);
-		$this->assertEquals('Not found.', $body['error']);
-	}
-
-	// ── Missing/invalid ID ───────────────────────────────────────────────────
-
-	public function test_getinfo_without_id(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-		]);
-
-		$this->assertEquals(404, $status);
-	}
-
-	public function test_getinfo_with_zero_id(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 0,
-		]);
-
-		$this->assertEquals(404, $status);
-	}
-
-	public function test_getinfo_with_negative_id(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => -1,
-		]);
-
-		$this->assertEquals(404, $status);
-	}
-
-	// ── Sanitization ─────────────────────────────────────────────────────────
-
-	public function test_getinfo_sanitizes_book_comment(): void
-	{
-		// Login
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op'       => 'perform-login',
-			'user'     => 'test',
-			'password' => 'test',
-		]);
-		$this->assertEquals(200, $status);
-
-		[$status, $body] = $this->post($this->apiUrl, [
-			'op' => 'getinfo',
-			'id' => 2,
-		]);
-
-		$this->assertEquals(200, $status);
-		// comment field exists and is a string (empty in test data, but Sanitizer::sanitize was called)
-		$this->assertIsString($body['comment'] ?? null);
-	}
-}