| 
									
										
										
										
											2024-09-14 22:21:01 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 00:07:53 +08:00
										 |  |  | namespace Tests\Meta; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Tests\TestCase; | 
					
						
							| 
									
										
										
										
											2024-09-14 22:21:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class OpensearchTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function test_opensearch_endpoint() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-10-01 00:07:53 +08:00
										 |  |  |         $appName = 'MyAppNameThatsReallyLongLikeThis'; | 
					
						
							|  |  |  |         setting()->put('app-name', $appName); | 
					
						
							| 
									
										
										
										
											2024-09-14 22:21:01 +08:00
										 |  |  |         $resultUrl = url('/search') . '?term={searchTerms}'; | 
					
						
							|  |  |  |         $selfUrl = url('/opensearch.xml'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $resp = $this->get('/opensearch.xml'); | 
					
						
							|  |  |  |         $resp->assertOk(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $html = $this->withHtml($resp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $html->assertElementExists('OpenSearchDescription > ShortName'); | 
					
						
							|  |  |  |         $html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16)); | 
					
						
							| 
									
										
										
										
											2024-10-01 00:07:53 +08:00
										 |  |  |         $html->assertElementNotContains('OpenSearchDescription > ShortName', $appName); | 
					
						
							| 
									
										
										
										
											2024-09-14 22:21:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $html->assertElementExists('OpenSearchDescription > Description'); | 
					
						
							| 
									
										
										
										
											2024-10-01 00:07:53 +08:00
										 |  |  |         $html->assertElementContains('OpenSearchDescription > Description', "Search {$appName}"); | 
					
						
							| 
									
										
										
										
											2024-09-14 22:21:01 +08:00
										 |  |  |         $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) . '"]'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |