-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathNoIndexNonProductionTest.php
More file actions
63 lines (46 loc) · 1.87 KB
/
NoIndexNonProductionTest.php
File metadata and controls
63 lines (46 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Tests\Feature;
use Tests\TestCase;
class NoIndexNonProductionTest extends TestCase
{
public function test_robots_txt_disallows_all_in_non_production(): void
{
$this->assertFalse(app()->isProduction());
$response = $this->get('/robots.txt');
$response->assertOk();
$response->assertHeader('Content-Type', 'text/plain; charset=UTF-8');
$this->assertStringContainsString('Disallow: /', $response->getContent());
}
public function test_robots_txt_allows_all_in_production(): void
{
app()->detectEnvironment(fn () => 'production');
$response = $this->get('/robots.txt');
$response->assertOk();
$this->assertStringContainsString("User-agent: *\nDisallow:", $response->getContent());
$this->assertStringContainsString('Sitemap:', $response->getContent());
}
public function test_non_production_responses_have_x_robots_tag_header(): void
{
$response = $this->get('/about');
$response->assertHeader('X-Robots-Tag', 'noindex, nofollow');
}
public function test_production_responses_do_not_have_x_robots_tag_header(): void
{
app()->detectEnvironment(fn () => 'production');
$response = $this->get('/about');
$response->assertHeaderMissing('X-Robots-Tag');
}
public function test_non_production_html_has_noindex_meta_tag(): void
{
$response = $this->get('/about');
$response->assertOk();
$response->assertSee('<meta name="robots" content="noindex, nofollow">', false);
}
public function test_production_html_does_not_have_noindex_meta_tag(): void
{
app()->detectEnvironment(fn () => 'production');
$response = $this->get('/about');
$response->assertOk();
$response->assertDontSee('<meta name="robots" content="noindex, nofollow">', false);
}
}