From 514db60617780de889645513ad613d8ff0ba3108 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 30 Sep 2024 17:07:53 +0100 Subject: [PATCH] Tests: Categorised up meta tests Extracted robots.txt tests into its own file to fit into new folder. Also tweaked open search tests a tad to specifically check long app names. --- tests/{ => Meta}/HelpTest.php | 4 +++- tests/{ => Meta}/LicensesTest.php | 4 +++- tests/{ => Meta}/OpenGraphTest.php | 3 ++- tests/{ => Meta}/OpensearchTest.php | 14 +++++------ tests/{ => Meta}/PwaManifestTest.php | 4 +++- tests/Meta/RobotsTest.php | 35 ++++++++++++++++++++++++++++ tests/PublicActionTest.php | 27 --------------------- 7 files changed, 53 insertions(+), 38 deletions(-) rename tests/{ => Meta}/HelpTest.php (94%) rename tests/{ => Meta}/LicensesTest.php (94%) rename tests/{ => Meta}/OpenGraphTest.php (98%) rename tests/{ => Meta}/OpensearchTest.php (84%) rename tests/{ => Meta}/PwaManifestTest.php (98%) create mode 100644 tests/Meta/RobotsTest.php diff --git a/tests/HelpTest.php b/tests/Meta/HelpTest.php similarity index 94% rename from tests/HelpTest.php rename to tests/Meta/HelpTest.php index 9cf80717f..e1de96bc8 100644 --- a/tests/HelpTest.php +++ b/tests/Meta/HelpTest.php @@ -1,6 +1,8 @@ put('app-name', $appName); $resultUrl = url('/search') . '?term={searchTerms}'; $selfUrl = url('/opensearch.xml'); @@ -17,14 +20,11 @@ class OpensearchTest extends TestCase $html->assertElementExists('OpenSearchDescription > ShortName'); $html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16)); + $html->assertElementNotContains('OpenSearchDescription > ShortName', $appName); $html->assertElementExists('OpenSearchDescription > Description'); - $html->assertElementContains('OpenSearchDescription > Description', trans('common.opensearch_description', [ - 'appName' => $appName, - ])); - + $html->assertElementContains('OpenSearchDescription > Description', "Search {$appName}"); $html->assertElementExists('OpenSearchDescription > Image'); - $html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]'); $html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]'); } diff --git a/tests/PwaManifestTest.php b/tests/Meta/PwaManifestTest.php similarity index 98% rename from tests/PwaManifestTest.php rename to tests/Meta/PwaManifestTest.php index c66f8b360..fc6d19b54 100644 --- a/tests/PwaManifestTest.php +++ b/tests/Meta/PwaManifestTest.php @@ -1,6 +1,8 @@ get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); + + $this->setSettings(['app-public' => 'true']); + + $resp = $this->get('/robots.txt'); + $resp->assertSee("User-agent: *\nDisallow:"); + $resp->assertDontSee('Disallow: /'); + } + + public function test_robots_effected_by_setting() + { + $this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); + + config()->set('app.allow_robots', true); + + $resp = $this->get('/robots.txt'); + $resp->assertSee("User-agent: *\nDisallow:"); + $resp->assertDontSee('Disallow: /'); + + // Check config overrides app-public setting + config()->set('app.allow_robots', false); + $this->setSettings(['app-public' => 'true']); + $this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); + } +} diff --git a/tests/PublicActionTest.php b/tests/PublicActionTest.php index 875b279a8..76745aaac 100644 --- a/tests/PublicActionTest.php +++ b/tests/PublicActionTest.php @@ -128,33 +128,6 @@ class PublicActionTest extends TestCase $resp->assertDontSee($page->name); } - public function test_robots_effected_by_public_status() - { - $this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); - - $this->setSettings(['app-public' => 'true']); - - $resp = $this->get('/robots.txt'); - $resp->assertSee("User-agent: *\nDisallow:"); - $resp->assertDontSee('Disallow: /'); - } - - public function test_robots_effected_by_setting() - { - $this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); - - config()->set('app.allow_robots', true); - - $resp = $this->get('/robots.txt'); - $resp->assertSee("User-agent: *\nDisallow:"); - $resp->assertDontSee('Disallow: /'); - - // Check config overrides app-public setting - config()->set('app.allow_robots', false); - $this->setSettings(['app-public' => 'true']); - $this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /"); - } - public function test_default_favicon_file_created_upon_access() { $faviconPath = public_path('favicon.ico');