aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/Module/ItemTest.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-11-10 18:01:06 +0000
committerMario <mario@mariovavti.com>2024-11-10 18:01:06 +0000
commit3791dfab3a73e84a007e3d8f5cd6cc4bdb014de2 (patch)
tree9a3c438b9669ca607330658d9b67616d76e7aa9c /tests/unit/Module/ItemTest.php
parent31a146b23aa7f5c6123a2ed21691944adcfbc306 (diff)
parent2c17d0b031b4081870d9ff86145e097ee257efb8 (diff)
downloadvolse-hubzilla-3791dfab3a73e84a007e3d8f5cd6cc4bdb014de2.tar.gz
volse-hubzilla-3791dfab3a73e84a007e3d8f5cd6cc4bdb014de2.tar.bz2
volse-hubzilla-3791dfab3a73e84a007e3d8f5cd6cc4bdb014de2.zip
Merge branch 'begin-refactoring-module-item' into 'dev'
Begin refactoring Module\Item See merge request hubzilla/core!2166
Diffstat (limited to 'tests/unit/Module/ItemTest.php')
-rw-r--r--tests/unit/Module/ItemTest.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/unit/Module/ItemTest.php b/tests/unit/Module/ItemTest.php
new file mode 100644
index 000000000..b461a3685
--- /dev/null
+++ b/tests/unit/Module/ItemTest.php
@@ -0,0 +1,56 @@
+<?php
+/*
+ * SPDX-FileCopyrightText: 2024 Hubzilla Community
+ * SPDX-FileContributor: Harald Eilertsen
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+namespace Zotlabs\Tests\Unit\Module;
+
+use PHPUnit\Framework\Attributes\TestWith;
+
+class ItemTest extends TestCase {
+
+ #[TestWith(['application/x-zot+json'])]
+ #[TestWith(['application/x-zot-activity+json'])]
+ public function test_request_with_no_args_return_404(string $type): void {
+ $this->expect_status(404, 'Not found');
+
+ $_SERVER['HTTP_ACCEPT'] = $type;
+ $this->get('item');
+ }
+
+ #[TestWith(['application/x-zot+json'])]
+ #[TestWith(['application/x-zot-activity+json'])]
+ public function test_request_with_non_exiting_idem_id(string $type): void {
+ $this->expect_status(404, 'Not found');
+
+ $_SERVER['HTTP_ACCEPT'] = $type;
+ $this->get('item/non-existing-id');
+ }
+
+ /**
+ * Helper function to mock the `http_status_exit` function.
+ *
+ * The request will be terminated by throwing an exception, which
+ * will also terminate the test case. Iow. control will not return
+ * to the test case after the request has been made.
+ *
+ * @param int $status The expected HTTP status code.
+ * @param string $description The expected HTTP status description
+ */
+ private function expect_status(int $status, string $description): void {
+ $this->getFunctionMock('Zotlabs\Module', 'http_status_exit')
+ ->expects($this->once())
+ ->with($this->identicalTo($status), $this->identicalTo($description))
+ ->willReturnCallback(
+ function () {
+ throw new KillmeException();
+ }
+ );
+
+ $this->expectException(KillmeException::class);
+
+ }
+}