54 lines
2.1 KiB
PHP
54 lines
2.1 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Tests\Feature;
|
||
|
|
|
||
|
|
use App\Models\Site;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class SubdomainsTest extends TestCase
|
||
|
|
{
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_root_domain_page_lists_its_subdomains(): void
|
||
|
|
{
|
||
|
|
$root = Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'example.com', 'root_domain' => 'example.com']);
|
||
|
|
Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'blog.example.com', 'root_domain' => 'example.com']);
|
||
|
|
Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'shop.example.com', 'root_domain' => 'example.com']);
|
||
|
|
Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'unrelated.net', 'root_domain' => 'unrelated.net']);
|
||
|
|
|
||
|
|
$response = $this->actingAs(User::factory()->create())->get(route('sites.show', $root));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertSeeText('Subdomains (2)');
|
||
|
|
$response->assertSeeText('blog.example.com');
|
||
|
|
$response->assertSeeText('shop.example.com');
|
||
|
|
$response->assertDontSeeText('unrelated.net');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_subdomain_page_links_back_to_its_root(): void
|
||
|
|
{
|
||
|
|
$root = Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'example.com', 'root_domain' => 'example.com']);
|
||
|
|
$sub = Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'blog.example.com', 'root_domain' => 'example.com']);
|
||
|
|
|
||
|
|
$response = $this->actingAs(User::factory()->create())->get(route('sites.show', $sub));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertSeeText('Subdomain of');
|
||
|
|
$response->assertSeeText($root->domain);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_root_domain_with_no_subdomains_shows_empty_state(): void
|
||
|
|
{
|
||
|
|
$root = Site::create(['collection' => 'CC-MAIN-TEST', 'domain' => 'lonely.com', 'root_domain' => 'lonely.com']);
|
||
|
|
|
||
|
|
$response = $this->actingAs(User::factory()->create())->get(route('sites.show', $root));
|
||
|
|
|
||
|
|
$response->assertOk();
|
||
|
|
$response->assertSeeText('Subdomains (0)');
|
||
|
|
$response->assertSeeText('No subdomains found.');
|
||
|
|
$response->assertDontSeeText('Subdomain of');
|
||
|
|
}
|
||
|
|
}
|