Skip to content

Commit 514db60

Browse files
committed
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.
1 parent 2f74cfb commit 514db60

File tree

7 files changed

+53
-38
lines changed

7 files changed

+53
-38
lines changed

tests/HelpTest.php renamed to tests/Meta/HelpTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class HelpTest extends TestCase
68
{

tests/LicensesTest.php renamed to tests/Meta/LicensesTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class LicensesTest extends TestCase
68
{

tests/OpenGraphTest.php renamed to tests/Meta/OpenGraphTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
44

55
use BookStack\Entities\Repos\BaseRepo;
66
use BookStack\Entities\Repos\BookRepo;
77
use Illuminate\Support\Str;
88
use Illuminate\Testing\TestResponse;
9+
use Tests\TestCase;
910

1011
class OpenGraphTest extends TestCase
1112
{

tests/OpensearchTest.php renamed to tests/Meta/OpensearchTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class OpensearchTest extends TestCase
68
{
79
public function test_opensearch_endpoint()
810
{
9-
$appName = setting('app-name');
11+
$appName = 'MyAppNameThatsReallyLongLikeThis';
12+
setting()->put('app-name', $appName);
1013
$resultUrl = url('/search') . '?term={searchTerms}';
1114
$selfUrl = url('/opensearch.xml');
1215

@@ -17,14 +20,11 @@ public function test_opensearch_endpoint()
1720

1821
$html->assertElementExists('OpenSearchDescription > ShortName');
1922
$html->assertElementContains('OpenSearchDescription > ShortName', mb_strimwidth($appName, 0, 16));
23+
$html->assertElementNotContains('OpenSearchDescription > ShortName', $appName);
2024

2125
$html->assertElementExists('OpenSearchDescription > Description');
22-
$html->assertElementContains('OpenSearchDescription > Description', trans('common.opensearch_description', [
23-
'appName' => $appName,
24-
]));
25-
26+
$html->assertElementContains('OpenSearchDescription > Description', "Search {$appName}");
2627
$html->assertElementExists('OpenSearchDescription > Image');
27-
2828
$html->assertElementExists('OpenSearchDescription > Url[rel="results"][template="' . htmlspecialchars($resultUrl) . '"]');
2929
$html->assertElementExists('OpenSearchDescription > Url[rel="self"][template="' . htmlspecialchars($selfUrl) . '"]');
3030
}

tests/PwaManifestTest.php renamed to tests/Meta/PwaManifestTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
46

57
class PwaManifestTest extends TestCase
68
{

tests/Meta/RobotsTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Tests\Meta;
4+
5+
use Tests\TestCase;
6+
7+
class RobotsTest extends TestCase
8+
{
9+
public function test_robots_effected_by_public_status()
10+
{
11+
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
12+
13+
$this->setSettings(['app-public' => 'true']);
14+
15+
$resp = $this->get('/robots.txt');
16+
$resp->assertSee("User-agent: *\nDisallow:");
17+
$resp->assertDontSee('Disallow: /');
18+
}
19+
20+
public function test_robots_effected_by_setting()
21+
{
22+
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
23+
24+
config()->set('app.allow_robots', true);
25+
26+
$resp = $this->get('/robots.txt');
27+
$resp->assertSee("User-agent: *\nDisallow:");
28+
$resp->assertDontSee('Disallow: /');
29+
30+
// Check config overrides app-public setting
31+
config()->set('app.allow_robots', false);
32+
$this->setSettings(['app-public' => 'true']);
33+
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
34+
}
35+
}

tests/PublicActionTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,6 @@ public function test_content_not_listed_on_404_for_public_users()
128128
$resp->assertDontSee($page->name);
129129
}
130130

131-
public function test_robots_effected_by_public_status()
132-
{
133-
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
134-
135-
$this->setSettings(['app-public' => 'true']);
136-
137-
$resp = $this->get('/robots.txt');
138-
$resp->assertSee("User-agent: *\nDisallow:");
139-
$resp->assertDontSee('Disallow: /');
140-
}
141-
142-
public function test_robots_effected_by_setting()
143-
{
144-
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
145-
146-
config()->set('app.allow_robots', true);
147-
148-
$resp = $this->get('/robots.txt');
149-
$resp->assertSee("User-agent: *\nDisallow:");
150-
$resp->assertDontSee('Disallow: /');
151-
152-
// Check config overrides app-public setting
153-
config()->set('app.allow_robots', false);
154-
$this->setSettings(['app-public' => 'true']);
155-
$this->get('/robots.txt')->assertSee("User-agent: *\nDisallow: /");
156-
}
157-
158131
public function test_default_favicon_file_created_upon_access()
159132
{
160133
$faviconPath = public_path('favicon.ico');

0 commit comments

Comments
 (0)