Skip to content

Commit 2f74cfb

Browse files
Add test for OpenSearch endpoint
1 parent 1302e3c commit 2f74cfb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/OpensearchTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
class OpensearchTest extends TestCase
6+
{
7+
public function test_opensearch_endpoint()
8+
{
9+
$appName = setting('app-name');
10+
$resultUrl = url('/search') . '?term={searchTerms}';
11+
$selfUrl = url('/opensearch.xml');
12+
13+
$resp = $this->get('/opensearch.xml');
14+
$resp->assertOk();
15+
16+
$html = $this->withHtml($resp);
17+
18+
$html->assertElementExists('OpenSearchDescription > ShortName');
19+
$html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16));
20+
21+
$html->assertElementExists('OpenSearchDescription > Description');
22+
$html->assertElementContains('OpenSearchDescription > Description', trans('common.opensearch_description', [
23+
'appName' => $appName,
24+
]));
25+
26+
$html->assertElementExists('OpenSearchDescription > Image');
27+
28+
$html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]');
29+
$html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]');
30+
}
31+
32+
public function test_opensearch_linked_to_from_home()
33+
{
34+
$appName = setting('app-name');
35+
$endpointUrl = url('/opensearch.xml');
36+
37+
$resp = $this->asViewer()->get('/');
38+
$html = $this->withHtml($resp);
39+
40+
$html->assertElementExists('head > link[rel="search"][type="application/opensearchdescription+xml"][title="' . htmlspecialchars($appName) . '"][href="' . htmlspecialchars($endpointUrl) . '"]');
41+
}
42+
}

0 commit comments

Comments
 (0)