forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUrlGenerationTest.php
More file actions
70 lines (55 loc) · 2.74 KB
/
UrlGenerationTest.php
File metadata and controls
70 lines (55 loc) · 2.74 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
64
65
66
67
68
69
70
<?php
use App\Providers\AppServiceProvider;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\URL;
beforeEach(function () {
Cache::flush();
});
describe('url generation with subpath', function () {
test('AppServiceProvider configureUrl sets URL origin from APP_URL config', function () {
// First, reset the URL generator to a known state
URL::useOrigin('http://localhost');
// Set APP_URL config to a subpath URL
config()->set('app.url', 'https://myserver.com/speedtest');
// Create a new instance of AppServiceProvider and call boot
// This simulates what happens when the app boots with APP_URL set
$provider = new AppServiceProvider(app());
$provider->boot();
// Verify that route() now generates URLs with the subpath
// Note: scheme may be http in test environment since forceScheme requires non-local + FORCE_HTTPS
expect(route('getting-started'))->toContain('/speedtest/getting-started');
expect(route('home'))->toContain('myserver.com/speedtest');
});
test('AppServiceProvider configureUrl sets URL origin for url() helper', function () {
URL::useOrigin('http://localhost');
config()->set('app.url', 'https://myserver.com/speedtest');
$provider = new AppServiceProvider(app());
$provider->boot();
expect(url('/admin'))->toContain('/speedtest/admin');
expect(url('/getting-started'))->toContain('/speedtest/getting-started');
});
});
describe('url generation without subpath', function () {
test('routes generate plain paths when APP_URL has no subpath', function () {
// Set APP_URL to a domain without a subpath
URL::useOrigin('http://localhost');
config()->set('app.url', 'https://myserver.com');
$provider = new AppServiceProvider(app());
$provider->boot();
// URLs should not have any subpath prefix - just the plain route path
expect(route('getting-started'))->toContain('myserver.com/getting-started');
expect(route('home'))->toContain('myserver.com');
// Verify no subpath is present
expect(route('getting-started'))->not->toContain('myserver.com/speedtest');
});
test('url() helper generates plain paths when APP_URL has no subpath', function () {
URL::useOrigin('http://localhost');
config()->set('app.url', 'https://myserver.com');
$provider = new AppServiceProvider(app());
$provider->boot();
expect(url('/admin'))->toContain('myserver.com/admin');
expect(url('/getting-started'))->toContain('myserver.com/getting-started');
// Verify no subpath is present
expect(url('/admin'))->not->toContain('myserver.com/speedtest');
});
});