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.
This commit is contained in:
Dan Brown 2024-09-30 17:07:53 +01:00
parent 2f74cfb42c
commit 514db60617
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
7 changed files with 53 additions and 38 deletions

View File

@ -1,6 +1,8 @@
<?php
namespace Tests;
namespace Tests\Meta;
use Tests\TestCase;
class HelpTest extends TestCase
{

View File

@ -1,6 +1,8 @@
<?php
namespace Tests;
namespace Tests\Meta;
use Tests\TestCase;
class LicensesTest extends TestCase
{

View File

@ -1,11 +1,12 @@
<?php
namespace Tests;
namespace Tests\Meta;
use BookStack\Entities\Repos\BaseRepo;
use BookStack\Entities\Repos\BookRepo;
use Illuminate\Support\Str;
use Illuminate\Testing\TestResponse;
use Tests\TestCase;
class OpenGraphTest extends TestCase
{

View File

@ -1,12 +1,15 @@
<?php
namespace Tests;
namespace Tests\Meta;
use Tests\TestCase;
class OpensearchTest extends TestCase
{
public function test_opensearch_endpoint()
{
$appName = setting('app-name');
$appName = 'MyAppNameThatsReallyLongLikeThis';
setting()->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) . '"]');
}

View File

@ -1,6 +1,8 @@
<?php
namespace Tests;
namespace Tests\Meta;
use Tests\TestCase;
class PwaManifestTest extends TestCase
{

35
tests/Meta/RobotsTest.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace Tests\Meta;
use Tests\TestCase;
class RobotsTest extends TestCase
{
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: /");
}
}

View File

@ -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');