From fde4962ce39515f7e7231e7ead4f1d565667c32c Mon Sep 17 00:00:00 2001 From: Maximilian Walter Date: Sat, 14 Sep 2024 16:21:01 +0200 Subject: [PATCH] Add test for OpenSearch endpoint --- tests/OpensearchTest.php | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/OpensearchTest.php diff --git a/tests/OpensearchTest.php b/tests/OpensearchTest.php new file mode 100644 index 000000000..a68076b43 --- /dev/null +++ b/tests/OpensearchTest.php @@ -0,0 +1,42 @@ +get('/opensearch.xml'); + $resp->assertOk(); + + $html = $this->withHtml($resp); + + $html->assertElementExists('OpenSearchDescription > ShortName'); + $html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16)); + + $html->assertElementExists('OpenSearchDescription > Description'); + $html->assertElementContains('OpenSearchDescription > Description', trans('common.opensearch_description', [ + 'appName' => $appName, + ])); + + $html->assertElementExists('OpenSearchDescription > Image'); + + $html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]'); + $html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]'); + } + + public function test_opensearch_linked_to_from_home() + { + $appName = setting('app-name'); + $endpointUrl = url('/opensearch.xml'); + + $resp = $this->asViewer()->get('/'); + $html = $this->withHtml($resp); + + $html->assertElementExists('head > link[rel="search"][type="application/opensearchdescription+xml"][title="' . htmlspecialchars($appName) . '"][href="' . htmlspecialchars($endpointUrl) . '"]'); + } +}